diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Flight.java b/src/main/java/hs/fulda/de/ci/exam/project/Flight.java index 073d93b..4e6604d 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Flight.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Flight.java @@ -1,7 +1,8 @@ package hs.fulda.de.ci.exam.project; import java.util.HashSet; -import java.util.LinkedList; + +import static hs.fulda.de.ci.exam.project.FlightStatus.Cancelled; public class Flight { String flightNumber; @@ -21,12 +22,35 @@ public class Flight { return this.flightInstances; } - public boolean cancel() { - return true; + public FlightInstance getFlightInstance(FlightInstance fi) { + for (FlightInstance obj : flightInstances) { + if (obj.equals(fi)) + return obj; + } + return null; + } + + public boolean cancel(FlightInstance fInstance1) { + if (flightInstances.contains(fInstance1)) { + for (FlightInstance obj : flightInstances) { + if (obj.equals(fInstance1)) { + obj.status = Cancelled; + System.out.println("Flight intance is cancelled"); + } + } + return true; + } + return false; + } - public boolean addFlightSchedule() { - return true; + public boolean addFlightSchedule(FlightInstance fi) { + flightInstances.add(fi); + if (flightInstances.contains(fi)) { + System.out.println("Flight instance is added"); + return true; + } + return false; } public String getFlightNumber() { diff --git a/src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java b/src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java index 50672a7..edbcaaf 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java @@ -1,4 +1,43 @@ package hs.fulda.de.ci.exam.project; +import java.sql.Time; + public class FlightInstance { + Time departureTime; + String gate; + FlightStatus status; + + public FlightInstance(Time departureTime, String gate, FlightStatus status) { + this.departureTime = departureTime; + this.gate = gate; + this.status = status; + } + + public FlightInstance(){ + + } + + public Time getDepartureTime() { + return departureTime; + } + + public void setDepartureTime(Time departureTime) { + this.departureTime = departureTime; + } + + public String getGate() { + return gate; + } + + public void setGate(String gate) { + this.gate = gate; + } + + public FlightStatus getStatus() { + return status; + } + + public void setStatus(FlightStatus status) { + this.status = status; + } } diff --git a/src/main/java/hs/fulda/de/ci/exam/project/FlightStatus.java b/src/main/java/hs/fulda/de/ci/exam/project/FlightStatus.java new file mode 100644 index 0000000..68aadf2 --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/FlightStatus.java @@ -0,0 +1,5 @@ +package hs.fulda.de.ci.exam.project; + +public enum FlightStatus { + Active, Scheduled, Delayed, Departed, Landed, InAir, Arrived, Cancelled, Diverted, Unknown +} diff --git a/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java b/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java index d6efd42..17d0b9c 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java +++ b/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java @@ -2,9 +2,13 @@ package hs.fulda.de.ci.exam.project; import org.junit.jupiter.api.Test; +import java.sql.Time; import java.util.HashSet; -import static org.assertj.core.api.Assertions.*; +import static hs.fulda.de.ci.exam.project.FlightStatus.Active; +import static hs.fulda.de.ci.exam.project.FlightStatus.Cancelled; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; class FlightTest { @@ -19,7 +23,7 @@ class FlightTest { Flight flight1 = new Flight("1", airport_fr, airport1_ist, 140); Flight flight2 = new Flight("2", airport1_ist, airport_fr, 120); - FlightInstance fInstance1 = new FlightInstance(); + FlightInstance fInstance1 = new FlightInstance(new Time(12, 45, 00), "4E", Active); @Test void getInstances_no_instance_should_be_equal() { @@ -37,13 +41,22 @@ class FlightTest { } @Test - void cancel() { - // TODO: 26.01.22 discussion needed + void addFlightScheduleShoudlAddFlightInstanceWithActiveStatus() { + boolean addInstance = flight1.addFlightSchedule(fInstance1); + assertTrue(addInstance); + FlightStatus result = flight1.getFlightInstance(fInstance1).getStatus(); + FlightStatus expected = Active; + assertThat(expected).isEqualTo(result); } @Test - void addFlightSchedule() { - // TODO: 26.01.22 discussion needed + void cancelingFlightShouldChangeActiveToCancelled() { + boolean addInstance = flight1.addFlightSchedule(fInstance1); + assertTrue(addInstance); + flight1.cancel(fInstance1); + FlightStatus result = flight1.getFlightInstance(fInstance1).getStatus(); + FlightStatus expected = Cancelled; + assertThat(expected).isEqualTo(result); } @Test diff --git a/target/classes/hs/fulda/de/ci/exam/project/Flight.class b/target/classes/hs/fulda/de/ci/exam/project/Flight.class index 7876b6b..4e95dbf 100644 Binary files a/target/classes/hs/fulda/de/ci/exam/project/Flight.class and b/target/classes/hs/fulda/de/ci/exam/project/Flight.class differ diff --git a/target/classes/hs/fulda/de/ci/exam/project/FlightInstance.class b/target/classes/hs/fulda/de/ci/exam/project/FlightInstance.class index 7f4aab6..a6953eb 100644 Binary files a/target/classes/hs/fulda/de/ci/exam/project/FlightInstance.class and b/target/classes/hs/fulda/de/ci/exam/project/FlightInstance.class differ diff --git a/target/test-classes/hs/fulda/de/ci/exam/project/FlightTest.class b/target/test-classes/hs/fulda/de/ci/exam/project/FlightTest.class index a4b7c91..dfb0f03 100644 Binary files a/target/test-classes/hs/fulda/de/ci/exam/project/FlightTest.class and b/target/test-classes/hs/fulda/de/ci/exam/project/FlightTest.class differ