Browse Source

add flight schedule

feature-pr-flight-management
Imron 3 years ago
parent
commit
12668db408
  1. 18
      src/main/java/hs/fulda/de/ci/exam/project/Flight.java
  2. 39
      src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java
  3. 5
      src/main/java/hs/fulda/de/ci/exam/project/FlightStatus.java
  4. 20
      src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java

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

@ -1,7 +1,6 @@
package hs.fulda.de.ci.exam.project; package hs.fulda.de.ci.exam.project;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
public class Flight { public class Flight {
String flightNumber; String flightNumber;
@ -21,12 +20,25 @@ public class Flight {
return this.flightInstances; return this.flightInstances;
} }
public FlightInstance getFlightInstance(FlightInstance fi){
for (FlightInstance obj : flightInstances) {
if (obj.equals(fi))
return obj;
}
return null;
}
public boolean cancel() { public boolean cancel() {
return true; return true;
} }
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() { public String getFlightNumber() {

39
src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java

@ -1,4 +1,43 @@
package hs.fulda.de.ci.exam.project; package hs.fulda.de.ci.exam.project;
import java.sql.Time;
public class FlightInstance { 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;
}
} }

5
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
}

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

@ -2,9 +2,12 @@ package hs.fulda.de.ci.exam.project;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.sql.Time;
import java.util.HashSet; import java.util.HashSet;
import static org.assertj.core.api.Assertions.*;
import static hs.fulda.de.ci.exam.project.FlightStatus.Active;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
class FlightTest { class FlightTest {
@ -19,7 +22,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();
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() {
@ -37,13 +40,12 @@ class FlightTest {
} }
@Test @Test
void cancel() {
// TODO: 26.01.22 discussion needed
}
@Test
void addFlightSchedule() {
// 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 @Test

Loading…
Cancel
Save