From e6465af3d149b7bb821ef659403f78c6503e6b2e Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Sun, 30 Jan 2022 18:10:18 +0100 Subject: [PATCH 1/3] get frequent flying number of a Customer --- .../hs/fulda/de/ci/exam/project/Customer.java | 19 ++++++++++ .../de/ci/exam/project/CustomerTest.java | 38 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/Customer.java create mode 100644 src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Customer.java b/src/main/java/hs/fulda/de/ci/exam/project/Customer.java new file mode 100644 index 0000000..a85e014 --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/Customer.java @@ -0,0 +1,19 @@ +package hs.fulda.de.ci.exam.project; + + +public class Customer extends Person{ + + private String frequentFlyerNumber; + + public Customer(String name, Address address, String email, String phone) { + super(name, address, email, phone); + } + + public void setFrequentFlyerNumber(String frequentFlyerNumber) { + this.frequentFlyerNumber = frequentFlyerNumber; + } + + public String getFrequentFlyerNumber() { + return frequentFlyerNumber; + } +} diff --git a/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java b/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java new file mode 100644 index 0000000..6c53905 --- /dev/null +++ b/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java @@ -0,0 +1,38 @@ +package hs.fulda.de.ci.exam.project; + +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Field; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CustomerTest { + + final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); + final Customer person1 = new Customer("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206"); + + + @Test + public void test_setFlyingNumber() throws NoSuchFieldException, IllegalAccessException{ + + person1.setFrequentFlyerNumber("5"); + + final Field field = person1.getClass().getDeclaredField("frequentFlyerNumber"); + field.setAccessible(true); + assertEquals(field.get(person1), "5","set frequent flying number of the customer"); + } + + @Test + public void test_getFlyingNumber() throws NoSuchFieldException, IllegalAccessException { + + final Field field = person1.getClass().getDeclaredField("frequentFlyerNumber"); + field.setAccessible(true); + field.set(person1, "10"); + + final String result = person1.getFrequentFlyerNumber(); + + assertEquals(result, "10","get frequent flying number of the customer"); + } + +} From a03a2a6a9aff7968bf43df33fe80c1b33c872838 Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Sun, 30 Jan 2022 22:52:11 +0100 Subject: [PATCH 2/3] adding Itinerary class and repository interface --- .../java/hs/fulda/de/ci/exam/project/Itinerary.java | 10 ++++++++++ .../fulda/de/ci/exam/project/ItineraryRepository.java | 8 ++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/ItineraryRepository.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 new file mode 100644 index 0000000..00a92ce --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java @@ -0,0 +1,10 @@ +package hs.fulda.de.ci.exam.project; + +import java.util.ArrayList; + +public class Itinerary { + + public Itinerary(Airport start_airport, Airport final_airport) { + + } +} diff --git a/src/main/java/hs/fulda/de/ci/exam/project/ItineraryRepository.java b/src/main/java/hs/fulda/de/ci/exam/project/ItineraryRepository.java new file mode 100644 index 0000000..8c4ea5f --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/ItineraryRepository.java @@ -0,0 +1,8 @@ +package hs.fulda.de.ci.exam.project; + +import java.util.ArrayList; + +public interface ItineraryRepository { + ArrayList findAll(); + void save(Itinerary itinerary); +} From 45e8a0e44d91caabcae3c72d19dfa4a8ae670eb9 Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Sun, 30 Jan 2022 22:53:34 +0100 Subject: [PATCH 3/3] get itineraries from repository --- .../hs/fulda/de/ci/exam/project/Customer.java | 9 +++++ .../de/ci/exam/project/CustomerTest.java | 34 ++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Customer.java b/src/main/java/hs/fulda/de/ci/exam/project/Customer.java index a85e014..4d8491f 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Customer.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Customer.java @@ -1,9 +1,14 @@ package hs.fulda.de.ci.exam.project; +import java.util.ArrayList; + public class Customer extends Person{ private String frequentFlyerNumber; + private ItineraryRepository itineraryRepository; + + public Customer(String name, Address address, String email, String phone) { super(name, address, email, phone); @@ -16,4 +21,8 @@ public class Customer extends Person{ public String getFrequentFlyerNumber() { return frequentFlyerNumber; } + + public ArrayList getItineraries() { + return itineraryRepository.findAll(); + } } diff --git a/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java b/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java index 6c53905..dafeff1 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java +++ b/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java @@ -1,17 +1,22 @@ 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.lang.reflect.Field; - -import static org.assertj.core.api.Assertions.assertThat; +import java.util.ArrayList; import static org.junit.jupiter.api.Assertions.assertEquals; +@ExtendWith(MockitoExtension.class) public class CustomerTest { final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); - final Customer person1 = new Customer("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206"); + @InjectMocks + final Customer person1 = new Customer("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206"); @Test public void test_setFlyingNumber() throws NoSuchFieldException, IllegalAccessException{ @@ -35,4 +40,25 @@ public class CustomerTest { assertEquals(result, "10","get frequent flying number of the customer"); } + @Mock + private ItineraryRepository itineraryRepo; + + @Test + public void test_getItineraries() { + 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); + Itinerary item2 = new Itinerary(airport_be, airport_fr); + itineraries.add(item1); + itineraries.add(item2); + + when(itineraryRepo.findAll()).thenReturn(itineraries); + + ArrayList new_itineraries = person1.getItineraries(); + + assertEquals(2, new_itineraries.size(), "Sizes are equal"); + } + }