|
| 1 | +package org.opentripplanner.updater.vehicle_rental.datasources.gbfs.v3; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | +import static org.junit.jupiter.params.provider.Arguments.argumentSet; |
| 6 | + |
| 7 | +import java.util.List; |
| 8 | +import java.util.stream.Stream; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.junit.jupiter.params.ParameterizedTest; |
| 11 | +import org.junit.jupiter.params.provider.Arguments; |
| 12 | +import org.junit.jupiter.params.provider.MethodSource; |
| 13 | +import org.mobilitydata.gbfs.v3_0.station_information.GBFSName; |
| 14 | +import org.mobilitydata.gbfs.v3_0.station_information.GBFSStation; |
| 15 | + |
| 16 | +class GbfsStationInformationMapperTest { |
| 17 | + |
| 18 | + private static final String TEST_STATION_ID = "TEST_STATION_ID"; |
| 19 | + private static final String TEST_STATION_NAME = "TEST_STATION_NAME"; |
| 20 | + |
| 21 | + @Test |
| 22 | + void acceptValidStation() { |
| 23 | + assertTrue(GbfsStationInformationMapper.isValid(validStation())); |
| 24 | + } |
| 25 | + |
| 26 | + @ParameterizedTest |
| 27 | + @MethodSource("provideInvalidStations") |
| 28 | + void invalidStationsShouldFail(GBFSStation station) { |
| 29 | + assertFalse(GbfsStationInformationMapper.isValid(station)); |
| 30 | + } |
| 31 | + |
| 32 | + private static GBFSStation validStation() { |
| 33 | + return new GBFSStation() |
| 34 | + .withLat(0d) |
| 35 | + .withLon(0d) |
| 36 | + .withStationId(TEST_STATION_ID) |
| 37 | + .withName(List.of(new GBFSName().withText(TEST_STATION_NAME).withLanguage("EN"))); |
| 38 | + } |
| 39 | + |
| 40 | + private static Stream<Arguments> provideInvalidStations() { |
| 41 | + return Stream.of( |
| 42 | + argumentSet("Missing station ID", validStation().withStationId(null)), |
| 43 | + argumentSet("Missing latitude", validStation().withLat(null)), |
| 44 | + argumentSet("Missing longitude", validStation().withLon(null)), |
| 45 | + argumentSet("Missing station name list", validStation().withName(null)), |
| 46 | + argumentSet("Empty station name list", validStation().withName(List.of())), |
| 47 | + argumentSet( |
| 48 | + "Station name list contains null name", |
| 49 | + validStation() |
| 50 | + .withName( |
| 51 | + List.of(new GBFSName().withText(TEST_STATION_NAME), new GBFSName().withText(null)) |
| 52 | + ) |
| 53 | + ), |
| 54 | + argumentSet( |
| 55 | + "Station name list contains empty name", |
| 56 | + validStation() |
| 57 | + .withName( |
| 58 | + List.of(new GBFSName().withText(TEST_STATION_NAME), new GBFSName().withText("")) |
| 59 | + ) |
| 60 | + ), |
| 61 | + argumentSet( |
| 62 | + "Station name list contains null language", |
| 63 | + validStation() |
| 64 | + .withName( |
| 65 | + List.of(new GBFSName().withText(TEST_STATION_NAME), new GBFSName().withLanguage(null)) |
| 66 | + ) |
| 67 | + ), |
| 68 | + argumentSet( |
| 69 | + "Station name list contains empty language", |
| 70 | + validStation() |
| 71 | + .withName( |
| 72 | + List.of(new GBFSName().withText(TEST_STATION_NAME), new GBFSName().withLanguage("")) |
| 73 | + ) |
| 74 | + ) |
| 75 | + ); |
| 76 | + } |
| 77 | +} |
0 commit comments