Skip to content

Commit e931d83

Browse files
Merge pull request #135 from danielhep/assertions-filter-by-isTransit
Assertions: fix crash on non-transit legs
2 parents 0ac743c + fbe9ded commit e931d83

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

assertions/src/main/java/org/opentripplanner/assertions/ItineraryAssertions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ public void assertMatches(TripPlan tripPlan) {
162162
* <p>If strict transit matching is enabled, all transit legs must match some requirement.
163163
*/
164164
private ItineraryMatchResult matchesAllLegs(Itinerary itinerary) {
165-
List<Leg> remainingLegs = new ArrayList<>(itinerary.legs());
165+
List<Leg> remainingLegs =
166+
itinerary.legs().stream().filter(Leg::isTransit).collect(Collectors.toList());
166167
List<String> errors = new ArrayList<>();
167168
List<LegMatchingState> completeMatches = new ArrayList<>();
168169
List<LegMatchingState> partialMatches = new ArrayList<>();

assertions/src/test/java/org/opentripplanner/assertions/ItineraryAssertionsTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ void singleLegMatchSuccess() {
4545
.assertMatches(plan));
4646
}
4747

48+
@Test
49+
void nonTransitLegsAreIgnored() {
50+
TripPlan plan =
51+
tripPlan(
52+
itinerary(
53+
walkLeg(Duration.ofMinutes(10)),
54+
transitLeg("10", "Route 10", LegMode.BUS, Duration.ofMinutes(20), List.of()),
55+
walkLeg(Duration.ofMinutes(10))));
56+
57+
assertDoesNotThrow(
58+
() ->
59+
new ItineraryAssertions()
60+
.withStrictTransitMatching()
61+
.hasLeg()
62+
.withRouteShortName("10")
63+
.assertMatches(plan));
64+
}
65+
4866
@Test
4967
void multiLegMatchSuccess() {
5068
TripPlan plan =
@@ -155,6 +173,28 @@ private static Itinerary itinerary(Leg... legs) {
155173
return new Itinerary(List.of(legs), OptionalDouble.empty());
156174
}
157175

176+
private static Leg walkLeg(Duration duration) {
177+
return new Leg(
178+
place("Walk From"),
179+
place("Walk To"),
180+
START,
181+
START.plus(duration),
182+
false,
183+
false,
184+
LegMode.WALK,
185+
duration,
186+
1000,
187+
Optional.empty(),
188+
null,
189+
null,
190+
List.of(),
191+
OptionalDouble.empty(),
192+
null,
193+
new LegGeometry(GEOMETRY),
194+
false,
195+
Optional.empty());
196+
}
197+
158198
private static Leg transitLeg(
159199
String routeShortName,
160200
String routeLongName,

0 commit comments

Comments
 (0)