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 2719856..126aa8b 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 @@ -21,20 +21,19 @@ public class Itinerary { return fare; } - public boolean makePayment(String transactionType, Customer customer, float fare){ + public boolean makePayment(FlightReservation flightReservation, String transactionType, Customer customer, float fare){ if(customer.getItineraries().size() >= 2) { - fare = makeDiscount(fare, 10); - if(transactionType == "Credit"){ - fare = makeDiscount(fare, 15); - System.out.println("Your discount rate is 15%. The total amount of: " + fare + "Euro"); - return true; - } - else if(transactionType == "Cash" || transactionType == "Check") { - System.out.println("Your discount rate is 10%. The total amount of: " + fare + "Euro"); - return true; - } + fare = makeDiscount(fare, 10); + if (transactionType == "Credit") { + fare = makeDiscount(fare, 15); + System.out.println("Your discount rate is 15%. The total amount of: " + fare + "Euro"); + return true; + } else if (transactionType == "Cash" || transactionType == "Check") { + System.out.println("Your discount rate is 10%. The total amount of: " + fare + "Euro"); + return true; + } } - + flightReservation.setStatus(ReservationStatus.Pending); return false; } 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 c430585..bf1e52f 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 @@ -47,10 +47,10 @@ public class ItineraryTest { when(person1.getItineraries()).thenReturn(itineraries); - boolean actualWithCredit = item1.makePayment("Credit", person1, 450); - boolean actualWithCash = item1.makePayment("Cash", person1, 450); - boolean actualWithCheck = item1.makePayment("Check", person1, 450); - boolean actualEmpty = item1.makePayment(" ", person1, 450); + boolean actualWithCredit = item1.makePayment(new FlightReservation(),"Credit", person1, 450); + boolean actualWithCash = item1.makePayment(new FlightReservation(), "Cash", person1, 450); + boolean actualWithCheck = item1.makePayment(new FlightReservation(), "Check", person1, 450); + boolean actualEmpty = item1.makePayment(new FlightReservation(), " ", person1, 450); assertEquals(true, actualWithCash, "The Payment method is successfully chosen"); assertEquals(true, actualWithCash, "The Payment method is successfully chosen"); @@ -59,6 +59,13 @@ public class ItineraryTest { assertEquals(false, actualEmpty, "The Payment method is wrong"); } + @Test + public void test_makePaymentStatus(){ + FlightReservation flightReservation = new FlightReservation(); + item1.makePayment(flightReservation,"Credit", person1, 450); + assertEquals(flightReservation.getStatus(), ReservationStatus.Pending); + } + @Test @DisplayName("Should Not Make Reservation when Passenger name is null") public void shouldThrowRuntimeExceptionWhenNameIsNull() {