|
|
@ -9,9 +9,11 @@ import org.junit.jupiter.params.provider.MethodSource; |
|
|
|
import org.mockito.InjectMocks; |
|
|
|
import org.mockito.Mock; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows; |
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
import static org.mockito.Mockito.*; |
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
@ -19,22 +21,22 @@ import java.util.List; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
|
public class ItineraryTest { |
|
|
|
|
|
|
|
final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); |
|
|
|
final Airport airport_fr = new Airport("Fraport", address1, "1234"); |
|
|
|
final Airport airport_be = new Airport("Berlin", address1, "5678"); |
|
|
|
final Itinerary item2 = new Itinerary(airport_be, airport_fr, new Date()); |
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
final Customer person1 = new Customer("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206"); |
|
|
|
final Itinerary item1 = new Itinerary(airport_fr, airport_be, new Date()); |
|
|
|
final Itinerary item2 = new Itinerary(airport_be, airport_fr, new Date()); |
|
|
|
|
|
|
|
@Mock |
|
|
|
private ItineraryRepository itineraryRepo; |
|
|
|
@Mock |
|
|
|
private FlightReservationRepository flightReservationRepository; |
|
|
|
|
|
|
|
@Test |
|
|
|
public void test_makePayment() { |
|
|
@ -62,7 +64,7 @@ public class ItineraryTest { |
|
|
|
public void shouldThrowRuntimeExceptionWhenNameIsNull() { |
|
|
|
String msg = null; |
|
|
|
try { |
|
|
|
item1.makeReservation(new Passenger("", "Ab", new Date())); |
|
|
|
item1.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("", "Ab", new Date())); |
|
|
|
} catch (Exception e) { |
|
|
|
msg = e.getMessage(); |
|
|
|
} |
|
|
@ -75,7 +77,7 @@ public class ItineraryTest { |
|
|
|
public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull(String passportNumber) { |
|
|
|
String msg = null; |
|
|
|
try { |
|
|
|
item1.makeReservation(new Passenger("John", passportNumber, new Date())); |
|
|
|
item1.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("John", passportNumber, new Date())); |
|
|
|
} catch (Exception e) { |
|
|
|
msg = e.getMessage(); |
|
|
|
} |
|
|
@ -90,7 +92,14 @@ public class ItineraryTest { |
|
|
|
@DisplayName("Should Not Make Reservation when Passenger Birthdate is null") |
|
|
|
public void shouldThrowRuntimeExceptionWhenDateIsNull() { |
|
|
|
assertThrows(RuntimeException.class, () -> { |
|
|
|
item1.makeReservation(new Passenger("John", "AB127389", null)); |
|
|
|
item1.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("John", "AB127389", null)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void test_makeReservation() { |
|
|
|
FlightReservation flightreservation = item2.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("John", "AB2389", new Date())); |
|
|
|
assertNotNull(flightreservation); |
|
|
|
assertEquals(flightreservation.getStatus(), ReservationStatus.Requested); |
|
|
|
} |
|
|
|
} |