From cf44c6aeeb7e07d4cbccf33a17d26d989d8aee31 Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Thu, 10 Feb 2022 01:36:48 +0100 Subject: [PATCH] search Aircraft by name --- src/main/java/hs/fulda/de/ci/exam/project/Admin.java | 8 ++++++++ .../hs/fulda/de/ci/exam/project/AircraftRepository.java | 2 +- src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Admin.java b/src/main/java/hs/fulda/de/ci/exam/project/Admin.java index cd4cb6b..ce8cb1e 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Admin.java +++ b/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()){ diff --git a/src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java b/src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java index 241363f..29fec15 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java +++ b/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); diff --git a/src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java b/src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java index f127a73..9a6f2e9 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java +++ b/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()); + } }