From 3854b846076a844be1a37b3880371c79d4ffb639 Mon Sep 17 00:00:00 2001 From: Imron Date: Mon, 24 Jan 2022 21:20:33 +0100 Subject: [PATCH] getFlights with two flights --- .../hs/fulda/de/ci/exam/project/Airport.java | 7 ++++--- .../fulda/de/ci/exam/project/AddressTest.java | 17 ++++++++++++++++ .../fulda/de/ci/exam/project/AirportTest.java | 20 ++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/test/java/hs/fulda/de/ci/exam/project/AddressTest.java diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Airport.java b/src/main/java/hs/fulda/de/ci/exam/project/Airport.java index 8f1ee49..2753031 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Airport.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Airport.java @@ -1,13 +1,14 @@ package hs.fulda.de.ci.exam.project; -import java.util.LinkedList; +import java.util.HashSet; +import java.util.Set; public class Airport { protected String name; public Address address; protected String code; - public LinkedList flights = new LinkedList<>(); + public HashSet flights = new HashSet<>(); public Airport(String name, Address address, String code) { this.name = name; @@ -27,7 +28,7 @@ public class Airport { return this.address; } - public LinkedList getFlights() { + public HashSet getFlights() { return this.flights; } diff --git a/src/test/java/hs/fulda/de/ci/exam/project/AddressTest.java b/src/test/java/hs/fulda/de/ci/exam/project/AddressTest.java new file mode 100644 index 0000000..60ccf8f --- /dev/null +++ b/src/test/java/hs/fulda/de/ci/exam/project/AddressTest.java @@ -0,0 +1,17 @@ +package hs.fulda.de.ci.exam.project; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class AddressTest { + + @BeforeEach + void setUp() { + } + + @Test + void testToString() { + } +} \ No newline at end of file diff --git a/src/test/java/hs/fulda/de/ci/exam/project/AirportTest.java b/src/test/java/hs/fulda/de/ci/exam/project/AirportTest.java index 3ac3bf4..63a66a2 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/AirportTest.java +++ b/src/test/java/hs/fulda/de/ci/exam/project/AirportTest.java @@ -1,9 +1,11 @@ package hs.fulda.de.ci.exam.project; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.HashSet; import java.util.LinkedList; import static org.assertj.core.api.Assertions.*; @@ -11,6 +13,7 @@ import static org.assertj.core.api.Assertions.*; @ExtendWith(MockitoExtension.class) public class AirportTest { + Address address_fr = new Address("Frankfurt str", "Frankfurt", "Hessen", "63023", "Germany"); Airport airport_fr = new Airport("Fraport", address_fr, "1234"); @@ -39,11 +42,26 @@ public class AirportTest { @Test void test_getFlights() { - LinkedList flist = new LinkedList<>(); + HashSet flist = new HashSet<>(); + flist.add(flight1); + + airport_fr.flights.add(flight1); + + assertThat(airport_fr.getFlights()).describedAs("get all flights of the airport").isEqualTo(flist); + } + + @Test + void test_getFlights_wiht_2_flights() { + HashSet flist = new HashSet<>(); flist.add(flight1); + flist.add(flight2); airport_fr.flights.add(flight1); + airport_fr.flights.add(flight1); + airport_fr.flights.add(flight2); assertThat(airport_fr.getFlights()).describedAs("get all flights of the airport").isEqualTo(flist); + + } }