Skip to content

Commit

Permalink
add test coverage to expire_calendar notice
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez committed Jan 29, 2024
1 parent a412159 commit c0b4b95
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void validate(NoticeContainer noticeContainer) {
} else if (isCalendarTableEmpty && allCalendarAreExpired) {
// Taking the first of the calendar dates for the service id.
// This is the case of foreign key violation or calendar.txt not provided.
// In this case all serviceId need to be expired to report the notices.
Optional<GtfsCalendarDate> firstCalendarDate =
calendarDateTable.byServiceId(serviceId).stream()
.min(Comparator.comparingInt(GtfsCalendarDate::csvRowNumber));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.time.LocalDate;
import java.util.List;
import java.util.Set;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -218,8 +217,7 @@ public void calendarWithNoDaysShouldNotGenerateNotice() {
}

@Test
@Ignore
public void calendarDateWithForeignKeyViolationShouldGenerateNotice() {
public void calendarDateWithForeignKeyViolationShouldNotGenerateNotice() {
NoticeContainer container = new NoticeContainer();

List<GtfsCalendar> calendars =
Expand Down Expand Up @@ -257,7 +255,80 @@ public void calendarDateWithForeignKeyViolationShouldGenerateNotice() {
container);
new ExpiredCalendarValidator(new DateForValidation(TEST_NOW), calendarTable, calendarDateTable)
.validate(container);
assertThat(container.getValidationNotices()).isEmpty();
}

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

List<GtfsCalendar> calendars = ImmutableList.of();

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

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

List<GtfsCalendar> calendars = ImmutableList.of();

GtfsCalendarTableContainer calendarTable =
GtfsCalendarTableContainer.forEntities(calendars, container);
var calendarDateTable =
GtfsCalendarDateTableContainer.forEntities(
ImmutableList.of(
new GtfsCalendarDate.Builder()
.setCsvRowNumber(3)
.setServiceId("SERVICE_ID_3")
.setDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(2)))
.setExceptionType(GtfsCalendarDateExceptionType.SERVICE_ADDED)
.build(),
new GtfsCalendarDate.Builder()
.setCsvRowNumber(2)
.setServiceId("SERVICE_ID_2")
.setDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(3)))
.setExceptionType(GtfsCalendarDateExceptionType.SERVICE_ADDED)
.build(),
new GtfsCalendarDate.Builder()
.setCsvRowNumber(1)
.setServiceId("SERVICE_ID_1")
.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())
.containsExactly(new ExpiredCalendarValidator.ExpiredCalendarNotice(2, "NOT_SERVICE_ID"));
.containsExactly(
new ExpiredCalendarValidator.ExpiredCalendarNotice(3, "SERVICE_ID_3"),
new ExpiredCalendarValidator.ExpiredCalendarNotice(2, "SERVICE_ID_2"),
new ExpiredCalendarValidator.ExpiredCalendarNotice(1, "SERVICE_ID_1"));
}
}

0 comments on commit c0b4b95

Please sign in to comment.