From 4a135ff41ca0ab674040e82bccda69f5b351aaa4 Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Tue, 1 Feb 2022 12:44:01 +0100 Subject: [PATCH 1/2] make payment method tested --- .../fulda/de/ci/exam/project/Itinerary.java | 66 ++++++++++++++++++- .../de/ci/exam/project/ItineraryTest.java | 49 ++++++++++++++ 2 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java 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 00a92ce..83e4198 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 @@ -1,10 +1,70 @@ package hs.fulda.de.ci.exam.project; -import java.util.ArrayList; - +import java.util.Date; +import java.util.List; public class Itinerary { - public Itinerary(Airport start_airport, Airport final_airport) { + private Airport start_airport; + private Airport final_airport; + private Date creationDate; + + public Itinerary(Airport start_airport, Airport final_airport, Date creationDate) { + this.start_airport = start_airport; + this.final_airport = final_airport; + this.creationDate = creationDate; + } + + public List getReservations(){ + return null; + } + + public float makeDiscount(float fare, float discountRate){ + fare = fare - (fare * discountRate/100); + return fare; + } + + public boolean makePayment(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; + } + } + + return false; + } + + public Airport getFinal_airport() { + return final_airport; + } + + public Airport getStart_airport() { + return start_airport; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public void setFinal_airport(Airport final_airport) { + this.final_airport = final_airport; + } + public void setStart_airport(Airport start_airport) { + this.start_airport = start_airport; } + + + + } 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 new file mode 100644 index 0000000..841c020 --- /dev/null +++ b/src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java @@ -0,0 +1,49 @@ +package hs.fulda.de.ci.exam.project; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import static org.mockito.Mockito.*; +import org.mockito.junit.jupiter.MockitoExtension; +import java.util.ArrayList; +import java.util.Date; + +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"); + + @InjectMocks + final Customer person1 = new Customer("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206"); + + @Mock + private ItineraryRepository itineraryRepo; + + @Test + public void test_makePayment() { + ArrayList itineraries = new ArrayList<>(); + + Airport airport_fr = new Airport("Fraport", address1, "1234"); + Airport airport_be = new Airport("Berlin", address1, "5678"); + Itinerary item1 = new Itinerary(airport_fr, airport_be, new Date()); + Itinerary item2 = new Itinerary(airport_be, airport_fr, new Date()); + itineraries.add(item1); + itineraries.add(item2); + + 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); + + assertEquals(true, actualWithCash, "The Payment method is successfully chosen"); + assertEquals(true, actualWithCash, "The Payment method is successfully chosen"); + assertEquals(true, actualWithCredit, "The Payment method is successfully chosen"); + assertEquals(true, actualWithCheck, "The Payment method is successfully chosen"); + assertEquals(false, actualEmpty, "The Payment method is wrong"); + } +} \ No newline at end of file From 9845780898ca199eb1e9cb466854b5421a0b9e45 Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Tue, 1 Feb 2022 13:34:30 +0100 Subject: [PATCH 2/2] updated Itinerary --- .../fulda/de/ci/exam/project/FlightReservation.java | 4 ++++ .../exam/project/FlightReservationRepository.java | 8 ++++++++ .../java/hs/fulda/de/ci/exam/project/Itinerary.java | 13 +++++++++++-- .../java/hs/fulda/de/ci/exam/project/Passenger.java | 4 ++++ .../hs/fulda/de/ci/exam/project/ItineraryTest.java | 8 ++++---- 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/Passenger.java diff --git a/src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java b/src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java new file mode 100644 index 0000000..f0e6c8e --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java @@ -0,0 +1,4 @@ +package hs.fulda.de.ci.exam.project; + +public class FlightReservation { +} diff --git a/src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java b/src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java new file mode 100644 index 0000000..5a1a071 --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java @@ -0,0 +1,8 @@ +package hs.fulda.de.ci.exam.project; + +import java.util.ArrayList; + +public interface FlightReservationRepository { + ArrayList findAll(); + void save(FlightReservation flightReservation); +} 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 83e4198..4167fda 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 @@ -7,6 +7,7 @@ public class Itinerary { private Airport start_airport; private Airport final_airport; private Date creationDate; + private FlightReservationRepository flightReservationRepository; public Itinerary(Airport start_airport, Airport final_airport, Date creationDate) { this.start_airport = start_airport; @@ -14,8 +15,8 @@ public class Itinerary { this.creationDate = creationDate; } - public List getReservations(){ - return null; + public List getReservations(){ + return flightReservationRepository.findAll(); } public float makeDiscount(float fare, float discountRate){ @@ -40,6 +41,14 @@ public class Itinerary { return false; } + public boolean makeReservation(Passenger passenger){ + List flightReservations = getReservations(); + FlightReservation flight = new FlightReservation(); + flightReservationRepository.save(flight); + + return false; + } + public Airport getFinal_airport() { return final_airport; } 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 new file mode 100644 index 0000000..8c85690 --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/Passenger.java @@ -0,0 +1,4 @@ +package hs.fulda.de.ci.exam.project; + +public class Passenger { +} 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 841c020..a3b75b7 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 @@ -15,9 +15,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; 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"); @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; @@ -26,10 +30,6 @@ public class ItineraryTest { public void test_makePayment() { ArrayList itineraries = new ArrayList<>(); - Airport airport_fr = new Airport("Fraport", address1, "1234"); - Airport airport_be = new Airport("Berlin", address1, "5678"); - Itinerary item1 = new Itinerary(airport_fr, airport_be, new Date()); - Itinerary item2 = new Itinerary(airport_be, airport_fr, new Date()); itineraries.add(item1); itineraries.add(item2);