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.
65 lines
2.5 KiB
65 lines
2.5 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.mockito.InjectMocks;
|
|
import org.mockito.Mock;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
import static org.mockito.Mockito.*;
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
|
|
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");
|
|
|
|
@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;
|
|
|
|
@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("Credit", person1, 450);
|
|
boolean actualWithCash = item1.makePayment("Cash", person1, 450);
|
|
boolean actualWithCheck = item1.makePayment("Check", person1, 450);
|
|
boolean actualEmpty = item1.makePayment(" ", 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
|
|
@DisplayName("Should Not Make Reservation when Passenger name is null")
|
|
public void shouldThrowRuntimeExceptionWhenNameIsNull(){
|
|
String msg = null;
|
|
try {
|
|
item1.makeReservation(new Passenger("", "Ab", new Date()));
|
|
} catch (Exception e) {
|
|
msg = e.getMessage();
|
|
}
|
|
assertEquals(msg, "Name cannot be null or empty");
|
|
}
|
|
}
|