Browse Source

search Aircraft by name

feature-pr-Admin
Sona Markosyan 3 years ago
parent
commit
cf44c6aeeb
  1. 8
      src/main/java/hs/fulda/de/ci/exam/project/Admin.java
  2. 2
      src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java
  3. 7
      src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java

8
src/main/java/hs/fulda/de/ci/exam/project/Admin.java

@ -20,6 +20,14 @@ public class Admin extends Person{
return aircraft;
}
public String searchAircraft(String name){
String aircraftDetails = aircraftRepository.findAircraftByAircraftName(name);
if(aircraftDetails.isBlank()){
throw new RuntimeException("Aircraft does not exist.");
}
return aircraftDetails;
}
public String searchFlights(String flightNumber){
String flightDetails = flightRepository.findFlightByFlightNumber(flightNumber);
if(flightDetails.isBlank()){

2
src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java

@ -13,7 +13,7 @@ public class AircraftRepository {
bw.close();
return true;
};
String findAircraftByAircraftNumber(String AircraftName){
String findAircraftByAircraftName(String AircraftName){
File file = new File("aircraft_list.txt");
try {
Scanner scanner = new Scanner(file);

7
src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java

@ -148,4 +148,11 @@ public class AdminTest {
admin.addAircraft("Boeing", "787", -2003);
});
}
@Test
public void test_searchAircraft(){
when(aircraftRepository.findAircraftByAircraftName(any(String.class))).thenReturn(aircraft.toString());
assertNotNull(admin.searchAircraft("Boeing"));
assertEquals(admin.searchAircraft("Boeing"), aircraft.toString());
}
}
Loading…
Cancel
Save