Skip to content

Commit 4b895f1

Browse files
Merge pull request #136 from danielhep/filter-null-fare-price
Filter null price fare products
2 parents 4211207 + 00bd838 commit 4b895f1

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public ItineraryAssertions withFarePrice(float price, String riderCategoryId, St
7878
.filter(fp -> fp.product().medium().isPresent())
7979
.filter(fp -> fp.product().riderCategory().get().id().equals(riderCategoryId))
8080
.filter(fp -> fp.product().medium().get().id().equals(mediumId))
81+
.filter(fp -> fp.product().price() != null)
8182
.anyMatch(fp -> fp.product().price().amount().floatValue() == price));
8283
return this;
8384
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ void partialMatchesAndErrorDetailsAreIncluded() {
131131

132132
@Test
133133
void withFarePriceHandlesPositiveAndNegativeMatches() {
134-
List<FareProductUse> fares = List.of(fare(2.75f, "orca:regular", "orca:cash"));
134+
List<FareProductUse> fares =
135+
List.of(fare("orca:regular", "orca:cash"), fare(2.75f, "orca:regular", "orca:cash"));
135136
TripPlan plan =
136137
tripPlan(itinerary(transitLeg("E", "E Line", LegMode.BUS, Duration.ofMinutes(12), fares)));
137138

@@ -236,7 +237,18 @@ private static Place place(String name) {
236237
name, 10.0f, 10.0f, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
237238
}
238239

239-
private static FareProductUse fare(float amount, String riderCategoryId, String mediumId) {
240+
private static FareProductUse fare(String riderCategoryId, String mediumId) {
241+
return new FareProductUse(
242+
"fare-" + riderCategoryId + "-" + mediumId,
243+
new FareProductUse.FareProduct(
244+
"product-" + riderCategoryId + "-" + mediumId,
245+
"Test fare",
246+
null,
247+
Optional.of(new FareProductUse.FareProduct.RiderCategory(riderCategoryId, "Rider")),
248+
Optional.of(new FareProductUse.FareProduct.FareMedium(mediumId, "Medium"))));
249+
}
250+
251+
private static FareProductUse fare(Float amount, String riderCategoryId, String mediumId) {
240252
return new FareProductUse(
241253
"fare-" + riderCategoryId + "-" + mediumId,
242254
new FareProductUse.FareProduct(

0 commit comments

Comments
 (0)