You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
4.4 KiB
112 lines
4.4 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
import org.junit.Assert;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
import org.mockito.InjectMocks;
|
|
import org.mockito.Mock;
|
|
|
|
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;
|
|
import java.util.List;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
@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());
|
|
|
|
@Mock
|
|
private ItineraryRepository itineraryRepo;
|
|
@Mock
|
|
private FlightReservationRepository flightReservationRepository;
|
|
|
|
@Test
|
|
public void test_makePayment() {
|
|
ArrayList<Itinerary> itineraries = new ArrayList<>();
|
|
|
|
itineraries.add(item1);
|
|
itineraries.add(item2);
|
|
|
|
when(person1.getItineraries()).thenReturn(itineraries);
|
|
|
|
boolean actualWithCredit = item1.makePayment(new FlightReservation(),"Credit", person1, 450);
|
|
boolean actualWithCash = item1.makePayment(new FlightReservation(), "Cash", person1, 450);
|
|
boolean actualWithCheck = item1.makePayment(new FlightReservation(), "Check", person1, 450);
|
|
boolean actualEmpty = item1.makePayment(new FlightReservation(), " ", person1, 450);
|
|
|
|
assertEquals(true, actualWithCash, "The Payment method is successfully chosen");
|
|
assertEquals(true, actualWithCash, "The Payment method is successfully chosen");
|
|
assertEquals(true, actualWithCredit, "The Payment method is successfully chosen");
|
|
assertEquals(true, actualWithCheck, "The Payment method is successfully chosen");
|
|
assertEquals(false, actualEmpty, "The Payment method is wrong");
|
|
}
|
|
|
|
@Test
|
|
public void test_makePaymentStatus(){
|
|
FlightReservation flightReservation = new FlightReservation();
|
|
item1.makePayment(flightReservation,"Credit", person1, 450);
|
|
assertEquals(flightReservation.getStatus(), ReservationStatus.Pending);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Should Not Make Reservation when Passenger name is null")
|
|
public void shouldThrowRuntimeExceptionWhenNameIsNull() {
|
|
String msg = null;
|
|
try {
|
|
item1.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("", "Ab", new Date()));
|
|
} catch (Exception e) {
|
|
msg = e.getMessage();
|
|
}
|
|
assertEquals("Name cannot be null or empty", msg);
|
|
}
|
|
|
|
@DisplayName("Should Not Make Reservation when Passenger passport number is invalid")
|
|
@ParameterizedTest
|
|
@MethodSource("passportNumberList")
|
|
public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull(String passportNumber) {
|
|
String msg = null;
|
|
try {
|
|
item1.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("John", passportNumber, new Date()));
|
|
} catch (Exception e) {
|
|
msg = e.getMessage();
|
|
}
|
|
assertEquals("Passport number cannot be null or empty", msg);
|
|
}
|
|
|
|
private static List<String> passportNumberList() {
|
|
return Arrays.asList("A2", "000000", "AB231837%8");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Should Not Make Reservation when Passenger Birthdate is null")
|
|
public void shouldThrowRuntimeExceptionWhenDateIsNull() {
|
|
assertThrows(RuntimeException.class, () -> {
|
|
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);
|
|
}
|
|
}
|