Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Nov 25, 2024
1 parent dd69e79 commit 5315ec1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ private Result<UpdateSuccess, UpdateError> apply(
EntityResolver entityResolver
) {
boolean shouldAddNewTrip = false;
for (var call : CallWrapper.of(journey)) {
if (StringUtils.hasNoValueOrNullAsString(call.getStopPointRef())) {
return UpdateError.result(null, EMPTY_STOP_POINT_REF, journey.getDataSource());
}
}
try {
shouldAddNewTrip = shouldAddNewTrip(journey, entityResolver);
Result<TripUpdate, UpdateError> result;
Expand Down Expand Up @@ -230,16 +235,6 @@ private Result<TripUpdate, UpdateError> handleModifiedTrip(
return UpdateError.result(trip != null ? trip.getId() : null, NOT_MONITORED, dataSource);
}

for (var call : CallWrapper.of(estimatedVehicleJourney)) {
if (StringUtils.hasNoValueOrNullAsString(call.getStopPointRef())) {
return UpdateError.result(
trip != null ? trip.getId() : null,
EMPTY_STOP_POINT_REF,
dataSource
);
}
}

LocalDate serviceDate = entityResolver.resolveServiceDate(estimatedVehicleJourney);

if (serviceDate == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertFailure;

import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opentripplanner.updater.siri.SiriEtBuilder;
import org.opentripplanner.updater.spi.UpdateError;
import org.opentripplanner.updater.trip.RealtimeTestConstants;
import org.opentripplanner.updater.trip.RealtimeTestEnvironment;

public class InvalidStopPointRefTest implements RealtimeTestConstants {

@ParameterizedTest
@ValueSource(strings = { "", " ", "\n", "null", " " })
void rejectEmptyStopPointRef(String invalidRef) {
private static Stream<Arguments> cases() {
return Stream
.of("", " ", " ", "\n", "null", "\t", null)
.flatMap(id -> Stream.of(Arguments.of(id, true), Arguments.of(id, false)));
}

@ParameterizedTest(name = "invalid id of ''{0}'', extraJourney={1}")
@MethodSource("cases")
void rejectEmptyStopPointRef(String invalidRef, boolean extraJourney) {
var env = RealtimeTestEnvironment.siri().build();

// journey contains empty stop point ref elements
Expand All @@ -23,6 +31,7 @@ void rejectEmptyStopPointRef(String invalidRef) {
.withEstimatedVehicleJourneyCode("invalid-journey")
.withOperatorRef("unknown-operator")
.withLineRef("unknown-line")
.withIsExtraJourney(extraJourney)
.withEstimatedCalls(builder ->
builder
.call(invalidRef)
Expand Down

0 comments on commit 5315ec1

Please sign in to comment.