Browse Source

flight cancellation

feature-pr-flight-management
Imron 3 years ago
parent
commit
252216de6b
  1. 16
      src/main/java/hs/fulda/de/ci/exam/project/Flight.java
  2. 13
      src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java
  3. BIN
      target/classes/hs/fulda/de/ci/exam/project/Flight.class
  4. BIN
      target/classes/hs/fulda/de/ci/exam/project/FlightInstance.class
  5. BIN
      target/test-classes/hs/fulda/de/ci/exam/project/FlightTest.class

16
src/main/java/hs/fulda/de/ci/exam/project/Flight.java

@ -2,6 +2,8 @@ package hs.fulda.de.ci.exam.project;
import java.util.HashSet; import java.util.HashSet;
import static hs.fulda.de.ci.exam.project.FlightStatus.Cancelled;
public class Flight { public class Flight {
String flightNumber; String flightNumber;
Airport departure; Airport departure;
@ -20,7 +22,7 @@ public class Flight {
return this.flightInstances; return this.flightInstances;
} }
public FlightInstance getFlightInstance(FlightInstance fi){
public FlightInstance getFlightInstance(FlightInstance fi) {
for (FlightInstance obj : flightInstances) { for (FlightInstance obj : flightInstances) {
if (obj.equals(fi)) if (obj.equals(fi))
return obj; return obj;
@ -28,9 +30,19 @@ public class Flight {
return null; return null;
} }
public boolean cancel() {
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 true;
} }
return false;
}
public boolean addFlightSchedule(FlightInstance fi) { public boolean addFlightSchedule(FlightInstance fi) {
flightInstances.add(fi); flightInstances.add(fi);

13
src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java

@ -6,6 +6,7 @@ import java.sql.Time;
import java.util.HashSet; import java.util.HashSet;
import static hs.fulda.de.ci.exam.project.FlightStatus.Active; 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.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -22,7 +23,7 @@ class FlightTest {
Flight flight1 = new Flight("1", airport_fr, airport1_ist, 140); Flight flight1 = new Flight("1", airport_fr, airport1_ist, 140);
Flight flight2 = new Flight("2", airport1_ist, airport_fr, 120); Flight flight2 = new Flight("2", airport1_ist, airport_fr, 120);
FlightInstance fInstance1 = new FlightInstance(new Time(12,45,00), "4E", Active);
FlightInstance fInstance1 = new FlightInstance(new Time(12, 45, 00), "4E", Active);
@Test @Test
void getInstances_no_instance_should_be_equal() { void getInstances_no_instance_should_be_equal() {
@ -48,6 +49,16 @@ class FlightTest {
assertThat(expected).isEqualTo(result); assertThat(expected).isEqualTo(result);
} }
@Test
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 @Test
void getFlightNumber() { void getFlightNumber() {
assertThat(flight1.getFlightNumber()).describedAs("get flight number of the flight").isEqualTo("1"); assertThat(flight1.getFlightNumber()).describedAs("get flight number of the flight").isEqualTo("1");

BIN
target/classes/hs/fulda/de/ci/exam/project/Flight.class

BIN
target/classes/hs/fulda/de/ci/exam/project/FlightInstance.class

BIN
target/test-classes/hs/fulda/de/ci/exam/project/FlightTest.class

Loading…
Cancel
Save