Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Notice documentation header check. #1422

Merged
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static NoticeSchema generateSchemaForNotice(Class<? extends Notice> noticeClass)
return schema;
}

private static NoticeDocComments loadComments(Class<?> noticeClass) {
public static NoticeDocComments loadComments(Class<?> noticeClass) {
String resourceName = NoticeDocComments.getResourceNameForClass(noticeClass);
InputStream is = noticeClass.getResourceAsStream(resourceName);
if (is == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public void validate(NoticeContainer noticeContainer) {
}
}

/**
* Dataset should not contain date ranges for services that have already expired.
*
* <p>This warning takes into account the `calendar_dates.txt` file as well as the `calendar.txt`
* file.
*/
@GtfsValidationNotice(
severity = WARNING,
urls = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public void validate(GtfsFeedInfo entity, NoticeContainer noticeContainer) {
}
}

/**
* The dataset expiration date defined in `feed_info.txt` is in seven days or less. At any time,
* the published GTFS dataset should be valid for at least the next 7 days.
*/
@GtfsValidationNotice(severity = WARNING)
static class FeedExpirationDate7DaysNotice extends ValidationNotice {

Expand Down Expand Up @@ -106,6 +110,10 @@ static class FeedExpirationDate7DaysNotice extends ValidationNotice {
}
}

/**
* At any time, the GTFS dataset should cover at least the next 30 days of service, and ideally
* for as long as the operator is confident that the schedule will continue to be operated.
*/
@GtfsValidationNotice(
severity = WARNING,
urls = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void validate(GtfsPathway pathway, NoticeContainer noticeContainer) {
}
}

/** A pathway should not have same values for `from_stop_id` and `to_stop_id`x. */
@GtfsValidationNotice(severity = WARNING, files = @FileRefs(GtfsPathwaySchema.class))
static class PathwayLoopNotice extends ValidationNotice {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.mobilitydata.gtfsvalidator.validator;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
Expand All @@ -16,6 +18,8 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mobilitydata.gtfsvalidator.notice.Notice;
import org.mobilitydata.gtfsvalidator.notice.NoticeDocComments;
import org.mobilitydata.gtfsvalidator.notice.schema.NoticeSchemaGenerator;

@RunWith(JUnit4.class)
public class NoticeDocumentationTest {
Expand Down Expand Up @@ -51,6 +55,22 @@ public void testThatRulesMarkdownContainsHeadersForAllValidationNotices() throws
assertThat(fromMarkdown).isEqualTo(fromSource);
}

@Test
public void testThatAllValidationNoticesAreDocumented() {
List<Class<?>> noticesWithoutDocComment =
discoverValidationNoticeClasses()
.filter(
clazz -> {
NoticeDocComments docComments = NoticeSchemaGenerator.loadComments(clazz);
return docComments.getDocComment() == null;
})
.collect(Collectors.toList());
assertWithMessage(
"We expect all validation notices to have a documentation comment. If this test fails, it likely means that a Javadoc /** */ documentation header needs to be added to the following classes:")
.that(noticesWithoutDocComment)
.isEmpty();
}

private static Stream<Class<Notice>> discoverValidationNoticeClasses() {
return ClassGraphDiscovery.discoverNoticeSubclasses(ClassGraphDiscovery.DEFAULT_NOTICE_PACKAGES)
.stream();
Expand Down