Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is about booking a flight online. Here are some codes: Interface for DBManager that Mock Objects fulfill: package is.hi.hbv401g.flightsearch.controller; import java.sql.SQLException; import java.util.List;

image text in transcribed

image text in transcribed

This program is about booking a flight online.

Here are some codes:

Interface for DBManager that Mock Objects fulfill:

package is.hi.hbv401g.flightsearch.controller; import java.sql.SQLException; 
import java.util.List; 
import is.hi.hbv401g.flightsearch.model.Booking; import is.hi.hbv401g.flightsearch.model.Flight; import is.hi.hbv401g.flightsearch.model.Query; 
public interface DBManager { List searchByQuery (Query q) throws SQLException; 
 List getLocations() throws SQLException; List getPopularLocations() throws SQLException; void addBooking(Booking bokking) throws SQLException; Booking searchForBooking(int bookNumber) throws SQLException; 

}

This mock object returns list of flights that have two flights:

package is.hi.hbv401g.flightsearch.controller; 
import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; 
import is.hi.hbv401g.flightsearch.model.Booking; import is.hi.hbv401g.flightsearch.model.Flight; import is.hi.hbv401g.flightsearch.model.Passenger; import is.hi.hbv401g.flightsearch.model.Query; import is.hi.hbv401g.flightsearch.model.Seat; 
public class CorrectList implements DBManager { 
 /* (non-Javadoc) * Skilar lista af gildum flugum */ 

@Override

 public List searchByQuery(Query q) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); 
 c1.set(2018,12,12, 15,30); c2.set(2018,12,12, 18, 0); 
 Seat s1 = new Seat(10000, "First Class", new Passenger("Anna", s1), false, "Phone charger", "One bag", false, "13A"); 
 Seat s2 = new Seat(10000, "First Class", new Passenger("Magga", s2), false, "Phone charger", "One bag", false, "13B"); 
 Seat s3 = new Seat(10000, "First Class", new Passenger("Sigga", s3), false, "Phone charger", "One bag", false, "14A"); 
 Seat s4 = new Seat(10000, "First Class", new Passenger("Binni", s4), false, "Phone charger", "One bag", false, "14B"); 
 ArrayList theSeats1 = new ArrayList(); theSeats1.add(s1); theSeats1.add(s2); 
 ArrayList theSeats2 = new ArrayList(); theSeats2.add(s3); theSeats2.add(s4); 
 Flight flight1 = new Flight ("KEFLAVIK","PARIS", c1, c2 , 100, 20, theSeats1, "FG1233"); 
 Flight flight2 = new Flight ("KEFLAVIK","DUBLIN", c1, c2 , 100, 20, theSeats2, "FGLF39"); 
List flightList = new ArrayList(); 

} }

}

flightList.add(flight2); flightList.add(flight1); 
return flightList; 
/* * Ekki nota i? essu verkefni/pro?fun */ 

@Override

public List getLocations() { // Ekki nota

return null;

}

/* * Ekki nota i? essu verkefni/pro?fun */ 

@Override

public List getPopularLocations() { // Ekki nota

return null;

}

/* * Ekki nota i? essu verkefni/pro?fun */ 

@Override

public void addBooking(Booking bokking) { // Ekki nota

}

/* * Ekki nota i? essu verkefni/pro?fun */ 

@Override

public Booking searchForBooking(int bookNumber) { // Ekki nota

return null;

Here is the Test fixture:

public class FlightSearchControllerTest { 
 public FlightSearchController controller; @Before public void setUp() { 

}

@After

 public void tearDown () { controller = null; 
 assertNull(controller); 

}

 /* Prufum egar vi fa?um lista af flugum til baka */ 

@Test

 public void testSearhForFlight() { DBManager manager = new CorrectList(); controller = new FlightSearchController(manager); 
 Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); 
 c1.set(2018,12,12, 15,30); c2.set(2018,12,12, 18, 0); int passengerCount = 2; 
 // Prufum search afer i? Controller 

List result = controller.search("KEFLAVIK", "PARIS", c1, c2, passengerCount); // Hu?n a? ekki a skila null

 assertNotNull(result); for (Flight f: result) { 
 // Passar brottfarastaur? 
 String departure = f.getDeparture(); assertEquals(departure, "KEFLAVIK"); 
 // Passar a?fangastaur? 
 String arrival = f.getArrival(); assertEquals(arrival, "PARIS"); 
 // Passar brottfarati?mi? 
 Calendar departureTime = f.getDepartureTime(); assertEquals(departureTime, c1); 
 // Passar komuti?mi 
 Calendar arrivalTime = f.getArrivalTime(); assertEquals(arrivalTime, c2); 

} }

} }

}

// Eru no?gu mo?rg laus sti i? fluginu 
int availableSeats = f.getNumberOfAvailableSeats(); assertTrue(passengerCount 
/* Prufum ef a database manager skilar engum niursto?um */ 

@Test

public void testSearchEmpty() { DBManager manager = new EmptySearchList(); 
controller = new FlightSearchController(manager); Calendar c1 = Calendar.getInstance(); 
Calendar c2 = Calendar.getInstance(); 
c1.set(2018,12,12, 15,30); c2.set(2018,12,12, 18, 0); List result = controller.search("KEFLAVIK", "PARIS", c1, c2, 2); 
/* A? ekki a skila null heldur to?mum lista */ 
assertNotNull(result); assertEquals(result.size(),0); 
/* Skoum ef a database manager skilar error ea SQLException */ 

@Test

public void testSearchFail() { DBManager manager = new FailSearch(); controller = new FlightSearchController(manager); 
Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); 
c1.set(2018,12,12, 15,30); c2.set(2018,12,12, 18, 0); List result = controller.search("KEFLAVIK", "PARIS", c1, c2, 2); 
// Eigum a? a fa? to?man lista til baka, ekki null og ekki error. 
assertNotNull(result); assertEquals(0,result.size()); 

// Just so you have an idea!

Testing the code in Eclipse using JUnit I have a presentation on this subject. We had to do a test fixture we have implemented for one of our controller components. We also used mock objects. My question that I have to answer are Why did you choose the test cases (inputs and expected results) you did? Why do you believe the behaviour covered by your test cases is sufficient? -How do your mock objects simulate behaviour in different test scenarios? Can someone give me some answers and ideas as to how I could answer these questions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions