diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java b/src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java index 00f9b5a..81d9a26 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java @@ -42,6 +42,7 @@ public class Itinerary { } public boolean makeReservation(Passenger passenger){ + validatePassengerDetails(passenger); List flightReservations = getReservations(); FlightReservation flight = new FlightReservation(); flightReservationRepository.save(flight); @@ -86,5 +87,11 @@ public class Itinerary { if(this.creationDate.equals(null)) throw new RuntimeException(("Creation Date should not be null or empty")); } + + public void validatePassengerDetails(Passenger passenger){ + passenger.validateName(); + } + + } diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Passenger.java b/src/main/java/hs/fulda/de/ci/exam/project/Passenger.java index 8c85690..69b2093 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Passenger.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Passenger.java @@ -1,4 +1,21 @@ package hs.fulda.de.ci.exam.project; +import java.util.Date; + public class Passenger { + private String name; + private String passportNumber; + private Date dateOfBirth; + + public Passenger(String name, String passportNumber, Date dateOfBirth) { + this.name = name; + this.passportNumber = passportNumber; + this.dateOfBirth = dateOfBirth; + } + + public void validateName() { + throw new RuntimeException(("Name cannot be null or empty")); + } + + } diff --git a/src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java b/src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java index a3b75b7..bbaa039 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java +++ b/src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java @@ -1,9 +1,13 @@ 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; @@ -46,4 +50,16 @@ public class ItineraryTest { 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"); + } } \ No newline at end of file