Skip to content

Commit

Permalink
Assert that all fare products are greater than 0
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Oct 12, 2023
1 parent f88e12d commit 8552aa2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public void routeFromSouthToNorth() {
@Test
public void selectOnlyBusses() {
var modes = Set.of(BUS, WALK);
SmokeTest.basicRouteTest(
var plan = SmokeTest.basicRouteTest(
new SmokeTestRequest(galvestonRoad, northLindale, modes),
List.of("WALK", "BUS", "WALK", "BUS", "WALK", "BUS", "WALK")
);

SmokeTest.assertThatAllTransitLegsHaveFareProducts(plan);
}

@Test
Expand Down
15 changes: 14 additions & 1 deletion src/test/java/org/opentripplanner/smoketest/SmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import org.opentripplanner.client.OtpApiClient;
import org.opentripplanner.client.model.FareProductUse;
import org.opentripplanner.client.model.Itinerary;
import org.opentripplanner.client.model.TripPlan;
import org.opentripplanner.client.model.VehicleRentalStation;
Expand Down Expand Up @@ -115,7 +116,11 @@ static void assertThereArePatternsWithVehiclePositions() {
}

static void assertThatAllTransitLegsHaveFareProducts(TripPlan plan) {
var transitLegs = plan.transitItineraries().stream().flatMap(i -> i.transitLegs().stream());
var transitLegs = plan
.transitItineraries()
.stream()
.flatMap(i -> i.transitLegs().stream())
.toList();
transitLegs.forEach(leg -> {
assertFalse(leg.fareProducts().isEmpty(), "Leg %s should have fare products".formatted(leg));

Expand All @@ -127,5 +132,13 @@ static void assertThatAllTransitLegsHaveFareProducts(TripPlan plan) {
leg.fareProducts().size()
);
});

var fareProducts = transitLegs
.stream()
.flatMap(l -> l.fareProducts().stream().map(FareProductUse::product));
assertTrue(
fareProducts.anyMatch(fp -> fp.price().amount().floatValue() > 0),
"There were no fare product with a price higher than 0."
);
}
}

0 comments on commit 8552aa2

Please sign in to comment.