Skip to content

Commit

Permalink
Add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed May 27, 2024
1 parent 7168186 commit 56c23fb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,9 @@ public DataFetcher<Iterable<Route>> routes() {
}

if (
PatternByServiceDatesFilter.hasServiceDayFilter(args.getGraphQLLimitByPatternServiceDates())
PatternByServiceDatesFilter.hasServiceDateFilter(
args.getGraphQLLimitByPatternServiceDates()
)
) {
var filter = new PatternByServiceDatesFilter(
transitService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public DataFetcher<Iterable<TripPattern>> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -166,4 +172,28 @@ public Set<FeedScopedId> getServiceIdsOnDate(LocalDate date) {
}
};
}

public static List<GraphQLServiceDateFilterInput> noFilterCases() {
var list = new ArrayList<GraphQLServiceDateFilterInput>();
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<Map<String, Object>> hasFilterCases() {
return List.of(Map.of("start", DATE), Map.of("end", DATE), Map.of("start", DATE, "end", DATE));
}

@ParameterizedTest
@MethodSource("hasFilterCases")
void hasServiceDateFilter(Map<String, Object> params) {
var input = new GraphQLServiceDateFilterInput(params);
assertTrue(PatternByServiceDatesFilter.hasServiceDateFilter(input));
}
}

0 comments on commit 56c23fb

Please sign in to comment.