Skip to content

Commit

Permalink
Fix missing submode on stop place
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Jan 7, 2025
1 parent b0cd0fb commit 6087423
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ public record TransportModeAndSubMode(
AllVehicleModesOfTransportEnumeration mode,
TransportSubMode subMode
) {
private static final Logger LOGGER = LoggerFactory.getLogger(
TransportModeAndSubMode.class
);

public TransportModeAndSubMode {
Objects.requireNonNull(mode, "Transport mode cannot be null");
Objects.requireNonNull(mode, "Transport submode cannot be null");
}

/**
* Return the transport mode and sub-mode for the given stop place.
* Return null if the transport mode is null.
* The submode can be missing, in which case it is mapped to TransportSubMode.MISSING.
*/
@Nullable
public static TransportModeAndSubMode of(StopPlace stopPlace) {
AllVehicleModesOfTransportEnumeration transportMode =
Expand All @@ -34,9 +35,16 @@ public static TransportModeAndSubMode of(StopPlace stopPlace) {
return TransportSubMode
.of(stopPlace)
.map(submode -> new TransportModeAndSubMode(transportMode, submode))
.orElse(null);
.orElse(
new TransportModeAndSubMode(transportMode, TransportSubMode.MISSING)
);
}

/**
* Return the transport mode and sub-mode for the corresponding NeTEx structures.
* Return null if the transport mode is null
* The submode can be missing, in which case it is mapped to TransportSubMode.MISSING.
*/
@Nullable
public static TransportModeAndSubMode of(
AllVehicleModesOfTransportEnumeration transportMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ void testMissingTransportModeAndSubModeFromStopPlace() {
assertNull(transportModeAndSubMode);
}

@Test
void testMissingTransportSubModeFromStopPlace() {
StopPlace stopPlace = new StopPlace();
stopPlace.withTransportMode(AllVehicleModesOfTransportEnumeration.RAIL);
TransportModeAndSubMode transportModeAndSubMode =
TransportModeAndSubMode.of(stopPlace);
assertNotNull(transportModeAndSubMode);
assertEquals(TransportSubMode.MISSING, transportModeAndSubMode.subMode());
}

@Test
void testCreateTransportModeAndSubModeFromStopPlace() {
StopPlace stopPlace = new StopPlace();
Expand Down

0 comments on commit 6087423

Please sign in to comment.