Skip to content

Commit

Permalink
test(CheckMonitoredTrip): Inline mockOtpPlanResponse and remove redun…
Browse files Browse the repository at this point in the history
…dant code.
  • Loading branch information
binh-dam-ibigroup committed Jun 27, 2024
1 parent 831de11 commit eced197
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ void canMonitorTrip() throws Exception {
false,
OtpTestUtils.createDefaultJourneyState()
);
monitoredTrip.updateAllDaysOfWeek(true);
monitoredTrip.tripName = "My Morning Commute";
monitoredTrip.itineraryExistence = new ItineraryExistence();
monitoredTrip.itineraryExistence.monday = new ItineraryExistence.ItineraryExistenceResult();
Persistence.monitoredTrips.create(monitoredTrip);
LOG.info("Created trip {}", monitoredTrip.id);
Expand Down Expand Up @@ -140,7 +137,6 @@ void canMonitorTrip() throws Exception {
CheckMonitoredTrip checkMonitoredTrip = new CheckMonitoredTrip(monitoredTrip, () -> mockResponse);
checkMonitoredTrip.run();
// Assert that there is one notification generated during check.
// TODO: Improve assertions to use snapshots.
Assertions.assertEquals(1, checkMonitoredTrip.notifications.size());
// Clear the created trip.
PersistenceTestUtils.deleteMonitoredTrip(monitoredTrip);
Expand Down Expand Up @@ -366,8 +362,9 @@ static List<ShouldSkipTripTestCase> createSkipTripTestCases() throws Exception {
@Test
void canMakeOTPRequestAndUpdateMatchingItineraryForPreviouslyUnmatchedItinerary() throws Exception {
// create an OTP mock to return
OtpResponse mockWeekdayResponse = OtpTestUtils.OTP_DISPATCHER_PLAN_RESPONSE.getResponse();
// create a mock monitored trip and CheckMonitorTrip instance
OtpResponse mockWeekdayResponse = mockOtpPlanResponse();
// create a mock monitored trip and CheckMonitorTrip instance.
// Note that the response below gets modified from the original mockOtpPlanResponse.
CheckMonitoredTrip mockCheckMonitoredTrip = createCheckMonitoredTrip(() -> mockWeekdayResponse);
MonitoredTrip mockTrip = mockCheckMonitoredTrip.trip;
Persistence.monitoredTrips.create(mockTrip);
Expand Down Expand Up @@ -430,8 +427,9 @@ void canMakeOTPRequestAndUpdateMatchingItineraryForPreviouslyUnmatchedItinerary(
@Test
void canMakeOTPRequestAndResolveUnmatchedItinerary() throws Exception {
// create an OTP mock to return
OtpResponse mockWeekdayResponse = OtpTestUtils.OTP_DISPATCHER_PLAN_RESPONSE.getResponse();
OtpResponse mockWeekdayResponse = mockOtpPlanResponse();
// create a mock monitored trip and CheckMonitorTrip instance
// Note that the response below gets modified from the original mockOtpPlanResponse.
CheckMonitoredTrip mockCheckMonitoredTrip = createCheckMonitoredTrip(() -> mockWeekdayResponse);
MonitoredTrip mockTrip = mockCheckMonitoredTrip.trip;
Persistence.monitoredTrips.create(mockTrip);
Expand Down Expand Up @@ -506,8 +504,9 @@ void canMakeOTPRequestAndResolveUnmatchedItinerary() throws Exception {
@Test
void canMakeOTPRequestAndResolveNoLongerPossibleTrip() throws Exception {
// create an OTP mock to return
OtpResponse mockWeekdayResponse = OtpTestUtils.OTP_DISPATCHER_PLAN_RESPONSE.getResponse();
OtpResponse mockWeekdayResponse = mockOtpPlanResponse();
// create a mock monitored trip and CheckMonitorTrip instance
// Note that the response below gets modified from the original mockOtpPlanResponse.
CheckMonitoredTrip mockCheckMonitoredTrip = createCheckMonitoredTrip(() -> mockWeekdayResponse);
MonitoredTrip mockTrip = mockCheckMonitoredTrip.trip;
Persistence.monitoredTrips.create(mockTrip);
Expand Down Expand Up @@ -626,10 +625,11 @@ void shouldReportRecurringTripInstanceInPastAsUpcoming() throws Exception {
setRecurringTodayAndTomorrow(trip);

// Build fake OTP response, using an existing one as template
OtpResponse otpResponse = OtpTestUtils.OTP_DISPATCHER_PLAN_RESPONSE.getResponse();
OtpResponse otpResponse = mockOtpPlanResponse();
Itinerary adjustedItinerary = trip.itinerary.clone();
otpResponse.plan.itineraries = List.of(adjustedItinerary);

// Note that the response below gets modified from the original mockOtpPlanResponse.
CheckMonitoredTrip check = new CheckMonitoredTrip(trip, () -> otpResponse);
check.shouldSkipMonitoredTripCheck(false);
check.checkOtpAndUpdateTripStatus();
Expand Down

0 comments on commit eced197

Please sign in to comment.