From 6f9aec74d673fe6e65e3b9edf04c67ef923cee75 Mon Sep 17 00:00:00 2001 From: Brady Hunsaker Date: Fri, 12 Jan 2024 11:12:45 -0500 Subject: [PATCH] refactor: Replace CurrentDateTime with DateForValidation and use LocalDate (#1636) --- ...ntDateTime.java => DateForValidation.java} | 22 ++++---- .../gtfsvalidator/testing/LoadingHelper.java | 9 ++-- .../validator/ValidationContext.java | 10 ++-- .../mobilitydata/gtfsvalidator/TestUtils.java | 6 +-- ...meTest.java => DateForValidationTest.java} | 21 ++++---- .../testgtfs/GtfsTestEntityValidator.java | 12 ++--- .../testgtfs/GtfsTestSingleFileValidator.java | 12 ++--- .../testgtfs/WholeFeedValidator.java | 14 ++--- .../validator/ValidationContextTest.java | 23 ++++---- .../validator/ValidatorLoaderTest.java | 17 +++--- .../runner/ValidationRunner.java | 7 ++- .../validator/DateTripsValidator.java | 15 +++--- .../validator/ExpiredCalendarValidator.java | 11 ++-- .../FeedExpirationDateValidator.java | 18 +++---- .../report/model/FeedMetadataTest.java | 7 ++- .../validator/DateTripsValidatorTest.java | 33 ++++++------ .../ExpiredCalendarValidatorTest.java | 48 ++++++++--------- .../FeedExpirationDateValidatorTest.java | 54 ++++++++----------- 18 files changed, 159 insertions(+), 180 deletions(-) rename core/src/main/java/org/mobilitydata/gtfsvalidator/input/{CurrentDateTime.java => DateForValidation.java} (67%) rename core/src/test/java/org/mobilitydata/gtfsvalidator/input/{CurrentDateTimeTest.java => DateForValidationTest.java} (54%) diff --git a/core/src/main/java/org/mobilitydata/gtfsvalidator/input/CurrentDateTime.java b/core/src/main/java/org/mobilitydata/gtfsvalidator/input/DateForValidation.java similarity index 67% rename from core/src/main/java/org/mobilitydata/gtfsvalidator/input/CurrentDateTime.java rename to core/src/main/java/org/mobilitydata/gtfsvalidator/input/DateForValidation.java index 5d78f42e52..9737f38fe5 100644 --- a/core/src/main/java/org/mobilitydata/gtfsvalidator/input/CurrentDateTime.java +++ b/core/src/main/java/org/mobilitydata/gtfsvalidator/input/DateForValidation.java @@ -16,19 +16,19 @@ package org.mobilitydata.gtfsvalidator.input; -import java.time.ZonedDateTime; +import java.time.LocalDate; -/** Represents the current date and time */ -public class CurrentDateTime { +/** The date to be used for validation rules. */ +public class DateForValidation { - private final ZonedDateTime now; + private final LocalDate date; - public CurrentDateTime(ZonedDateTime now) { - this.now = now; + public DateForValidation(LocalDate date) { + this.date = date; } - public ZonedDateTime getNow() { - return now; + public LocalDate getDate() { + return date; } @Override @@ -36,14 +36,14 @@ public boolean equals(Object other) { if (this == other) { return true; } - if (other instanceof CurrentDateTime) { - return this.now.equals(((CurrentDateTime) other).now); + if (other instanceof DateForValidation) { + return this.date.equals(((DateForValidation) other).date); } return false; } @Override public int hashCode() { - return now.hashCode(); + return date.hashCode(); } } diff --git a/core/src/main/java/org/mobilitydata/gtfsvalidator/testing/LoadingHelper.java b/core/src/main/java/org/mobilitydata/gtfsvalidator/testing/LoadingHelper.java index 613e808f07..b51f788eb6 100644 --- a/core/src/main/java/org/mobilitydata/gtfsvalidator/testing/LoadingHelper.java +++ b/core/src/main/java/org/mobilitydata/gtfsvalidator/testing/LoadingHelper.java @@ -18,13 +18,12 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; +import java.time.LocalDate; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; import org.mobilitydata.gtfsvalidator.table.AnyTableLoader; @@ -41,7 +40,7 @@ public class LoadingHelper { private CountryCode countryCode = CountryCode.forStringOrUnknown("ca"); - private ZonedDateTime currentTime = ZonedDateTime.of(2021, 1, 1, 14, 30, 0, 0, ZoneOffset.UTC); + private LocalDate dateForValidation = LocalDate.of(2021, 1, 1); private NoticeContainer noticeContainer = new NoticeContainer(); @@ -68,7 +67,7 @@ public > Y load( ValidationContext context = ValidationContext.builder() .setCountryCode(countryCode) - .setCurrentDateTime(new CurrentDateTime(currentTime)) + .setDateForValidation(new DateForValidation(dateForValidation)) .build(); ValidatorProvider provider = new DefaultValidatorProvider(context, validatorLoader); return (Y) AnyTableLoader.load(tableDescriptor, provider, in, noticeContainer); diff --git a/core/src/main/java/org/mobilitydata/gtfsvalidator/validator/ValidationContext.java b/core/src/main/java/org/mobilitydata/gtfsvalidator/validator/ValidationContext.java index c39e91c2cf..539e18a478 100644 --- a/core/src/main/java/org/mobilitydata/gtfsvalidator/validator/ValidationContext.java +++ b/core/src/main/java/org/mobilitydata/gtfsvalidator/validator/ValidationContext.java @@ -18,7 +18,7 @@ import com.google.common.collect.ImmutableMap; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; /** * A read-only context passed to particular validator objects. It gives information relevant for @@ -57,8 +57,8 @@ public CountryCode countryCode() { * * @return The time when validation started as @code{ZonedDateTime} */ - public CurrentDateTime currentDateTime() { - return get(CurrentDateTime.class); + public DateForValidation dateForValidation() { + return get(DateForValidation.class); } /** Returns a member of the context with requested class. */ @@ -82,8 +82,8 @@ public Builder setCountryCode(CountryCode countryCode) { } /** Sets the current time. */ - public Builder setCurrentDateTime(CurrentDateTime currentDateTime) { - return set(CurrentDateTime.class, currentDateTime); + public Builder setDateForValidation(DateForValidation dateForValidation) { + return set(DateForValidation.class, dateForValidation); } /** Sets a member of the context with requested class. */ diff --git a/core/src/test/java/org/mobilitydata/gtfsvalidator/TestUtils.java b/core/src/test/java/org/mobilitydata/gtfsvalidator/TestUtils.java index 8bb3e7b16c..28f63f7389 100644 --- a/core/src/test/java/org/mobilitydata/gtfsvalidator/TestUtils.java +++ b/core/src/test/java/org/mobilitydata/gtfsvalidator/TestUtils.java @@ -5,10 +5,10 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.time.ZonedDateTime; +import java.time.LocalDate; import java.util.List; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; import org.mobilitydata.gtfsvalidator.validator.ValidationContext; @@ -32,7 +32,7 @@ public static InputStream toInputStream(String s) { public static ValidationContext contextForTest() { return ValidationContext.builder() .setCountryCode(CountryCode.forStringOrUnknown("ca")) - .setCurrentDateTime(new CurrentDateTime(ZonedDateTime.now())) + .setDateForValidation(new DateForValidation(LocalDate.now())) .build(); } } diff --git a/core/src/test/java/org/mobilitydata/gtfsvalidator/input/CurrentDateTimeTest.java b/core/src/test/java/org/mobilitydata/gtfsvalidator/input/DateForValidationTest.java similarity index 54% rename from core/src/test/java/org/mobilitydata/gtfsvalidator/input/CurrentDateTimeTest.java rename to core/src/test/java/org/mobilitydata/gtfsvalidator/input/DateForValidationTest.java index c9cf4e09bc..0c5bdb8aa4 100644 --- a/core/src/test/java/org/mobilitydata/gtfsvalidator/input/CurrentDateTimeTest.java +++ b/core/src/test/java/org/mobilitydata/gtfsvalidator/input/DateForValidationTest.java @@ -18,26 +18,23 @@ import static com.google.common.truth.Truth.assertThat; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; +import java.time.LocalDate; import org.junit.Test; -public class CurrentDateTimeTest { - private static final ZonedDateTime TEST_NOW = - ZonedDateTime.of(2021, 1, 1, 14, 30, 0, 0, ZoneOffset.UTC); - private static final ZonedDateTime OTHER_DATE_TIME = - ZonedDateTime.of(2021, 4, 1, 14, 30, 0, 0, ZoneOffset.UTC); +public class DateForValidationTest { + private static final LocalDate TEST_NOW = LocalDate.of(2021, 1, 1); + private static final LocalDate OTHER_DATE_TIME = LocalDate.of(2021, 4, 1); @Test - public void getNow() { - CurrentDateTime currentDateTime = new CurrentDateTime(TEST_NOW); - assertThat(currentDateTime.getNow()).isEqualTo(TEST_NOW); + public void getDate() { + DateForValidation dateForValidation = new DateForValidation(TEST_NOW); + assertThat(dateForValidation.getDate()).isEqualTo(TEST_NOW); } @Test public void testEquals() { - assertThat(new CurrentDateTime(TEST_NOW).equals(new CurrentDateTime(TEST_NOW))).isTrue(); - assertThat(new CurrentDateTime(TEST_NOW).equals(new CurrentDateTime(OTHER_DATE_TIME))) + assertThat(new DateForValidation(TEST_NOW).equals(new DateForValidation(TEST_NOW))).isTrue(); + assertThat(new DateForValidation(TEST_NOW).equals(new DateForValidation(OTHER_DATE_TIME))) .isFalse(); } } diff --git a/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestEntityValidator.java b/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestEntityValidator.java index 03b234ace9..88a3c90744 100644 --- a/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestEntityValidator.java +++ b/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestEntityValidator.java @@ -18,18 +18,18 @@ import javax.inject.Inject; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.validator.SingleEntityValidator; public class GtfsTestEntityValidator extends SingleEntityValidator { private final CountryCode countryCode; - private final CurrentDateTime currentDateTime; + private final DateForValidation dateForValidation; @Inject - public GtfsTestEntityValidator(CountryCode countryCode, CurrentDateTime currentDateTime) { + public GtfsTestEntityValidator(CountryCode countryCode, DateForValidation dateForValidation) { this.countryCode = countryCode; - this.currentDateTime = currentDateTime; + this.dateForValidation = dateForValidation; } @Override @@ -39,7 +39,7 @@ public CountryCode getCountryCode() { return countryCode; } - public CurrentDateTime getCurrentDateTime() { - return currentDateTime; + public DateForValidation getDateForValidation() { + return dateForValidation; } } diff --git a/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestSingleFileValidator.java b/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestSingleFileValidator.java index 9b9608f12b..cd3bf2052a 100644 --- a/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestSingleFileValidator.java +++ b/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestSingleFileValidator.java @@ -18,7 +18,7 @@ import javax.inject.Inject; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.validator.FileValidator; @@ -26,14 +26,14 @@ public class GtfsTestSingleFileValidator extends FileValidator { private final GtfsTestTableContainer table; private final CountryCode countryCode; - private final CurrentDateTime currentDateTime; + private final DateForValidation dateForValidation; @Inject public GtfsTestSingleFileValidator( - GtfsTestTableContainer table, CountryCode countryCode, CurrentDateTime currentDateTime) { + GtfsTestTableContainer table, CountryCode countryCode, DateForValidation dateForValidation) { this.table = table; this.countryCode = countryCode; - this.currentDateTime = currentDateTime; + this.dateForValidation = dateForValidation; } @Override @@ -47,7 +47,7 @@ public CountryCode getCountryCode() { return countryCode; } - public CurrentDateTime getCurrentDateTime() { - return currentDateTime; + public DateForValidation getDateForValidation() { + return dateForValidation; } } diff --git a/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/WholeFeedValidator.java b/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/WholeFeedValidator.java index f12c69abd0..4844bbbd67 100644 --- a/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/WholeFeedValidator.java +++ b/core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/WholeFeedValidator.java @@ -18,7 +18,7 @@ import javax.inject.Inject; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.table.GtfsFeedContainer; import org.mobilitydata.gtfsvalidator.validator.FileValidator; @@ -27,14 +27,16 @@ public class WholeFeedValidator extends FileValidator { private final GtfsFeedContainer feedContainer; private final CountryCode countryCode; - private final CurrentDateTime currentDateTime; + private final DateForValidation dateForValidation; @Inject public WholeFeedValidator( - GtfsFeedContainer feedContainer, CountryCode countryCode, CurrentDateTime currentDateTime) { + GtfsFeedContainer feedContainer, + CountryCode countryCode, + DateForValidation dateForValidation) { this.feedContainer = feedContainer; this.countryCode = countryCode; - this.currentDateTime = currentDateTime; + this.dateForValidation = dateForValidation; } @Override @@ -48,7 +50,7 @@ public CountryCode getCountryCode() { return countryCode; } - public CurrentDateTime getCurrentDateTime() { - return currentDateTime; + public DateForValidation getDateForValidation() { + return dateForValidation; } } diff --git a/core/src/test/java/org/mobilitydata/gtfsvalidator/validator/ValidationContextTest.java b/core/src/test/java/org/mobilitydata/gtfsvalidator/validator/ValidationContextTest.java index 3270fb70f2..cc836322f1 100644 --- a/core/src/test/java/org/mobilitydata/gtfsvalidator/validator/ValidationContextTest.java +++ b/core/src/test/java/org/mobilitydata/gtfsvalidator/validator/ValidationContextTest.java @@ -19,23 +19,22 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; +import java.time.LocalDate; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; @RunWith(JUnit4.class) public final class ValidationContextTest { private static final CountryCode COUNTRY_CODE = CountryCode.forStringOrUnknown("AU"); - private static final CurrentDateTime CURRENT_DATE_TIME = - new CurrentDateTime(ZonedDateTime.of(2021, 1, 1, 14, 30, 0, 0, ZoneOffset.UTC)); + private static final DateForValidation CURRENT_DATE = + new DateForValidation(LocalDate.of(2021, 1, 1)); private static final ValidationContext VALIDATION_CONTEXT = ValidationContext.builder() .setCountryCode(COUNTRY_CODE) - .setCurrentDateTime(CURRENT_DATE_TIME) + .setDateForValidation(CURRENT_DATE) .build(); @Test @@ -44,14 +43,14 @@ public void get_countryCode_successful() { } @Test - public void get_currentDateTime_successful() { - assertThat(VALIDATION_CONTEXT.get(CurrentDateTime.class)).isEqualTo(CURRENT_DATE_TIME); + public void get_dateForValidation_successful() { + assertThat(VALIDATION_CONTEXT.get(DateForValidation.class)).isEqualTo(CURRENT_DATE); } @Test public void get_unsupported_throws() { assertThrows( - IllegalArgumentException.class, () -> VALIDATION_CONTEXT.get(ChildCurrentDateTime.class)); + IllegalArgumentException.class, () -> VALIDATION_CONTEXT.get(ChildDateForValidation.class)); } @Test @@ -64,10 +63,10 @@ public void get_extraIntegerObject_successful() { .isEqualTo(10); } - private static class ChildCurrentDateTime extends CurrentDateTime { + private static class ChildDateForValidation extends DateForValidation { - public ChildCurrentDateTime(ZonedDateTime now) { - super(now); + public ChildDateForValidation(LocalDate date) { + super(date); } } } diff --git a/core/src/test/java/org/mobilitydata/gtfsvalidator/validator/ValidatorLoaderTest.java b/core/src/test/java/org/mobilitydata/gtfsvalidator/validator/ValidatorLoaderTest.java index 55edfd49af..c169d29ac3 100644 --- a/core/src/test/java/org/mobilitydata/gtfsvalidator/validator/ValidatorLoaderTest.java +++ b/core/src/test/java/org/mobilitydata/gtfsvalidator/validator/ValidatorLoaderTest.java @@ -19,11 +19,10 @@ import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; +import java.time.LocalDate; import org.junit.Test; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.table.GtfsFeedContainer; import org.mobilitydata.gtfsvalidator.table.GtfsTableContainer.TableStatus; import org.mobilitydata.gtfsvalidator.testgtfs.GtfsTestEntityValidator; @@ -34,12 +33,12 @@ public class ValidatorLoaderTest { private static final CountryCode COUNTRY_CODE = CountryCode.forStringOrUnknown("AU"); - private static final CurrentDateTime CURRENT_DATE_TIME = - new CurrentDateTime(ZonedDateTime.of(2021, 1, 1, 14, 30, 0, 0, ZoneOffset.UTC)); + private static final DateForValidation CURRENT_DATE = + new DateForValidation(LocalDate.of(2021, 1, 1)); private static final ValidationContext VALIDATION_CONTEXT = ValidationContext.builder() .setCountryCode(COUNTRY_CODE) - .setCurrentDateTime(CURRENT_DATE_TIME) + .setDateForValidation(CURRENT_DATE) .build(); @Test @@ -51,7 +50,7 @@ public void createValidatorWithContext_injectsContext() .validator(); assertThat(validator.getCountryCode()).isEqualTo(VALIDATION_CONTEXT.countryCode()); - assertThat(validator.getCurrentDateTime()).isEqualTo(VALIDATION_CONTEXT.currentDateTime()); + assertThat(validator.getDateForValidation()).isEqualTo(VALIDATION_CONTEXT.dateForValidation()); } @Test @@ -65,7 +64,7 @@ public void createSingleFileValidator_injectsTableContainerAndContext() .validator(); assertThat(validator.getCountryCode()).isEqualTo(VALIDATION_CONTEXT.countryCode()); - assertThat(validator.getCurrentDateTime()).isEqualTo(VALIDATION_CONTEXT.currentDateTime()); + assertThat(validator.getDateForValidation()).isEqualTo(VALIDATION_CONTEXT.dateForValidation()); assertThat(validator.getStopTable()).isEqualTo(table); } @@ -83,7 +82,7 @@ public void createMultiFileValidator_injectsFeedContainerAndContext() WholeFeedValidator validator = validatorWithStatus.validator(); assertThat(validator.getCountryCode()).isEqualTo(VALIDATION_CONTEXT.countryCode()); - assertThat(validator.getCurrentDateTime()).isEqualTo(VALIDATION_CONTEXT.currentDateTime()); + assertThat(validator.getDateForValidation()).isEqualTo(VALIDATION_CONTEXT.dateForValidation()); assertThat(validator.getFeedContainer()).isEqualTo(feedContainer); } diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunner.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunner.java index 0bb04fb5a6..ad5fae0960 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunner.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunner.java @@ -27,12 +27,11 @@ import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.time.Duration; -import java.time.ZoneId; -import java.time.ZonedDateTime; +import java.time.LocalDate; import java.util.Date; import java.util.List; import java.util.stream.Collectors; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.input.GtfsInput; import org.mobilitydata.gtfsvalidator.notice.IOError; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; @@ -121,7 +120,7 @@ public Status run(ValidationRunnerConfig config) { ValidationContext validationContext = ValidationContext.builder() .setCountryCode(config.countryCode()) - .setCurrentDateTime(new CurrentDateTime(ZonedDateTime.now(ZoneId.systemDefault()))) + .setDateForValidation(new DateForValidation(LocalDate.now())) .build(); try { feedContainer = diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidator.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidator.java index 9f7a871062..81cc22dcf8 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidator.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidator.java @@ -25,7 +25,7 @@ import javax.inject.Inject; import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice; import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; import org.mobilitydata.gtfsvalidator.table.*; @@ -55,16 +55,16 @@ public class DateTripsValidator extends FileValidator { private final GtfsFrequencyTableContainer frequencyTable; - private final CurrentDateTime currentDateTime; + private final DateForValidation dateForValidation; @Inject DateTripsValidator( - CurrentDateTime currentDateTime, + DateForValidation dateForValidation, GtfsCalendarDateTableContainer calendarDateTable, GtfsCalendarTableContainer calendarTable, GtfsTripTableContainer tripContainer, GtfsFrequencyTableContainer frequencyTable) { - this.currentDateTime = currentDateTime; + this.dateForValidation = dateForValidation; this.calendarTable = calendarTable; this.calendarDateTable = calendarDateTable; this.tripContainer = tripContainer; @@ -73,7 +73,6 @@ public class DateTripsValidator extends FileValidator { @Override public void validate(NoticeContainer noticeContainer) { - LocalDate now = currentDateTime.getNow().toLocalDate(); final Map> servicePeriodMap = CalendarUtil.servicePeriodToServiceDatesMap( CalendarUtil.buildServicePeriodMap(calendarTable, calendarDateTable)); @@ -82,15 +81,15 @@ public void validate(NoticeContainer noticeContainer) { servicePeriodMap, tripContainer, frequencyTable); Optional majorityServiceDates = TripCalendarUtil.computeMajorityServiceCoverage(tripCounts); - LocalDate currentDatePlusSevenDays = now.plusDays(7); + LocalDate currentDatePlusSevenDays = dateForValidation.getDate().plusDays(7); if (!majorityServiceDates.isEmpty()) { LocalDate serviceWindowStartDate = majorityServiceDates.get().startDate(); LocalDate serviceWindowEndDate = majorityServiceDates.get().endDate(); - if (serviceWindowStartDate.isAfter(now) + if (serviceWindowStartDate.isAfter(dateForValidation.getDate()) || serviceWindowEndDate.isBefore(currentDatePlusSevenDays)) { noticeContainer.addValidationNotice( new TripCoverageNotActiveForNext7DaysNotice( - GtfsDate.fromLocalDate(now), + GtfsDate.fromLocalDate(dateForValidation.getDate()), GtfsDate.fromLocalDate(serviceWindowStartDate), GtfsDate.fromLocalDate(serviceWindowEndDate))); } diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/ExpiredCalendarValidator.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/ExpiredCalendarValidator.java index 8dc0eecdab..d25e1550b7 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/ExpiredCalendarValidator.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/ExpiredCalendarValidator.java @@ -24,7 +24,7 @@ import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice; import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.UrlRef; import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; import org.mobilitydata.gtfsvalidator.table.*; @@ -37,27 +37,26 @@ public class ExpiredCalendarValidator extends FileValidator { private final GtfsCalendarDateTableContainer calendarDateTable; - private final CurrentDateTime currentDateTime; + private final DateForValidation dateForValidation; @Inject ExpiredCalendarValidator( - CurrentDateTime currentDateTime, + DateForValidation dateForValidation, GtfsCalendarTableContainer calendarTable, GtfsCalendarDateTableContainer calendarDateTable) { - this.currentDateTime = currentDateTime; + this.dateForValidation = dateForValidation; this.calendarTable = calendarTable; this.calendarDateTable = calendarDateTable; } @Override public void validate(NoticeContainer noticeContainer) { - LocalDate now = currentDateTime.getNow().toLocalDate(); final Map> servicePeriodMap = CalendarUtil.servicePeriodToServiceDatesMap( CalendarUtil.buildServicePeriodMap(calendarTable, calendarDateTable)); for (var serviceId : servicePeriodMap.keySet()) { SortedSet serviceDates = servicePeriodMap.get(serviceId); - if (!serviceDates.isEmpty() && serviceDates.last().isBefore(now)) { + if (!serviceDates.isEmpty() && serviceDates.last().isBefore(dateForValidation.getDate())) { int csvRowNumber = calendarTable.byServiceId(serviceId).get().csvRowNumber(); noticeContainer.addValidationNotice(new ExpiredCalendarNotice(csvRowNumber, serviceId)); } diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidator.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidator.java index b174f6b3c1..dea9ae4766 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidator.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidator.java @@ -18,13 +18,12 @@ import static org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.SectionRef.BEST_PRACTICES_DATASET_PUBLISHING; import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.WARNING; -import java.time.LocalDate; import javax.inject.Inject; import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice; import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.FileRefs; import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.SectionRefs; import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfo; @@ -46,20 +45,21 @@ @GtfsValidator public class FeedExpirationDateValidator extends SingleEntityValidator { - private final CurrentDateTime currentDateTime; + private final DateForValidation dateForValidation; @Inject - FeedExpirationDateValidator(CurrentDateTime currentDateTime) { - this.currentDateTime = currentDateTime; + FeedExpirationDateValidator(DateForValidation dateForValidation) { + this.dateForValidation = dateForValidation; } @Override public void validate(GtfsFeedInfo entity, NoticeContainer noticeContainer) { if (entity.hasFeedEndDate()) { - LocalDate now = currentDateTime.getNow().toLocalDate(); - GtfsDate currentDate = GtfsDate.fromLocalDate(now); - GtfsDate currentDatePlusSevenDays = GtfsDate.fromLocalDate(now.plusDays(7)); - GtfsDate currentDatePlusThirtyDays = GtfsDate.fromLocalDate(now.plusDays(30)); + GtfsDate currentDate = GtfsDate.fromLocalDate(dateForValidation.getDate()); + GtfsDate currentDatePlusSevenDays = + GtfsDate.fromLocalDate(dateForValidation.getDate().plusDays(7)); + GtfsDate currentDatePlusThirtyDays = + GtfsDate.fromLocalDate(dateForValidation.getDate().plusDays(30)); if (entity.feedEndDate().compareTo(currentDatePlusSevenDays) <= 0) { noticeContainer.addValidationNotice( new FeedExpirationDate7DaysNotice( diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java index 9965841136..553e48a9a1 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java @@ -7,14 +7,13 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.time.ZoneId; -import java.time.ZonedDateTime; +import java.time.LocalDate; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.mobilitydata.gtfsvalidator.input.CountryCode; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.input.GtfsInput; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.table.*; @@ -27,7 +26,7 @@ public class FeedMetadataTest { ValidationContext validationContext = ValidationContext.builder() .setCountryCode(CountryCode.forStringOrUnknown("CA")) - .setCurrentDateTime(new CurrentDateTime(ZonedDateTime.now(ZoneId.systemDefault()))) + .setDateForValidation(new DateForValidation(LocalDate.now())) .build(); ValidatorLoader validatorLoader; File rootDir; diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidatorTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidatorTest.java index bbea78238c..1a8e367351 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidatorTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidatorTest.java @@ -7,14 +7,12 @@ import com.google.common.collect.ImmutableSet; import java.time.DayOfWeek; import java.time.LocalDate; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; import org.mobilitydata.gtfsvalidator.table.*; @@ -24,20 +22,19 @@ @RunWith(JUnit4.class) public class DateTripsValidatorTest { - private static final ZonedDateTime TEST_NOW = - ZonedDateTime.of(2022, 12, 1, 8, 30, 0, 0, ZoneOffset.UTC); + private static final LocalDate TEST_NOW = LocalDate.of(2022, 12, 1); @Test public void serviceWindowEndingBefore7DaysFromNowShouldGenerateNotice() { - var serviceWindowStart = TEST_NOW.toLocalDate(); - var serviceWindowEnd = TEST_NOW.toLocalDate().plusDays(6); + var serviceWindowStart = TEST_NOW; + var serviceWindowEnd = TEST_NOW.plusDays(6); var notices = validateSimpleServiceWindow(serviceWindowStart, serviceWindowEnd); assertThat(notices) .containsExactly( new TripCoverageNotActiveForNext7DaysNotice( - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate()), + GtfsDate.fromLocalDate(TEST_NOW), GtfsDate.fromLocalDate(serviceWindowStart), GtfsDate.fromLocalDate(serviceWindowEnd))); } @@ -45,13 +42,13 @@ public void serviceWindowEndingBefore7DaysFromNowShouldGenerateNotice() { @Test public void serviceWindowStartingAfterNowShouldGenerateNotice() { - var serviceWindowStart = TEST_NOW.toLocalDate().plusDays(1); - var serviceWindowEnd = TEST_NOW.toLocalDate().plusDays(7); + var serviceWindowStart = TEST_NOW.plusDays(1); + var serviceWindowEnd = TEST_NOW.plusDays(7); var notices = validateSimpleServiceWindow(serviceWindowStart, serviceWindowEnd); assertThat(notices) .containsExactly( new TripCoverageNotActiveForNext7DaysNotice( - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate()), + GtfsDate.fromLocalDate(TEST_NOW), GtfsDate.fromLocalDate(serviceWindowStart), GtfsDate.fromLocalDate(serviceWindowEnd))); } @@ -59,8 +56,8 @@ public void serviceWindowStartingAfterNowShouldGenerateNotice() { @Test public void serviceWindowStartingNowAndEndingIn7DaysShouldNotGenerateNotice() { - var serviceWindowStart = TEST_NOW.toLocalDate(); - var serviceWindowEnd = TEST_NOW.toLocalDate().plusDays(7); + var serviceWindowStart = TEST_NOW; + var serviceWindowEnd = TEST_NOW.plusDays(7); var notices = validateSimpleServiceWindow(serviceWindowStart, serviceWindowEnd); assertThat(notices).isEmpty(); } @@ -68,8 +65,8 @@ public void serviceWindowStartingNowAndEndingIn7DaysShouldNotGenerateNotice() { @Test public void serviceWindowStartingBeforeNowAndEndingAfter7DaysShouldNotGenerateNotice() { - var serviceWindowStart = TEST_NOW.toLocalDate().minusDays(1); - var serviceWindowEnd = TEST_NOW.toLocalDate().plusDays(8); + var serviceWindowStart = TEST_NOW.minusDays(1); + var serviceWindowEnd = TEST_NOW.plusDays(8); var notices = validateSimpleServiceWindow(serviceWindowStart, serviceWindowEnd); assertThat(notices).isEmpty(); } @@ -94,7 +91,11 @@ private List validateSimpleServiceWindow( var validator = new DateTripsValidator( - new CurrentDateTime(TEST_NOW), dateTable, calendarTable, tripContainer, frequencyTable); + new DateForValidation(TEST_NOW), + dateTable, + calendarTable, + tripContainer, + frequencyTable); validator.validate(noticeContainer); diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/ExpiredCalendarValidatorTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/ExpiredCalendarValidatorTest.java index 31c2bc13c0..0af95fc8c8 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/ExpiredCalendarValidatorTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/ExpiredCalendarValidatorTest.java @@ -21,14 +21,13 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.time.DayOfWeek; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; +import java.time.LocalDate; import java.util.List; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.table.*; import org.mobilitydata.gtfsvalidator.table.GtfsTableContainer.TableStatus; @@ -44,8 +43,7 @@ public class ExpiredCalendarValidatorTest { DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY); - private static final ZonedDateTime TEST_NOW = - ZonedDateTime.of(2021, 1, 1, 14, 30, 0, 0, ZoneOffset.UTC); + private static final LocalDate TEST_NOW = LocalDate.of(2021, 1, 1); @Test public void calendarEndDateOneDayAgoShouldGenerateNotice() { @@ -56,8 +54,8 @@ public void calendarEndDateOneDayAgoShouldGenerateNotice() { new GtfsCalendar.Builder() .setCsvRowNumber(2) .setServiceId("WEEK") - .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().minusDays(7))) - .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().minusDays(1))) + .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(7))) + .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(1))) .setMonday(1) .setTuesday(1) .setWednesday(1) @@ -68,7 +66,7 @@ public void calendarEndDateOneDayAgoShouldGenerateNotice() { GtfsCalendarTableContainer.forEntities(calendars, container); var dateTable = GtfsCalendarDateTableContainer.forStatus(TableStatus.EMPTY_FILE); - new ExpiredCalendarValidator(new CurrentDateTime(TEST_NOW), calendarTable, dateTable) + new ExpiredCalendarValidator(new DateForValidation(TEST_NOW), calendarTable, dateTable) .validate(container); assertThat(container.getValidationNotices()) .containsExactly(new ExpiredCalendarValidator.ExpiredCalendarNotice(2, "WEEK")); @@ -83,8 +81,8 @@ public void calendarEndDateTodayShouldNotGenerateNotice() { new GtfsCalendar.Builder() .setCsvRowNumber(2) .setServiceId("WEEK") - .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().minusDays(7))) - .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate())) + .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(7))) + .setEndDate(GtfsDate.fromLocalDate(TEST_NOW)) .setMonday(1) .setTuesday(1) .setWednesday(1) @@ -95,7 +93,7 @@ public void calendarEndDateTodayShouldNotGenerateNotice() { GtfsCalendarTableContainer.forEntities(calendars, container); var dateTable = GtfsCalendarDateTableContainer.forStatus(TableStatus.EMPTY_FILE); - new ExpiredCalendarValidator(new CurrentDateTime(TEST_NOW), calendarTable, dateTable) + new ExpiredCalendarValidator(new DateForValidation(TEST_NOW), calendarTable, dateTable) .validate(container); assertThat(container.getValidationNotices()).isEmpty(); } @@ -109,8 +107,8 @@ public void calendarEndDateOneDayFromNowShouldNotGenerateNotice() { new GtfsCalendar.Builder() .setCsvRowNumber(2) .setServiceId("WEEK") - .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().minusDays(7))) - .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(1))) + .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(7))) + .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.plusDays(1))) .setMonday(1) .setTuesday(1) .setWednesday(1) @@ -121,7 +119,7 @@ public void calendarEndDateOneDayFromNowShouldNotGenerateNotice() { GtfsCalendarTableContainer.forEntities(calendars, container); var dateTable = GtfsCalendarDateTableContainer.forStatus(TableStatus.EMPTY_FILE); - new ExpiredCalendarValidator(new CurrentDateTime(TEST_NOW), calendarTable, dateTable) + new ExpiredCalendarValidator(new DateForValidation(TEST_NOW), calendarTable, dateTable) .validate(container); assertThat(container.getValidationNotices()).isEmpty(); } @@ -135,8 +133,8 @@ public void calendarEndDateOneDayAgoButExtendedByAddedCalendarDateTableShouldNot new GtfsCalendar.Builder() .setCsvRowNumber(2) .setServiceId("WEEK") - .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().minusDays(7))) - .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().minusDays(1))) + .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(7))) + .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(1))) .setMonday(1) .setTuesday(1) .setWednesday(1) @@ -152,11 +150,11 @@ public void calendarEndDateOneDayAgoButExtendedByAddedCalendarDateTableShouldNot new GtfsCalendarDate.Builder() .setCsvRowNumber(2) .setServiceId("WEEK") - .setDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate())) + .setDate(GtfsDate.fromLocalDate(TEST_NOW)) .setExceptionType(GtfsCalendarDateExceptionType.SERVICE_ADDED) .build()), container); - new ExpiredCalendarValidator(new CurrentDateTime(TEST_NOW), calendarTable, dateTable) + new ExpiredCalendarValidator(new DateForValidation(TEST_NOW), calendarTable, dateTable) .validate(container); assertThat(container.getValidationNotices()).isEmpty(); } @@ -170,8 +168,8 @@ public void calendarEndDateTodayButShortenedByRemovedCalendarDateShouldGenerateN new GtfsCalendar.Builder() .setCsvRowNumber(2) .setServiceId("WEEK") - .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().minusDays(7))) - .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate())) + .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(7))) + .setEndDate(GtfsDate.fromLocalDate(TEST_NOW)) .setMonday(1) .setTuesday(1) .setWednesday(1) @@ -187,11 +185,11 @@ public void calendarEndDateTodayButShortenedByRemovedCalendarDateShouldGenerateN new GtfsCalendarDate.Builder() .setCsvRowNumber(2) .setServiceId("WEEK") - .setDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate())) + .setDate(GtfsDate.fromLocalDate(TEST_NOW)) .setExceptionType(GtfsCalendarDateExceptionType.SERVICE_REMOVED) .build()), container); - new ExpiredCalendarValidator(new CurrentDateTime(TEST_NOW), calendarTable, dateTable) + new ExpiredCalendarValidator(new DateForValidation(TEST_NOW), calendarTable, dateTable) .validate(container); assertThat(container.getValidationNotices()) .containsExactly(new ExpiredCalendarValidator.ExpiredCalendarNotice(2, "WEEK")); @@ -206,14 +204,14 @@ public void calendarWithNoDaysShouldNotGenerateNotice() { new GtfsCalendar.Builder() .setCsvRowNumber(2) .setServiceId("WEEK") - .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().minusDays(7))) - .setEndDate(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate())) + .setStartDate(GtfsDate.fromLocalDate(TEST_NOW.minusDays(7))) + .setEndDate(GtfsDate.fromLocalDate(TEST_NOW)) .build()); GtfsCalendarTableContainer calendarTable = GtfsCalendarTableContainer.forEntities(calendars, container); var dateTable = GtfsCalendarDateTableContainer.forStatus(TableStatus.EMPTY_FILE); - new ExpiredCalendarValidator(new CurrentDateTime(TEST_NOW), calendarTable, dateTable) + new ExpiredCalendarValidator(new DateForValidation(TEST_NOW), calendarTable, dateTable) .validate(container); assertThat(container.getValidationNotices()).isEmpty(); } diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidatorTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidatorTest.java index 849aae2b6f..8eaee1f1a4 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidatorTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidatorTest.java @@ -18,12 +18,11 @@ import static com.google.common.truth.Truth.assertThat; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; +import java.time.LocalDate; import java.util.List; import java.util.Locale; import org.junit.Test; -import org.mobilitydata.gtfsvalidator.input.CurrentDateTime; +import org.mobilitydata.gtfsvalidator.input.DateForValidation; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfo; @@ -32,12 +31,11 @@ import org.mobilitydata.gtfsvalidator.validator.FeedExpirationDateValidator.FeedExpirationDate7DaysNotice; public class FeedExpirationDateValidatorTest { - private static final ZonedDateTime TEST_NOW = - ZonedDateTime.of(2021, 1, 1, 14, 30, 0, 0, ZoneOffset.UTC); + private static final LocalDate TEST_NOW = LocalDate.of(2021, 1, 1); private List validateFeedInfo(GtfsFeedInfo feedInfo) { NoticeContainer container = new NoticeContainer(); - new FeedExpirationDateValidator(new CurrentDateTime(TEST_NOW)).validate(feedInfo, container); + new FeedExpirationDateValidator(new DateForValidation(TEST_NOW)).validate(feedInfo, container); return container.getValidationNotices(); } @@ -53,61 +51,51 @@ private GtfsFeedInfo createFeedInfo(GtfsDate feedEndDate) { @Test public void feedExpiringInFiveDaysFromNowShouldGenerateNotice() { - assertThat( - validateFeedInfo( - createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(3))))) + assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(3))))) .containsExactly( new FeedExpirationDate7DaysNotice( 1, - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate()), - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(3)), - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(7)))); + GtfsDate.fromLocalDate(TEST_NOW), + GtfsDate.fromLocalDate(TEST_NOW.plusDays(3)), + GtfsDate.fromLocalDate(TEST_NOW.plusDays(7)))); } @Test public void feedExpiringInSevenDaysFromNowShouldGenerateNotice() { - assertThat( - validateFeedInfo( - createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(7))))) + assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(7))))) .containsExactly( new FeedExpirationDate7DaysNotice( 1, - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate()), - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(7)), - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(7)))); + GtfsDate.fromLocalDate(TEST_NOW), + GtfsDate.fromLocalDate(TEST_NOW.plusDays(7)), + GtfsDate.fromLocalDate(TEST_NOW.plusDays(7)))); } @Test public void feedExpiring7to30DaysFromNowShouldGenerateNotice() { - assertThat( - validateFeedInfo( - createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(23))))) + assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(23))))) .containsExactly( new FeedExpirationDate30DaysNotice( 1, - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate()), - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(23)), - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(30)))); + GtfsDate.fromLocalDate(TEST_NOW), + GtfsDate.fromLocalDate(TEST_NOW.plusDays(23)), + GtfsDate.fromLocalDate(TEST_NOW.plusDays(30)))); } @Test public void feedExpiring30DaysFromNowShouldGenerateNotice() { - assertThat( - validateFeedInfo( - createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(30))))) + assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(30))))) .containsExactly( new FeedExpirationDate30DaysNotice( 1, - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate()), - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(30)), - GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(30)))); + GtfsDate.fromLocalDate(TEST_NOW), + GtfsDate.fromLocalDate(TEST_NOW.plusDays(30)), + GtfsDate.fromLocalDate(TEST_NOW.plusDays(30)))); } @Test public void feedExpiringInMoreThan30DaysFromNowShouldNotGenerateNotice() { - assertThat( - validateFeedInfo( - createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.toLocalDate().plusDays(45))))) + assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(45))))) .isEmpty(); } }