Browse Source

refactor make reservation

feature-pr-PersonAndItinerary
Sona Markosyan 2 years ago
parent
commit
ab409115b0
  1. 3
      src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java
  2. 16
      src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java
  3. 23
      src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java

3
src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java

@ -20,11 +20,10 @@ public class FlightReservation {
this.status = status;
}
public FlightReservation() {
public FlightReservation(){
}
public String getReservationNumber() {
return reservationNumber;
}

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

@ -1,6 +1,7 @@
package hs.fulda.de.ci.exam.project;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
public class Itinerary {
@ -15,10 +16,6 @@ public class Itinerary {
this.creationDate = creationDate;
}
public List<FlightReservation> getReservations(){
return flightReservationRepository.findAll();
}
public float makeDiscount(float fare, float discountRate){
fare = fare - (fare * discountRate/100);
return fare;
@ -41,13 +38,14 @@ public class Itinerary {
return false;
}
public boolean makeReservation(Passenger passenger){
public FlightReservation makeReservation(FlightSeat flightSeat, Passenger passenger){
HashMap<Passenger, FlightSeat> seatHashMap= new HashMap<Passenger, FlightSeat>();
seatHashMap.put(passenger, flightSeat);
validatePassengerDetails(passenger);
List<FlightReservation> flightReservations = getReservations();
FlightReservation flight = new FlightReservation();
flightReservationRepository.save(flight);
return false;
flight.setSeatMap(seatHashMap);
flight.setStatus(ReservationStatus.Requested);
return flight;
}
public Airport getFinal_airport() {

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

@ -9,9 +9,11 @@ import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import static org.junit.jupiter.api.Assertions.assertThrows;
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;
@ -19,22 +21,22 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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");
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());
final Itinerary item2 = new Itinerary(airport_be, airport_fr, new Date());
@Mock
private ItineraryRepository itineraryRepo;
@Mock
private FlightReservationRepository flightReservationRepository;
@Test
public void test_makePayment() {
@ -62,7 +64,7 @@ public class ItineraryTest {
public void shouldThrowRuntimeExceptionWhenNameIsNull() {
String msg = null;
try {
item1.makeReservation(new Passenger("", "Ab", new Date()));
item1.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("", "Ab", new Date()));
} catch (Exception e) {
msg = e.getMessage();
}
@ -75,7 +77,7 @@ public class ItineraryTest {
public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull(String passportNumber) {
String msg = null;
try {
item1.makeReservation(new Passenger("John", passportNumber, new Date()));
item1.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("John", passportNumber, new Date()));
} catch (Exception e) {
msg = e.getMessage();
}
@ -90,7 +92,14 @@ public class ItineraryTest {
@DisplayName("Should Not Make Reservation when Passenger Birthdate is null")
public void shouldThrowRuntimeExceptionWhenDateIsNull() {
assertThrows(RuntimeException.class, () -> {
item1.makeReservation(new Passenger("John", "AB127389", null));
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);
}
}
Loading…
Cancel
Save