From f31d6c24bc21d605091cbcf5fcdd9db5f6b76534 Mon Sep 17 00:00:00 2001 From: Imron Date: Sun, 30 Jan 2022 19:54:08 +0100 Subject: [PATCH] add and get flights tests --- .../hs/fulda/de/ci/exam/project/Airline.java | 12 ++++++ .../fulda/de/ci/exam/project/AirlineTest.java | 41 ++++++++++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Airline.java b/src/main/java/hs/fulda/de/ci/exam/project/Airline.java index aa9d0fb..1a85b40 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Airline.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Airline.java @@ -1,12 +1,16 @@ package hs.fulda.de.ci.exam.project; +import java.util.HashSet; + public class Airline { private String name; private String code; + private HashSet flights; public Airline(String name, String code) { this.name = name; this.code = code; + this.flights = new HashSet<>(); } public String getName() { @@ -24,4 +28,12 @@ public class Airline { public void setCode(String code) { this.code = code; } + + public HashSet getFlights() { + return flights; + } + + public void addFlight(Flight flight) { + flights.add(flight); + } } diff --git a/src/test/java/hs/fulda/de/ci/exam/project/AirlineTest.java b/src/test/java/hs/fulda/de/ci/exam/project/AirlineTest.java index e4ee951..6230300 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/AirlineTest.java +++ b/src/test/java/hs/fulda/de/ci/exam/project/AirlineTest.java @@ -4,19 +4,50 @@ import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; +import java.util.HashSet; + import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.mock; @RunWith(MockitoJUnitRunner.class) public class AirlineTest { @Test - void testConstructorSetsNameParameterCorrectly(){ + void testConstructorSetsNameParameterCorrectly() { Airline airline = new Airline("Pegasus", "1234"); - assertThat(airline.getName()).describedAs("name of airline").isEqualTo("Pegasus"); + assertThat(airline.getName()) + .describedAs("name of airline") + .isEqualTo("Pegasus"); } + @Test - void testConstructorSetsCodeParameterCorrectly(){ + void testConstructorSetsCodeParameterCorrectly() { Airline airline = new Airline("Pegasus", "1234"); - assertThat(airline.getCode()).describedAs("code of airline").isEqualTo("1234"); + assertThat(airline.getCode()) + .describedAs("code of airline") + .isEqualTo("1234"); } + + @Test + void getFlightsReturnsEmptyListOfFlights() { + Airline airline = new Airline("Pegasus", "1234"); + HashSet flights = new HashSet<>(); + assertThat(airline.getFlights()) + .describedAs("flights of airline") + .isEqualTo(flights); + } + + @Test + void addFlightAddsFlightToListOfFlights() { + Airline airline = new Airline("Pegasus", "1234"); + Flight flight1 = mock(Flight.class); + HashSet flights = new HashSet<>(); + flights.add(flight1); + + airline.addFlight(flight1); + + assertThat(airline.getFlights()) + .describedAs("flights of airline") + .isEqualTo(flights); + } + }