Browse Source

add and get flights tests

feature-pr-AirlineClass
Imron 3 years ago
parent
commit
f31d6c24bc
  1. 12
      src/main/java/hs/fulda/de/ci/exam/project/Airline.java
  2. 41
      src/test/java/hs/fulda/de/ci/exam/project/AirlineTest.java

12
src/main/java/hs/fulda/de/ci/exam/project/Airline.java

@ -1,12 +1,16 @@
package hs.fulda.de.ci.exam.project; package hs.fulda.de.ci.exam.project;
import java.util.HashSet;
public class Airline { public class Airline {
private String name; private String name;
private String code; private String code;
private HashSet<Flight> flights;
public Airline(String name, String code) { public Airline(String name, String code) {
this.name = name; this.name = name;
this.code = code; this.code = code;
this.flights = new HashSet<>();
} }
public String getName() { public String getName() {
@ -24,4 +28,12 @@ public class Airline {
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
public HashSet<Flight> getFlights() {
return flights;
}
public void addFlight(Flight flight) {
flights.add(flight);
}
} }

41
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.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import java.util.HashSet;
import static org.assertj.core.api.Assertions.assertThat; 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) @RunWith(MockitoJUnitRunner.class)
public class AirlineTest { public class AirlineTest {
@Test @Test
void testConstructorSetsNameParameterCorrectly(){
void testConstructorSetsNameParameterCorrectly() {
Airline airline = new Airline("Pegasus", "1234"); 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 @Test
void testConstructorSetsCodeParameterCorrectly(){
void testConstructorSetsCodeParameterCorrectly() {
Airline airline = new Airline("Pegasus", "1234"); 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<Flight> 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<Flight> flights = new HashSet<>();
flights.add(flight1);
airline.addFlight(flight1);
assertThat(airline.getFlights())
.describedAs("flights of airline")
.isEqualTo(flights);
}
} }
Loading…
Cancel
Save