Skip to content

Commit

Permalink
Refactor test a little
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Feb 28, 2025
1 parent 7bdb1e3 commit f5ac386
Showing 1 changed file with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -19,9 +20,10 @@

public class TripMatcherFactoryTest {

public static final FeedScopedId AKT_ID = new FeedScopedId("F", "AKT");
public static final FeedScopedId RUTER1_ID = new FeedScopedId("F", "RUT:1");
public static final FeedScopedId RUTER2_ID = new FeedScopedId("F", "RUT:2");
private static final FeedScopedId AKT_ID = id("AKT");
private static final FeedScopedId RUTER1_ID = id("RUT:1");
private static final FeedScopedId RUTER2_ID = id("RUT:2");
private static final FeedScopedId RUTER_ROUTE1_ID = id("RUT:route:1");
private Trip tripRut;
private Trip tripRut2;
private Trip tripAkt;
Expand All @@ -30,52 +32,50 @@ public class TripMatcherFactoryTest {
void setup() {
tripRut =
Trip
.of(new FeedScopedId("F", "RUT:route:trip:1"))
.of(id("RUT:route:trip:1"))
.withRoute(
Route
.of(new FeedScopedId("F", "RUT:route:1"))
.of(RUTER_ROUTE1_ID)
.withAgency(Agency.of(RUTER1_ID).withName("RUT").withTimezone("Europe/Oslo").build())
.withMode(TransitMode.BUS)
.withShortName("BUS")
.build()
)
.withServiceId(new FeedScopedId("F", "RUT:route:trip:1"))
.withServiceId(id("RUT:route:trip:1"))
.build();
tripRut2 =
Trip
.of(new FeedScopedId("F", "RUT:route:trip:2"))
.of(id("RUT:route:trip:2"))
.withRoute(
Route
.of(new FeedScopedId("F", "RUT:route:2"))
.of(id("RUT:route:2"))
.withAgency(Agency.of(RUTER2_ID).withName("RUT").withTimezone("Europe/Oslo").build())
.withMode(TransitMode.BUS)
.withShortName("BUS")
.build()
)
.withServiceId(new FeedScopedId("F", "RUT:route:trip:2"))
.withServiceId(id("RUT:route:trip:2"))
.build();
tripAkt =
Trip
.of(new FeedScopedId("F", "AKT:route:trip:1"))
.of(id("AKT:route:trip:1"))
.withRoute(
Route
.of(new FeedScopedId("F", "AKT:route:1"))
.of(id("AKT:route:1"))
.withAgency(Agency.of(AKT_ID).withName("AKT").withTimezone("Europe/Oslo").build())
.withMode(TransitMode.BUS)
.withShortName("BUS")
.build()
)
.withServiceId(new FeedScopedId("F", "AKT:route:trip:1"))
.withServiceId(id("AKT:route:trip:1"))
.build();
}

@Test
void testMatchIncludeRouteId() {
TripRequest request = TripRequest
.of()
.withIncludedRoutes(
FilterValues.ofEmptyIsEverything("routes", List.of(new FeedScopedId("F", "RUT:route:1")))
)
.withIncludedRoutes(FilterValues.ofEmptyIsEverything("routes", List.of(RUTER_ROUTE1_ID)))
.build();

Matcher<Trip> matcher = TripMatcherFactory.of(request, feedScopedId -> Set.of());
Expand All @@ -89,9 +89,7 @@ void testMatchIncludeRouteId() {
void testMatchExcludeRouteId() {
TripRequest request = TripRequest
.of()
.withExcludedRoutes(
FilterValues.ofEmptyIsEverything("routes", List.of(new FeedScopedId("F", "RUT:route:1")))
)
.withExcludedRoutes(FilterValues.ofEmptyIsEverything("routes", List.of(RUTER_ROUTE1_ID)))
.build();

Matcher<Trip> matcher = TripMatcherFactory.of(request, feedScopedId -> Set.of());
Expand All @@ -116,9 +114,7 @@ void testMatchDefaultAll() {
void testMatchIncludeAgencyId() {
TripRequest request = TripRequest
.of()
.withIncludedAgencies(
FilterValues.ofEmptyIsEverything("agencies", List.of(new FeedScopedId("F", "RUT:1")))
)
.withIncludedAgencies(FilterValues.ofEmptyIsEverything("agencies", List.of(RUTER1_ID)))
.build();

Matcher<Trip> matcher = TripMatcherFactory.of(request, feedScopedId -> Set.of());
Expand Down Expand Up @@ -208,9 +204,9 @@ void testMatchServiceDates() {
}

private Set<LocalDate> dummyServiceDateProvider(FeedScopedId feedScopedId) {
if (feedScopedId.equals(new FeedScopedId("F", "RUT:route:trip:1"))) {
if (feedScopedId.equals(id("RUT:route:trip:1"))) {
return Set.of(LocalDate.of(2024, 2, 22), LocalDate.of(2024, 2, 23));
} else if (feedScopedId.equals(new FeedScopedId("F", "RUT:route:trip:2"))) {
} else if (feedScopedId.equals(id("RUT:route:trip:2"))) {
return Set.of(LocalDate.of(2024, 2, 23));
}
return Set.of();
Expand Down

0 comments on commit f5ac386

Please sign in to comment.