Browse Source

should not make reservation when passenger name is blank

feature-pr-PersonAndItinerary
Sona Markosyan 3 years ago
parent
commit
37804111a5
  1. 7
      src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java
  2. 17
      src/main/java/hs/fulda/de/ci/exam/project/Passenger.java
  3. 16
      src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java

7
src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java

@ -42,6 +42,7 @@ public class Itinerary {
} }
public boolean makeReservation(Passenger passenger){ public boolean makeReservation(Passenger passenger){
validatePassengerDetails(passenger);
List<FlightReservation> flightReservations = getReservations(); List<FlightReservation> flightReservations = getReservations();
FlightReservation flight = new FlightReservation(); FlightReservation flight = new FlightReservation();
flightReservationRepository.save(flight); flightReservationRepository.save(flight);
@ -86,5 +87,11 @@ public class Itinerary {
if(this.creationDate.equals(null)) if(this.creationDate.equals(null))
throw new RuntimeException(("Creation Date should not be null or empty")); throw new RuntimeException(("Creation Date should not be null or empty"));
} }
public void validatePassengerDetails(Passenger passenger){
passenger.validateName();
}
} }

17
src/main/java/hs/fulda/de/ci/exam/project/Passenger.java

@ -1,4 +1,21 @@
package hs.fulda.de.ci.exam.project; package hs.fulda.de.ci.exam.project;
import java.util.Date;
public class Passenger { 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"));
}
} }

16
src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java

@ -1,9 +1,13 @@
package hs.fulda.de.ci.exam.project; 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.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.util.ArrayList; import java.util.ArrayList;
@ -46,4 +50,16 @@ public class ItineraryTest {
assertEquals(true, actualWithCheck, "The Payment method is successfully chosen"); assertEquals(true, actualWithCheck, "The Payment method is successfully chosen");
assertEquals(false, actualEmpty, "The Payment method is wrong"); 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");
}
} }
Loading…
Cancel
Save