Advertisement
drorgrebel

Maman12_2018A_20441

Nov 23rd, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.91 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2. import org.junit.Test;
  3. /**
  4.  * Flight_Tester
  5.  * Tests Flight class.
  6.  *
  7.  * @author Dror
  8.  * @version 20441/Maman_12/2018A
  9.  */
  10. public class Flight_Tester
  11. {  
  12.    //Test Flight Constructors
  13.      @Test  /*new Flight ("Origin", "destination", depHour, depMinute, durTimeminutes, noOfPass, price)
  14.               getArrivalTime()/setArrivalTime()
  15.               getDeparture(),
  16.               getDestination(),
  17.               getFlightDuration(),
  18.               getIsFull()    
  19.              */
  20.      public void testFlight_ctor()
  21.      {
  22.            Flight flight1 = new Flight(new String("London"), new String("Paris"),9,40,200,100,1000);
  23.            String flight1_str = flight1.toString();
  24.            String flight1_str_exp = "Flight from London to Paris departs at 09:40. Flight is not full.";
  25.          //Expcted to be equal
  26.            assertEquals("flight1 toString():", flight1_str_exp, flight1.toString() );
  27.            
  28.            Flight flight2 = new Flight( flight1 );
  29.          //Expcted to be equal:  flight1_str_exp and flight2 which is a copy of flight1
  30.            assertEquals("flight1 toString():", flight1_str_exp, flight2.toString() );
  31.            
  32.          //Test the default values:
  33.          //Try create a new object with wrong argument values for duration(-1), number of passengers( 1000 > MAX_CAPACITY), and price(-10)
  34.            Flight flight3 = new Flight( "London", "Paris", 9, 40, -1, 1000, -10);
  35.            String flight3_str_exp = "Flight from London to Paris departs at 09:40. Flight is full.";  
  36.            assertEquals("flight3 toString():", flight3_str_exp, flight3.toString() );
  37.          //Check getFlightDuration (expected to initiate 0 Minutes).
  38.            assertEquals("flight3 getFlightDuration():", 0, flight3.getFlightDuration() );
  39.          //Check getNoOfPassengers (expected to initiate MAX_CAPACITY Passengers to flight).
  40.            assertEquals("flight3 getNoOfPassengers():", 250, flight3.getNoOfPassengers() );      
  41.          //Check getProice (expected to initiate a price of 0 to a flight-Ticket).
  42.            assertEquals("flight3 getPrice():", 0, flight3.getPrice() );
  43.      }//End testFlight_ctor  
  44.      
  45.    //Test Flight.equals()
  46.      @Test  
  47.      public void testFlight_equals()
  48.      {
  49.            Flight flight1 = new Flight(new String("Aman"), new String("Thailand"),0,38,600,250,1500);
  50.            String flight1_str = flight1.toString();
  51.            String flight1_str_exp = "Flight from Aman to Thailand departs at 00:38. Flight is full.";
  52.          //Expcted to be equal
  53.            assertEquals("flight1 toString():", flight1_str_exp, flight1.toString() );
  54.            
  55.            Flight flight2 = new Flight( flight1 );
  56.          //Expcted to be equal:  flight1_str_exp and flight2 which is a copy of flight1
  57.            boolean flight1_flight2 = flight1.equals(flight2);
  58.            boolean flight2_flight1 = flight2.equals(flight1);
  59.            assertEquals("flight1 is expected to be equal to flight2 :", true, flight1_flight2 );
  60.            assertEquals("flight2 is expected to be equal to flight1 :", true, flight2_flight1 );
  61.  
  62.      }//End testFlight_equals    
  63.      
  64.          
  65.    //Test Flight get/set origin and destination  
  66.      @Test
  67.      public void testFlight_SetGetOrigin()
  68.      {
  69.            Flight flight1 = new Flight(new String("London"), new String("Paris"),9,40,200,100,1000);
  70.            Flight flight2 = new Flight( flight1 );
  71.          //Expcted to be equal
  72.            assertEquals("flight1 getOrigin():", "London", flight1.getOrigin() );
  73.  
  74.          //Expcted to be equal:
  75.            assertEquals("flight2 toString():", "London", flight2.getOrigin() );
  76.          //Expcted false:
  77.             String LONDON = "LONDON";
  78.             assertEquals("flight1 toString():", false, LONDON.equals(flight2.getOrigin()) );
  79.            
  80.          //Set origin to be TLV
  81.            flight1.setOrigin("TLV");
  82.            assertEquals("flight1 set Origin to TLV:", "TLV", flight1.getOrigin() );  
  83.            assertEquals("flight2 Origin is still London:", "London", flight2.getOrigin() );    
  84.            
  85.          //Set Destination to be Berlin
  86.            flight1.setDestination("Berlin");
  87.            assertEquals("flight1 set Destination to Berlin:", "Berlin", flight1.getDestination() );  
  88.            assertEquals("flight2 Origin is still London:", "Paris", flight2.getDestination() );  
  89.            
  90.      }
  91.            
  92.  
  93.    //Test Flight get/set Flight Duration
  94.      @Test
  95.      public void testFlight_flightDuration()
  96.      {
  97.            Flight flight1 = new Flight(new String("London"), new String("Paris"),9,40,200,100,1000);
  98.          //Set Flight Duration to be negative --> expected not be changed
  99.            flight1.setFlightDuration( -10 );            
  100.          //Expcted to maintain the 200 minutes value
  101.            assertEquals("flight1 FlightDuration after setting to -10 Minutes(maintains old value)", 200, flight1.getFlightDuration() );
  102.  
  103.          //Set Flight Duration to be 600
  104.            flight1.setFlightDuration( 600 );            
  105.          //Expcteded to be 600 Minutes.
  106.            assertEquals("flight1 FlightDuration after setting to 600 Minutes: ", 600, flight1.getFlightDuration() );          
  107.                    
  108.      }
  109.            
  110.      
  111.      @Test  //Test minFromMidnight(), equals(), before(), after()
  112.      public void testDate2()
  113.      {
  114.             Time1 t1 = new Time1(23,59);
  115.             int t1_from_midnight = t1.minFromMidnight();
  116.             assertEquals("Time1(23,59)", "23:59", t1.toString());
  117.             Time1 t2 = new Time1(24,00);
  118.             assertEquals("Time1(24,00)", "00:00", t2.toString());
  119.             t1.setHour(22);
  120.             assertEquals("t1.setHour(22)", "22:59", t1.toString());
  121.             t1.setHour(24);
  122.             assertEquals("t1.setHour(24)", "22:59", t1.toString());
  123.             t1.setHour(-1);
  124.             assertEquals("t1.setHour(-1)", "22:59", t1.toString());
  125.  
  126.      }
  127.      
  128.      
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement