22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
44import static org .junit .jupiter .api .Assertions .assertFalse ;
5+ import static org .junit .jupiter .api .Assertions .assertTrue ;
56import static org .opentripplanner .transit .model .basic .TransitMode .BUS ;
67import static org .opentripplanner .transit .model .basic .TransitMode .FERRY ;
78import static org .opentripplanner .transit .model .basic .TransitMode .RAIL ;
@@ -47,7 +48,10 @@ class DefaultTransitServiceTest {
4748 .withParentStation (STATION )
4849 .build ();
4950 private static final RegularStop STOP_B = TEST_MODEL .stop ("B" ).withParentStation (STATION ).build ();
50-
51+ private static final RegularStop STOP_C = TEST_MODEL .stop ("C" ).withVehicleType (BUS ).build ();
52+ private static final RegularStop STOP_ONE = TEST_MODEL .stop ("Stop_1" )
53+ .withVehicleType (TRAM )
54+ .build ();
5155 private static final FeedScopedId SERVICE_ID = new FeedScopedId ("FEED" , "SERVICE" );
5256 private static final int SERVICE_CODE = 0 ;
5357 private static final TripPattern FERRY_PATTERN = TEST_MODEL .pattern (FERRY ).build ();
@@ -90,6 +94,22 @@ class DefaultTransitServiceTest {
9094 .withServiceCode (SERVICE_CODE )
9195 .build ();
9296
97+ static FeedScopedId CALENDAR_ID_TWO = TimetableRepositoryForTest .id ("CAL_2" );
98+ static Trip TRIP_TODAY = TimetableRepositoryForTest .trip ("12345" )
99+ .withHeadsign (I18NString .of ("Trip Headsign" ))
100+ .withServiceId (CALENDAR_ID_TWO )
101+ .build ();
102+ private static final ScheduledTripTimes SCHEDULED_TRIP_TIMES_TODAY = ScheduledTripTimes .of ()
103+ .withTrip (TRIP_TODAY )
104+ .withArrivalTimes (new int [] { 0 , 1 })
105+ .withDepartureTimes (new int [] { 0 , 1 })
106+ .withServiceCode (SERVICE_CODE )
107+ .build ();
108+ private static final TripPattern BUS_PATTERN_TODAY = TEST_MODEL .pattern (BUS )
109+ .withStopPattern (REAL_TIME_STOP_PATTERN )
110+ .withScheduledTimeTableBuilder (builder -> builder .addTripTimes (SCHEDULED_TRIP_TIMES_TODAY ))
111+ .build ();
112+
93113 private static final LocalDate SERVICE_DATE = LocalDate .of (2024 , 1 , 1 );
94114 private static final LocalDate NO_SERVICE_DATE = LocalDate .of (2024 , 1 , 2 );
95115
@@ -107,43 +127,57 @@ static void setup() {
107127 var siteRepository = TEST_MODEL .siteRepositoryBuilder ()
108128 .withRegularStop (STOP_A )
109129 .withRegularStop (STOP_B )
130+ .withRegularStop (STOP_C )
131+ .withRegularStop (STOP_ONE )
110132 .withStation (STATION )
111133 .build ();
112134
113135 var deduplicator = new Deduplicator ();
114- var transitModel = new TimetableRepository (siteRepository , deduplicator );
136+ var timetableRepository = new TimetableRepository (siteRepository , new Deduplicator () );
115137 var canceledStopTimes = TEST_MODEL .stopTimesEvery5Minutes (3 , TRIP , "11:30" );
116138 var canceledTripTimes = TripTimesFactory .tripTimes (TRIP , canceledStopTimes , deduplicator )
117139 .createRealTimeFromScheduledTimes ()
118140 .cancelTrip ()
119141 .build ();
120- transitModel .addTripPattern (RAIL_PATTERN .getId (), RAIL_PATTERN );
142+ timetableRepository .addTripPattern (RAIL_PATTERN .getId (), RAIL_PATTERN );
121143
122144 // Crate a calendar (needed for testing cancelled trips)
123145 CalendarServiceData calendarServiceData = new CalendarServiceData ();
124146 var firstDate = LocalDate .of (2024 , 8 , 8 );
125147 var secondDate = LocalDate .of (2024 , 8 , 9 );
148+ var thirdDate = LocalDate .of (2025 , 7 , 2 );
149+
126150 calendarServiceData .putServiceDatesForServiceId (
127151 CALENDAR_ID ,
128- List .of (firstDate , secondDate , SERVICE_DATE )
152+ List .of (firstDate , secondDate , thirdDate , SERVICE_DATE )
153+ );
154+ calendarServiceData .putServiceDatesForServiceId (
155+ CALENDAR_ID_TWO ,
156+ List .of (firstDate , secondDate )
129157 );
130- transitModel .getServiceCodes ().put (CALENDAR_ID , 0 );
131- transitModel .updateCalendarServiceData (true , calendarServiceData , DataImportIssueStore .NOOP );
132158
133- transitModel .index ();
134- var timetableRepository = new TimetableRepository (siteRepository , new Deduplicator ());
135- var calendar = new CalendarServiceData ();
136- calendar .putServiceDatesForServiceId (SERVICE_ID , List .of (SERVICE_DATE ));
137159 var serviceCodes = timetableRepository .getServiceCodes ();
138160 serviceCodes .put (SERVICE_ID , SERVICE_CODE );
139- timetableRepository .updateCalendarServiceData (true , calendar , DataImportIssueStore .NOOP );
161+ serviceCodes .put (CALENDAR_ID , SERVICE_CODE );
162+ serviceCodes .put (CALENDAR_ID_TWO , 1 );
163+
140164 timetableRepository .addTripPattern (RAIL_PATTERN .getId (), RAIL_PATTERN );
165+ timetableRepository .addTripPattern (BUS_PATTERN .getId (), BUS_PATTERN );
166+ timetableRepository .addTripPattern (BUS_PATTERN_TODAY .getId (), BUS_PATTERN_TODAY );
167+
168+ timetableRepository .updateCalendarServiceData (
169+ true ,
170+ calendarServiceData ,
171+ DataImportIssueStore .NOOP
172+ );
173+
141174 timetableRepository .index ();
142175
143176 TimetableSnapshot timetableSnapshot = new TimetableSnapshot ();
144177 TripTimes tripTimes = ScheduledTripTimes .of ()
145178 .withTrip (TimetableRepositoryForTest .trip ("123" ).build ())
146179 .withDepartureTimes (new int [] { 0 , 1 })
180+ .withServiceCode (SERVICE_CODE )
147181 .build ();
148182 timetableSnapshot .update (new RealTimeTripUpdate (REAL_TIME_PATTERN , tripTimes , firstDate ));
149183 timetableSnapshot .update (new RealTimeTripUpdate (RAIL_PATTERN , canceledTripTimes , firstDate ));
@@ -273,4 +307,12 @@ void getRealtimeTripTimesForAddedTrip() {
273307 void getRealtimeTripTimesForAddedTripOnNoServiceDay () {
274308 assertEquals (Optional .empty (), service .getTripTimeOnDates (ADDED_TRIP , NO_SERVICE_DATE ));
275309 }
310+
311+ @ Test
312+ void hasTripsForStop () {
313+ assertTrue (service .hasScheduledServicesAfter (LocalDate .of (2025 , 7 , 1 ), STOP_ONE ));
314+ assertTrue (service .hasScheduledServicesAfter (LocalDate .of (2025 , 7 , 2 ), STOP_ONE ));
315+ assertFalse (service .hasScheduledServicesAfter (LocalDate .of (2025 , 7 , 3 ), STOP_ONE ));
316+ assertFalse (service .hasScheduledServicesAfter (LocalDate .of (2025 , 7 , 1 ), STOP_C ));
317+ }
276318}
0 commit comments