From 89a20474f53bbc936b1b00d25f59c771d5add954 Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Thu, 17 Feb 2022 19:44:23 +0100 Subject: [PATCH] should not make reservation when passenger birthdate is null --- .../java/hs/fulda/de/ci/exam/project/Itinerary.java | 1 + .../java/hs/fulda/de/ci/exam/project/Passenger.java | 6 +++++- .../hs/fulda/de/ci/exam/project/ItineraryTest.java | 12 ++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) 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 71ebcb9..cdfe540 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 @@ -91,6 +91,7 @@ public class Itinerary { public void validatePassengerDetails(Passenger passenger){ passenger.validateName(); passenger.validatePassportNumber(); + passenger.validateDate(); } 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 d4ea2dd..b7b9d89 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 @@ -32,5 +32,9 @@ public class Passenger { } } - + public void validateDate() { + if(dateOfBirth.equals(null)) { + throw new RuntimeException("Birthdate cannot be null"); + } + } } 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 dc2a480..3b9f9da 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 @@ -59,7 +59,7 @@ public class ItineraryTest { @Test @DisplayName("Should Not Make Reservation when Passenger name is null") - public void shouldThrowRuntimeExceptionWhenNameIsNull(){ + public void shouldThrowRuntimeExceptionWhenNameIsNull() { String msg = null; try { item1.makeReservation(new Passenger("", "Ab", new Date())); @@ -72,7 +72,7 @@ public class ItineraryTest { @DisplayName("Should Not Make Reservation when Passenger passport number is invalid") @ParameterizedTest @MethodSource("passportNumberList") - public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull(String passportNumber){ + public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull(String passportNumber) { String msg = null; try { item1.makeReservation(new Passenger("John", passportNumber, new Date())); @@ -85,4 +85,12 @@ public class ItineraryTest { private static List 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 Passenger("John", "AB127389", null)); + }); + } } \ No newline at end of file