From 63fdbe225545baec06a4b6fb9c939c9d8d5f3d61 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 28 Feb 2025 09:28:49 +0100 Subject: [PATCH] Refactor test a little --- .../transit/TripMatcherFactoryTest.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/TripMatcherFactoryTest.java b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/TripMatcherFactoryTest.java index 72516780771..ebb554d4047 100644 --- a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/TripMatcherFactoryTest.java +++ b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/TripMatcherFactoryTest.java @@ -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; @@ -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; @@ -30,42 +32,42 @@ 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(); } @@ -73,9 +75,7 @@ void setup() { 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 matcher = TripMatcherFactory.of(request, feedScopedId -> Set.of()); @@ -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 matcher = TripMatcherFactory.of(request, feedScopedId -> Set.of()); @@ -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 matcher = TripMatcherFactory.of(request, feedScopedId -> Set.of()); @@ -208,9 +204,9 @@ void testMatchServiceDates() { } private Set 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();