Skip to content

Commit

Permalink
Apply some review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 22, 2025
1 parent c206b82 commit aa84c15
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opentripplanner._support.time.DateTimes.ZONED_DATE_TIME_1;
import static org.opentripplanner._support.time.DateTimes.ZONED_DATE_TIME_2;
import static org.opentripplanner._support.time.DateTimes.ANY_ZONED_DATE_TIME_1;
import static org.opentripplanner._support.time.DateTimes.ANY_ZONED_DATE_TIME_2;
import static org.opentripplanner.ext.fares.impl.FareModelForTest.FARE_PRODUCT_USE;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

Expand All @@ -13,7 +13,6 @@
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.opentripplanner._support.time.DateTimes;
import org.opentripplanner.ext.flex.edgetype.FlexTripEdge;
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPath;
import org.opentripplanner.framework.geometry.GeometryUtils;
Expand All @@ -40,7 +39,7 @@ class FlexibleTransitLegBuilderTest implements PlanTestConstants {

@Test
void listsAreInitialized(){
var leg = new FlexibleTransitLegBuilder().withStartTime(ZONED_DATE_TIME_1).withEndTime(ZONED_DATE_TIME_2).withFlexTripEdge(EDGE).build();
var leg = new FlexibleTransitLegBuilder().withStartTime(ANY_ZONED_DATE_TIME_1).withEndTime(ANY_ZONED_DATE_TIME_2).withFlexTripEdge(EDGE).build();
assertNotNull(leg.fareProducts());
assertNotNull(leg.getTransitAlerts());
}
Expand All @@ -57,26 +56,26 @@ void everythingIsNonNull(){

@Test
void copy(){
var leg = new FlexibleTransitLegBuilder().withStartTime(ZONED_DATE_TIME_1).withEndTime(ZONED_DATE_TIME_2).withFlexTripEdge(EDGE)
var leg = new FlexibleTransitLegBuilder().withStartTime(ANY_ZONED_DATE_TIME_1).withEndTime(ANY_ZONED_DATE_TIME_2).withFlexTripEdge(EDGE)
.withFareProducts(List.of(FARE_PRODUCT_USE)).withAlerts(Set.of(ALERT)).build();

var copy = leg.copy().build();

assertEquals(copy.flexTripEdge(), EDGE);
assertEquals(copy.getStartTime(), ZONED_DATE_TIME_1);
assertEquals(copy.getEndTime(), ZONED_DATE_TIME_2);
assertEquals(copy.getStartTime(), ANY_ZONED_DATE_TIME_1);
assertEquals(copy.getEndTime(), ANY_ZONED_DATE_TIME_2);
assertEquals(copy.getTransitAlerts(), Set.of(ALERT));
assertEquals(copy.fareProducts(), List.of(FARE_PRODUCT_USE));
}

@Test
void timeShift(){
var leg = new FlexibleTransitLegBuilder().withStartTime(ZONED_DATE_TIME_1).withEndTime(ZONED_DATE_TIME_2).withFlexTripEdge(EDGE).withFareProducts(List.of(FARE_PRODUCT_USE)).build();
var leg = new FlexibleTransitLegBuilder().withStartTime(ANY_ZONED_DATE_TIME_1).withEndTime(ANY_ZONED_DATE_TIME_2).withFlexTripEdge(EDGE).withFareProducts(List.of(FARE_PRODUCT_USE)).build();

var shifted = leg.withTimeShift(TIME_SHIFT);

assertEquals(ZONED_DATE_TIME_1.plus(TIME_SHIFT), shifted.getStartTime());
assertEquals(ZONED_DATE_TIME_2.plus(TIME_SHIFT), shifted.getEndTime());
assertEquals(ANY_ZONED_DATE_TIME_1.plus(TIME_SHIFT), shifted.getStartTime());
assertEquals(ANY_ZONED_DATE_TIME_2.plus(TIME_SHIFT), shifted.getEndTime());
assertEquals(List.of(FARE_PRODUCT_USE), shifted.fareProducts());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.opentripplanner.ext.stopconsolidation.model;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner._support.time.DateTimes.LOCAL_DATE;
import static org.opentripplanner._support.time.DateTimes.ANY_LOCAL_DATE;
import static org.opentripplanner.ext.fares.impl.FareModelForTest.FARE_PRODUCT_USE;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.opentripplanner._support.time.DateTimes;
import org.opentripplanner._support.time.ZoneIds;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.model.fare.FareProductUse;
Expand All @@ -31,7 +30,7 @@ class ConsolidatedStopLegBuilderTest implements PlanTestConstants{
.build();
private static final ScheduledTransitLeg SCHEDULED_TRANSIT_LEG = new ScheduledTransitLegBuilder<>()
.withZoneId(ZoneIds.BERLIN)
.withServiceDate(LOCAL_DATE)
.withServiceDate(ANY_LOCAL_DATE)
.withTripPattern(PATTERN)
.withBoardStopIndexInPattern(0)
.withAlightStopIndexInPattern(1).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public ScheduledTransitLeg getLeg(TransitService transitService) {
transitService.getTransitAlertService(),
transitService::findMultiModalStation
)
.copyLegWithAlerts(leg, false);
.decorateWithAlerts(leg, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void decorate(Itinerary itinerary) {
final var firstLeg = new AtomicBoolean(true);
itinerary.transformTransitLegs(leg -> {
if (leg.isTransitLeg()) {
var l = alertToLegMapper.copyLegWithAlerts(leg, firstLeg.get());
var l = alertToLegMapper.decorateWithAlerts(leg, firstLeg.get());
firstLeg.set(false);
return l;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Set;
import java.util.function.Function;
import org.opentripplanner.ext.flex.FlexibleTransitLeg;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.model.plan.ScheduledTransitLeg;
import org.opentripplanner.model.plan.StopArrival;
import org.opentripplanner.model.plan.TransitLeg;
Expand Down Expand Up @@ -45,7 +44,7 @@ public AlertToLegMapper(
* @param isFirstLeg Whether the leg is a first leg of the itinerary. This affects the matched
* stop condition.
*/
public TransitLeg copyLegWithAlerts(TransitLeg leg, boolean isFirstLeg) {
public TransitLeg decorateWithAlerts(TransitLeg leg, boolean isFirstLeg) {
// Alert alerts are only relevant for transit legs
if (!leg.isTransitLeg()) {
return leg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

public class DateTimes {

public static final ZonedDateTime ZONED_DATE_TIME_1 = ZonedDateTime.parse(
public static final ZonedDateTime ANY_ZONED_DATE_TIME_1 = ZonedDateTime.parse(
"2025-01-14T14:01:21+01:00"
);
public static final ZonedDateTime ZONED_DATE_TIME_2 = ZONED_DATE_TIME_1.plusHours(3);
public static final LocalDate LOCAL_DATE = LocalDate.of(2025, 1, 15);
public static final ZonedDateTime ANY_ZONED_DATE_TIME_2 = ANY_ZONED_DATE_TIME_1.plusHours(3);
public static final LocalDate ANY_LOCAL_DATE = LocalDate.of(2025, 1, 15);
}

0 comments on commit aa84c15

Please sign in to comment.