Skip to content

Commit

Permalink
Merge 9c29f43 into c19527b
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez authored Jan 16, 2024
2 parents c19527b + 9c29f43 commit 07c25a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public void validate(NoticeContainer noticeContainer) {
CalendarUtil.buildServicePeriodMap(calendarTable, calendarDateTable));
for (var serviceId : servicePeriodMap.keySet()) {
SortedSet<LocalDate> serviceDates = servicePeriodMap.get(serviceId);
if (!serviceDates.isEmpty() && serviceDates.last().isBefore(dateForValidation.getDate())) {
if (!serviceDates.isEmpty()
&& serviceDates.last().isBefore(dateForValidation.getDate())
&& calendarTable.byServiceId(serviceId).isPresent()) {
int csvRowNumber = calendarTable.byServiceId(serviceId).get().csvRowNumber();
noticeContainer.addValidationNotice(new ExpiredCalendarNotice(csvRowNumber, serviceId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,34 @@ public void calendarWithNoDaysShouldNotGenerateNotice() {
.validate(container);
assertThat(container.getValidationNotices()).isEmpty();
}

@Test
public void calendarDateWithInvalidServiceIdShouldNotThrowExceptionAndShouldNotGenerateNotice() {
NoticeContainer container = new NoticeContainer();

List<GtfsCalendar> calendars =
ImmutableList.of(
new GtfsCalendar.Builder()
.setCsvRowNumber(2)
.setServiceId("SERVICE_ID")
.setStartDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(7)))
.setEndDate(GtfsDate.fromLocalDate(TEST_NOW))
.build());

GtfsCalendarTableContainer calendarTable =
GtfsCalendarTableContainer.forEntities(calendars, container);
var calendarDateTable =
GtfsCalendarDateTableContainer.forEntities(
ImmutableList.of(
new GtfsCalendarDate.Builder()
.setCsvRowNumber(2)
.setServiceId("NOT_SERVICE_ID")
.setDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(1)))
.setExceptionType(GtfsCalendarDateExceptionType.SERVICE_ADDED)
.build()),
container);
new ExpiredCalendarValidator(new DateForValidation(TEST_NOW), calendarTable, calendarDateTable)
.validate(container);
assertThat(container.getValidationNotices()).isEmpty();
}
}

0 comments on commit 07c25a7

Please sign in to comment.