diff --git a/pom.xml b/pom.xml
index 3ab7a4eca56..5014ac03e9f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1864,6 +1864,7 @@
**/CheckerTest.class
+ **/WriteTagCheckTest.class
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/AbstractModuleTestSupport.java b/src/test/java/com/puppycrawl/tools/checkstyle/AbstractModuleTestSupport.java
index 67db8ef4f8e..8ba67719178 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/AbstractModuleTestSupport.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/AbstractModuleTestSupport.java
@@ -210,14 +210,23 @@ protected final void verifyFilterWithInlineConfigParser(String filePath,
testInputConfiguration.createConfigurationWithoutFilters();
final List violationsWithoutFilters =
new ArrayList<>(testInputConfiguration.getViolations());
+ final List actualViolationsWithoutFilters =
+ getActualViolationsForFile(configWithoutFilters, filePath);
violationsWithoutFilters.addAll(testInputConfiguration.getFilteredViolations());
Collections.sort(violationsWithoutFilters);
- verifyViolations(configWithoutFilters, filePath, violationsWithoutFilters);
- verify(configWithoutFilters, filePath, expectedUnfiltered);
+ verifyViolations(filePath, violationsWithoutFilters, actualViolationsWithoutFilters);
+ assertWithMessage("Violations for %s differ.", filePath)
+ .that(actualViolationsWithoutFilters)
+ .containsExactlyElementsIn(expectedUnfiltered);
final DefaultConfiguration configWithFilters =
testInputConfiguration.createConfiguration();
- verifyViolations(configWithFilters, filePath, testInputConfiguration.getViolations());
- verify(configWithFilters, filePath, expectedFiltered);
+ final List actualViolationsWithFilters =
+ getActualViolationsForFile(configWithFilters, filePath);
+ verifyViolations(filePath, testInputConfiguration.getViolations(),
+ actualViolationsWithFilters);
+ assertWithMessage("Violations for %s differ.", filePath)
+ .that(actualViolationsWithFilters)
+ .containsExactlyElementsIn(expectedFiltered);
}
/**
@@ -229,14 +238,17 @@ protected final void verifyFilterWithInlineConfigParser(String filePath,
* @param expected an array of expected messages.
* @throws Exception if exception occurs during verification process.
*/
- protected final void verifyWithInlineConfigParser(String filePath, String... expected)
+ protected void verifyWithInlineConfigParser(String filePath, String... expected)
throws Exception {
final TestInputConfiguration testInputConfiguration =
InlineConfigParser.parse(filePath);
final DefaultConfiguration parsedConfig =
testInputConfiguration.createConfiguration();
- verifyViolations(parsedConfig, filePath, testInputConfiguration.getViolations());
- verify(parsedConfig, filePath, expected);
+ final List actualViolations = getActualViolationsForFile(parsedConfig, filePath);
+ verifyViolations(filePath, testInputConfiguration.getViolations(), actualViolations);
+ assertWithMessage("Violations for %s differ.", filePath)
+ .that(actualViolations)
+ .containsExactlyElementsIn(expected);
}
/**
@@ -468,9 +480,8 @@ protected static void execute(Checker checker, String... filenames) throws Excep
* @param testInputViolations List of TestInputViolation objects.
* @throws Exception if exception occurs during verification process.
*/
- private void verifyViolations(Configuration config,
- String file,
- List testInputViolations)
+ protected void verifyViolations(Configuration config, String file,
+ List testInputViolations)
throws Exception {
final List actualViolations = getActualViolationsForFile(config, file);
final List actualViolationLines = actualViolations.stream()
@@ -490,6 +501,33 @@ private void verifyViolations(Configuration config,
}
}
+ /**
+ * Performs verification of violation lines.
+ *
+ * @param file file path.
+ * @param testInputViolations List of TestInputViolation objects.
+ * @param actualViolations for a file
+ */
+ private void verifyViolations(String file,
+ List testInputViolations,
+ List actualViolations) {
+ final List actualViolationLines = actualViolations.stream()
+ .map(violation -> violation.substring(0, violation.indexOf(':')))
+ .map(Integer::valueOf)
+ .collect(Collectors.toUnmodifiableList());
+ final List expectedViolationLines = testInputViolations.stream()
+ .map(TestInputViolation::getLineNo)
+ .collect(Collectors.toUnmodifiableList());
+ assertWithMessage("Violation lines for %s differ.", file)
+ .that(actualViolationLines)
+ .isEqualTo(expectedViolationLines);
+ for (int index = 0; index < actualViolations.size(); index++) {
+ assertWithMessage("Actual and expected violations differ.")
+ .that(actualViolations.get(index))
+ .matches(testInputViolations.get(index).toRegex());
+ }
+ }
+
/**
* Tests the file with the check config.
*
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java
index b291307de41..dd87d8a43c0 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java
@@ -195,9 +195,7 @@ public void testPositionOne() throws Exception {
verifyWithInlineConfigParser(getPath("InputAbstractJavadocPositionOne.java"), expected);
assertWithMessage("Invalid number of javadocs")
.that(JavadocCatchCheck.javadocsNumber)
- // until https://github.com/checkstyle/checkstyle/issues/12586
- // actual javadoc count is 21, but verifyWithInlineConfigParser verify file twice
- .isEqualTo(42);
+ .isEqualTo(21);
}
@Test
@@ -207,9 +205,7 @@ public void testPositionTwo() throws Exception {
verifyWithInlineConfigParser(getPath("InputAbstractJavadocPositionTwo.java"), expected);
assertWithMessage("Invalid number of javadocs")
.that(JavadocCatchCheck.javadocsNumber)
- // until https://github.com/checkstyle/checkstyle/issues/12586
- // actual javadoc count is 29, but verifyWithInlineConfigParser verify file twice
- .isEqualTo(58);
+ .isEqualTo(29);
}
@Test
@@ -219,9 +215,7 @@ public void testPositionThree() throws Exception {
verifyWithInlineConfigParser(getPath("InputAbstractJavadocPositionThree.java"), expected);
assertWithMessage("Invalid number of javadocs")
.that(JavadocCatchCheck.javadocsNumber)
- // until https://github.com/checkstyle/checkstyle/issues/12586
- // actual javadoc count is 15, but verifyWithInlineConfigParser verify file twice
- .isEqualTo(30);
+ .isEqualTo(15);
}
@Test
@@ -232,9 +226,7 @@ public void testPositionWithSinglelineCommentsOne() throws Exception {
getPath("InputAbstractJavadocPositionWithSinglelineCommentsOne.java"), expected);
assertWithMessage("Invalid number of javadocs")
.that(JavadocCatchCheck.javadocsNumber)
- // until https://github.com/checkstyle/checkstyle/issues/12586
- // actual javadoc count is 21, but verifyWithInlineConfigParser verify file twice
- .isEqualTo(42);
+ .isEqualTo(21);
}
@Test
@@ -245,9 +237,7 @@ public void testPositionWithSinglelineCommentsTwo() throws Exception {
getPath("InputAbstractJavadocPositionWithSinglelineCommentsTwo.java"), expected);
assertWithMessage("Invalid number of javadocs")
.that(JavadocCatchCheck.javadocsNumber)
- // until https://github.com/checkstyle/checkstyle/issues/12586
- // actual javadoc count is 29, but verifyWithInlineConfigParser verify file twice
- .isEqualTo(58);
+ .isEqualTo(29);
}
@Test
@@ -258,9 +248,7 @@ public void testPositionWithSinglelineCommentsThree() throws Exception {
getPath("InputAbstractJavadocPositionWithSinglelineCommentsThree.java"), expected);
assertWithMessage("Invalid number of javadocs")
.that(JavadocCatchCheck.javadocsNumber)
- // until https://github.com/checkstyle/checkstyle/issues/12586
- // actual javadoc count is 15, but verifyWithInlineConfigParser verify file twice
- .isEqualTo(30);
+ .isEqualTo(15);
}
@Test
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/WriteTagCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/WriteTagCheckTest.java
index 5d0e90574d6..ff6b60a6339 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/WriteTagCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/WriteTagCheckTest.java
@@ -37,6 +37,9 @@
import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
import com.puppycrawl.tools.checkstyle.Checker;
+import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
+import com.puppycrawl.tools.checkstyle.bdd.InlineConfigParser;
+import com.puppycrawl.tools.checkstyle.bdd.TestInputConfiguration;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
/**
@@ -188,6 +191,17 @@ public void testWriteTagRecordsAndCompactCtors() throws Exception {
getNonCompilablePath("InputWriteTagRecordsAndCompactCtors.java"), expected);
}
+ @Override
+ protected void verifyWithInlineConfigParser(String filePath, String... expected)
+ throws Exception {
+ final TestInputConfiguration testInputConfiguration =
+ InlineConfigParser.parse(filePath);
+ final DefaultConfiguration parsedConfig =
+ testInputConfiguration.createConfiguration();
+ verifyViolations(parsedConfig, filePath, testInputConfiguration.getViolations());
+ verify(parsedConfig, filePath, expected);
+ }
+
@Override
protected void verify(Checker checker,
File[] processedFiles,