diff --git a/src/main/java/org/opentripplanner/routing/stoptimes/StopTimesHelper.java b/src/main/java/org/opentripplanner/routing/stoptimes/StopTimesHelper.java index 4426122d84d..109bf7f53c0 100644 --- a/src/main/java/org/opentripplanner/routing/stoptimes/StopTimesHelper.java +++ b/src/main/java/org/opentripplanner/routing/stoptimes/StopTimesHelper.java @@ -52,6 +52,10 @@ public static List stopTimesForStop( ArrivalDeparture arrivalDeparture, boolean includeCancelledTrips ) { + if (numberOfDepartures <= 0) { + return List.of(); + } + List result = new ArrayList<>(); // Fetch all patterns, including those from realtime sources diff --git a/src/test/java/org/opentripplanner/routing/stoptimes/StopTimesHelperTest.java b/src/test/java/org/opentripplanner/routing/stoptimes/StopTimesHelperTest.java index f9cf1898a19..54194696e71 100644 --- a/src/test/java/org/opentripplanner/routing/stoptimes/StopTimesHelperTest.java +++ b/src/test/java/org/opentripplanner/routing/stoptimes/StopTimesHelperTest.java @@ -41,12 +41,29 @@ public static void setUp() throws Exception { tt.getTripTimes(0).cancelTrip(); } + /** + * Case 0, requested number of departure = 0 + */ + @Test + void stopTimesForStop_zeroRequestedNumberOfDeparture() { + var result = StopTimesHelper.stopTimesForStop( + transitService, + transitService.getRegularStop(stopId), + serviceDate.atStartOfDay(transitService.getTimeZone()).toInstant(), + Duration.ofHours(24), + 0, + ArrivalDeparture.BOTH, + true + ); + + assertTrue(result.isEmpty()); + } + /** * Case 1, should find first departure for each pattern when numberOfDepartures is one */ @Test void stopTimesForStop_oneDeparture() { - // Case 1, should find first departure for each pattern var result = StopTimesHelper.stopTimesForStop( transitService, transitService.getRegularStop(stopId),