diff --git a/application/src/main/java/org/opentripplanner/service/vehiclerental/street/VehicleRentalEdge.java b/application/src/main/java/org/opentripplanner/service/vehiclerental/street/VehicleRentalEdge.java index 0935909e0c7..4633392cf05 100644 --- a/application/src/main/java/org/opentripplanner/service/vehiclerental/street/VehicleRentalEdge.java +++ b/application/src/main/java/org/opentripplanner/service/vehiclerental/street/VehicleRentalEdge.java @@ -33,7 +33,7 @@ public static VehicleRentalEdge createVehicleRentalEdge( @Override public State[] traverse(State s0) { - if (!s0.getRequest().mode().includesRenting()) { + if (!s0.getRequest().mode().includesRenting() || s0.getVehicleRentalState() == null) { return State.empty(); } diff --git a/application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java b/application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java index b606bcd9962..6919f0f8bbe 100644 --- a/application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java +++ b/application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java @@ -330,7 +330,9 @@ public State[] traverse(State s0) { final StateEditor editor; final boolean arriveByRental = - s0.getRequest().mode().includesRenting() && s0.getRequest().arriveBy(); + s0.getRequest().mode().includesRenting() && + s0.getRequest().arriveBy() && + s0.getVehicleRentalState() != null; if (arriveByRental && tov.rentalTraversalBanned(s0)) { return State.empty(); } else if (arriveByRental && hasStartedWalkingInNoDropOffZoneAndIsExitingIt(s0)) { diff --git a/application/src/main/java/org/opentripplanner/street/search/state/StateData.java b/application/src/main/java/org/opentripplanner/street/search/state/StateData.java index 648b2f3110c..435b48b035b 100644 --- a/application/src/main/java/org/opentripplanner/street/search/state/StateData.java +++ b/application/src/main/java/org/opentripplanner/street/search/state/StateData.java @@ -172,6 +172,7 @@ else if (requestMode.includesRenting()) { stationReturnedStateData.vehicleRentalState = HAVE_RENTED; stationReturnedStateData.currentMode = TraverseMode.WALK; res.add(stationReturnedStateData); + res.add(proto.clone()); } else { var beforeRentalStateData = proto.clone(); beforeRentalStateData.vehicleRentalState = BEFORE_RENTING; diff --git a/application/src/test/java/org/opentripplanner/street/integration/BikeRentalTest.java b/application/src/test/java/org/opentripplanner/street/integration/BikeRentalTest.java index 8dc1e240392..187b6b3679c 100644 --- a/application/src/test/java/org/opentripplanner/street/integration/BikeRentalTest.java +++ b/application/src/test/java/org/opentripplanner/street/integration/BikeRentalTest.java @@ -168,10 +168,10 @@ public void testNoBikesAvailable() { "null - BEFORE_RENTING - E1 (1,656.14, 828)" ), List.of( - "WALK - HAVE_RENTED - AB street (76.19, 38)", - "WALK - HAVE_RENTED - BC street (1,579.95, 790)", - "WALK - HAVE_RENTED - CD street (1,655.14, 828)", - "null - HAVE_RENTED - E1 (1,656.14, 828)" + "WALK - null - AB street (76.19, 38)", + "WALK - null - BC street (1,579.95, 790)", + "WALK - null - CD street (1,655.14, 828)", + "null - null - E1 (1,656.14, 828)" ) ); } @@ -450,7 +450,7 @@ private void assertNoRental( ); assertEquals( - List.of("WALK - HAVE_RENTED - BC street (1,503.76, 752)"), + List.of("WALK - null - BC street (1,503.76, 752)"), runStreetSearchAndCreateDescriptor(fromVertex, toVertex, true, setter), "arriveBy" ); diff --git a/application/src/test/java/org/opentripplanner/street/search/state/StateTest.java b/application/src/test/java/org/opentripplanner/street/search/state/StateTest.java index 9722f1dd785..c1c580d26f2 100644 --- a/application/src/test/java/org/opentripplanner/street/search/state/StateTest.java +++ b/application/src/test/java/org/opentripplanner/street/search/state/StateTest.java @@ -48,15 +48,24 @@ class StateTest { NULL_RENTAL_STATES.add(null); } + static Set setOfWithNull(VehicleRentalState... states) { + var set = new HashSet(); + set.add(null); + for (var state : states) { + set.add(state); + } + return set; + } + static Stream testCases() { return Stream.of( of(SCOOTER_RENTAL, false, Set.of(BEFORE_RENTING), Set.of(WALK)), //FIXME: it's strange that the arriveBy rental searches all start on a bicycle - of(SCOOTER_RENTAL, true, Set.of(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)), + of(SCOOTER_RENTAL, true, setOfWithNull(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)), of(BIKE_RENTAL, false, Set.of(BEFORE_RENTING), Set.of(WALK)), - of(BIKE_RENTAL, true, Set.of(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)), + of(BIKE_RENTAL, true, setOfWithNull(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)), of(CAR_RENTAL, false, Set.of(BEFORE_RENTING), Set.of(WALK)), - of(CAR_RENTAL, true, Set.of(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)), + of(CAR_RENTAL, true, setOfWithNull(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)), of(StreetMode.CAR, false, NULL_RENTAL_STATES, Set.of(CAR)), of(BIKE, false, NULL_RENTAL_STATES, Set.of(BICYCLE)), of(StreetMode.WALK, false, NULL_RENTAL_STATES, Set.of(TraverseMode.WALK)),