diff --git a/src/main/java/org/opentripplanner/apis/gtfs/PatternByServiceDatesFilter.java b/src/main/java/org/opentripplanner/apis/gtfs/PatternByServiceDatesFilter.java index 313c44f2647..c7a0314fbb5 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/PatternByServiceDatesFilter.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/PatternByServiceDatesFilter.java @@ -91,7 +91,7 @@ private boolean hasServicesOnDate(TripPattern pattern) { }); } - public static boolean hasServiceDayFilter(GraphQLServiceDateFilterInput serviceDays) { + public static boolean hasServiceDateFilter(GraphQLServiceDateFilterInput serviceDays) { return ( serviceDays != null && (serviceDays.getGraphQLStart() != null || serviceDays.getGraphQLEnd() != null) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java index d5033af7da7..0936d98cf74 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java @@ -607,7 +607,9 @@ public DataFetcher> routes() { } if ( - PatternByServiceDatesFilter.hasServiceDayFilter(args.getGraphQLLimitByPatternServiceDates()) + PatternByServiceDatesFilter.hasServiceDateFilter( + args.getGraphQLLimitByPatternServiceDates() + ) ) { var filter = new PatternByServiceDatesFilter( transitService, diff --git a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/RouteImpl.java b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/RouteImpl.java index d9b76ab72ef..ac4a485706b 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/RouteImpl.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/RouteImpl.java @@ -181,7 +181,7 @@ public DataFetcher> patterns() { var args = new GraphQLTypes.GraphQLRoutePatternsArgs(environment.getArguments()); - if (PatternByServiceDatesFilter.hasServiceDayFilter(args.getGraphQLServiceDates())) { + if (PatternByServiceDatesFilter.hasServiceDateFilter(args.getGraphQLServiceDates())) { var filter = new PatternByServiceDatesFilter(transitService, args.getGraphQLServiceDates()); return filter.filterPatterns(patterns); } else { diff --git a/src/test/java/org/opentripplanner/apis/gtfs/PatternByServiceDatesFilterTest.java b/src/test/java/org/opentripplanner/apis/gtfs/PatternByServiceDatesFilterTest.java index 2ef9b22f335..09582d67d3c 100644 --- a/src/test/java/org/opentripplanner/apis/gtfs/PatternByServiceDatesFilterTest.java +++ b/src/test/java/org/opentripplanner/apis/gtfs/PatternByServiceDatesFilterTest.java @@ -3,17 +3,22 @@ import static java.time.LocalDate.parse; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.apis.gtfs.PatternByServiceDatesFilterTest.FilterExpectation.NOT_REMOVED; import static org.opentripplanner.apis.gtfs.PatternByServiceDatesFilterTest.FilterExpectation.REMOVED; import java.time.LocalDate; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLServiceDateFilterInput; import org.opentripplanner.model.calendar.CalendarService; import org.opentripplanner.transit.model._data.TransitModelForTest; import org.opentripplanner.transit.model.framework.FeedScopedId; @@ -37,6 +42,7 @@ class PatternByServiceDatesFilterTest { private static final RegularStop STOP_1 = MODEL.stop("1").build(); private static final StopPattern STOP_PATTERN = TransitModelForTest.stopPattern(STOP_1, STOP_1); private static final TripPattern PATTERN_1 = pattern(); + private static final LocalDate DATE = LocalDate.parse("2024-05-27"); enum FilterExpectation { REMOVED, @@ -166,4 +172,28 @@ public Set getServiceIdsOnDate(LocalDate date) { } }; } + + public static List noFilterCases() { + var list = new ArrayList(); + list.add(null); + list.add(new GraphQLServiceDateFilterInput(Map.of())); + return list; + } + + @ParameterizedTest + @MethodSource("noFilterCases") + void hasNoServiceDateFilter(GraphQLServiceDateFilterInput input) { + assertFalse(PatternByServiceDatesFilter.hasServiceDateFilter(input)); + } + + public static List> hasFilterCases() { + return List.of(Map.of("start", DATE), Map.of("end", DATE), Map.of("start", DATE, "end", DATE)); + } + + @ParameterizedTest + @MethodSource("hasFilterCases") + void hasServiceDateFilter(Map params) { + var input = new GraphQLServiceDateFilterInput(params); + assertTrue(PatternByServiceDatesFilter.hasServiceDateFilter(input)); + } }