|
| 1 | +package com.bobocode.flight_search; |
| 2 | + |
| 3 | +import com.bobocode.flight_search.factory.FlightServiceFactory; |
| 4 | +import com.bobocode.flight_search.service.FlightService; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import static org.junit.jupiter.api.Assertions.*; |
| 10 | + |
| 11 | +public class FlightServiceTest { |
| 12 | + |
| 13 | + private FlightService flightService = new FlightServiceFactory().creteFlightService(); |
| 14 | + |
| 15 | + @Test |
| 16 | + public void testRegisterFlight() { |
| 17 | + boolean registered = flightService.registerFlight("PR344"); |
| 18 | + |
| 19 | + assertTrue(registered); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void testRegisterSameFlightTwice() { |
| 24 | + flightService.registerFlight("RB122"); |
| 25 | + |
| 26 | + boolean registeredSecondTime = flightService.registerFlight("RB122"); |
| 27 | + |
| 28 | + assertFalse(registeredSecondTime); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testSearchExistingFlightByFullNumber() { |
| 33 | + flightService.registerFlight("OL234"); |
| 34 | + flightService.registerFlight("KM23234"); |
| 35 | + flightService.registerFlight("LTE114"); |
| 36 | + flightService.registerFlight("BRT14"); |
| 37 | + |
| 38 | + List<String> foundFlights = flightService.searchFlights("LTE114"); |
| 39 | + |
| 40 | + assertEquals(1, foundFlights.size()); |
| 41 | + assertEquals("LTE114", foundFlights.get(0)); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testSearchNonExistingFlight() { |
| 46 | + List<String> foundFlights = flightService.searchFlights("XXX"); |
| 47 | + |
| 48 | + assertNotNull(foundFlights); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testSearchFlights() { |
| 53 | + flightService.registerFlight("OR1214"); |
| 54 | + flightService.registerFlight("BTR14"); |
| 55 | + flightService.registerFlight("BMK198"); |
| 56 | + flightService.registerFlight("RLR198"); |
| 57 | + |
| 58 | + List<String> foundFlights = flightService.searchFlights("R1"); |
| 59 | + |
| 60 | + assertTrue(foundFlights.contains("OR1214")); |
| 61 | + assertTrue(foundFlights.contains("BTR14")); |
| 62 | + assertTrue(foundFlights.contains("RLR198")); |
| 63 | + assertEquals(3, foundFlights.size()); |
| 64 | + } |
| 65 | +} |
0 commit comments