Browse Source

refactor make reservation

feature-pr-PersonAndItinerary
Sona Markosyan 3 years ago
parent
commit
ab409115b0
  1. 1
      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

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

@ -24,7 +24,6 @@ public class FlightReservation {
} }
public String getReservationNumber() { public String getReservationNumber() {
return reservationNumber; 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; package hs.fulda.de.ci.exam.project;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
public class Itinerary { public class Itinerary {
@ -15,10 +16,6 @@ public class Itinerary {
this.creationDate = creationDate; this.creationDate = creationDate;
} }
public List<FlightReservation> getReservations(){
return flightReservationRepository.findAll();
}
public float makeDiscount(float fare, float discountRate){ public float makeDiscount(float fare, float discountRate){
fare = fare - (fare * discountRate/100); fare = fare - (fare * discountRate/100);
return fare; return fare;
@ -41,13 +38,14 @@ public class Itinerary {
return false; 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); validatePassengerDetails(passenger);
List<FlightReservation> flightReservations = getReservations();
FlightReservation flight = new FlightReservation(); FlightReservation flight = new FlightReservation();
flightReservationRepository.save(flight);
return false;
flight.setSeatMap(seatHashMap);
flight.setStatus(ReservationStatus.Requested);
return flight;
} }
public Airport getFinal_airport() { 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.InjectMocks;
import org.mockito.Mock; 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 static org.mockito.Mockito.*;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -19,22 +21,22 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class ItineraryTest { public class ItineraryTest {
final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany");
final Airport airport_fr = new Airport("Fraport", address1, "1234"); final Airport airport_fr = new Airport("Fraport", address1, "1234");
final Airport airport_be = new Airport("Berlin", address1, "5678"); final Airport airport_be = new Airport("Berlin", address1, "5678");
final Itinerary item2 = new Itinerary(airport_be, airport_fr, new Date());
@InjectMocks @InjectMocks
final Customer person1 = new Customer("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206"); 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 item1 = new Itinerary(airport_fr, airport_be, new Date());
final Itinerary item2 = new Itinerary(airport_be, airport_fr, new Date());
@Mock @Mock
private ItineraryRepository itineraryRepo; private ItineraryRepository itineraryRepo;
@Mock
private FlightReservationRepository flightReservationRepository;
@Test @Test
public void test_makePayment() { public void test_makePayment() {
@ -62,7 +64,7 @@ public class ItineraryTest {
public void shouldThrowRuntimeExceptionWhenNameIsNull() { public void shouldThrowRuntimeExceptionWhenNameIsNull() {
String msg = null; String msg = null;
try { try {
item1.makeReservation(new Passenger("", "Ab", new Date()));
item1.makeReservation(new FlightSeat(1000.0, "5"), new Passenger("", "Ab", new Date()));
} catch (Exception e) { } catch (Exception e) {
msg = e.getMessage(); msg = e.getMessage();
} }
@ -75,7 +77,7 @@ public class ItineraryTest {
public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull(String passportNumber) { public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull(String passportNumber) {
String msg = null; String msg = null;
try { 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) { } catch (Exception e) {
msg = e.getMessage(); msg = e.getMessage();
} }
@ -90,7 +92,14 @@ public class ItineraryTest {
@DisplayName("Should Not Make Reservation when Passenger Birthdate is null") @DisplayName("Should Not Make Reservation when Passenger Birthdate is null")
public void shouldThrowRuntimeExceptionWhenDateIsNull() { public void shouldThrowRuntimeExceptionWhenDateIsNull() {
assertThrows(RuntimeException.class, () -> { 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