From c0f8d9de89c072ec47fc153919a10524d01245f4 Mon Sep 17 00:00:00 2001 From: Brian Ferris Date: Tue, 27 Jun 2023 13:15:50 -0700 Subject: [PATCH] Remove unit-test that RULES.md is up-to-date with Notice classes. --- main/build.gradle | 12 ---- .../validator/NoticeDocumentationTest.java | 71 ------------------- 2 files changed, 83 deletions(-) diff --git a/main/build.gradle b/main/build.gradle index df34c56bb0..b20e9cb31b 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -52,16 +52,4 @@ dependencies { testImplementation 'com.google.truth:truth:1.0.1' testImplementation 'com.google.truth.extensions:truth-java8-extension:1.0.1' testImplementation 'org.mockito:mockito-core:4.5.1' -} - -// A custom task to copy RULES.md into the test resource directory so that we can reference it in -// unit tests. See NoticeDocumentationTest for more details. -tasks.register('copyRulesMarkdown', Copy) { - from "$rootDir/RULES.md" - into "$projectDir/build/resources/test" -} - -test { - // Make sure `copyRulesMarkdown` runs before we run any tests. - dependsOn 'copyRulesMarkdown' } \ No newline at end of file diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeDocumentationTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeDocumentationTest.java index 72fd32375e..37ad6656f4 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeDocumentationTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeDocumentationTest.java @@ -1,20 +1,11 @@ package org.mobilitydata.gtfsvalidator.validator; -import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import com.google.common.collect.ImmutableList; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.Test; @@ -26,37 +17,6 @@ @RunWith(JUnit4.class) public class NoticeDocumentationTest { - private static Pattern MARKDOWN_NOTICE_SIMPLE_CLASS_NAME_ANCHOR_PATTERN = - Pattern.compile("^"); - - private static Pattern MARKDOWN_NOTICE_CODE_HEADER_PATTERN = - Pattern.compile("^### (([a-z0-9]+_)*[a-z0-9]+)"); - - /** - * If this test is failing, it likely means you need to update RULES.md in the project root - * directory to include an entry for a new notice. - */ - @Test - public void testThatRulesMarkdownContainsAnchorsForAllValidationNotices() throws IOException { - Set fromMarkdown = readNoticeSimpleClassNamesFromRulesMarkdown(); - Set fromSource = - discoverValidationNoticeClasses().map(Class::getSimpleName).collect(Collectors.toSet()); - - assertThat(fromMarkdown).isEqualTo(fromSource); - } - - /** - * If this test is failing, it likely means you need to update RULES.md in the project root - * directory to include an entry for a new notice. - */ - @Test - public void testThatRulesMarkdownContainsHeadersForAllValidationNotices() throws IOException { - Set fromMarkdown = readNoticeCodesFromRulesMarkdown(); - Set fromSource = - discoverValidationNoticeClasses().map(Notice::getCode).collect(Collectors.toSet()); - - assertThat(fromMarkdown).isEqualTo(fromSource); - } @Test public void testThatAllValidationNoticesAreDocumented() { @@ -164,35 +124,4 @@ private static Stream> discoverValidationNoticeClasses() { return ClassGraphDiscovery.discoverNoticeSubclasses(ClassGraphDiscovery.DEFAULT_NOTICE_PACKAGES) .stream(); } - - private static Set readNoticeSimpleClassNamesFromRulesMarkdown() throws IOException { - return readValuesFromRulesMarkdown(MARKDOWN_NOTICE_SIMPLE_CLASS_NAME_ANCHOR_PATTERN); - } - - private static Set readNoticeCodesFromRulesMarkdown() throws IOException { - return readValuesFromRulesMarkdown(MARKDOWN_NOTICE_CODE_HEADER_PATTERN); - } - - private static Set readValuesFromRulesMarkdown(Pattern pattern) throws IOException { - // RULES.md is copied into the main/build/resources/test resource directory by a custom copy - // rule in the main/build.gradle file. - try (InputStream in = NoticeDocumentationTest.class.getResourceAsStream("/RULES.md")) { - // Scan lines from the markdown file, find those that match our regex pattern, and pull out - // the matching group. - return new BufferedReader(new InputStreamReader(in)) - .lines() - .map(line -> maybeMatchAndExtract(pattern, line)) - .flatMap(Optional::stream) - .collect(Collectors.toSet()); - } - } - - private static Optional maybeMatchAndExtract(Pattern p, String line) { - Matcher m = p.matcher(line); - if (m.matches()) { - return Optional.of(m.group(1)); - } else { - return Optional.empty(); - } - } }