Skip to content

Commit

Permalink
Issue #9142: finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and pbludov committed Jan 9, 2022
1 parent 6393a4b commit a1c3c35
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 46 deletions.
4 changes: 3 additions & 1 deletion config/import-control-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<!-- Disallow hamcrest and only allow Truth -->
<disallow pkg="org.hamcrest.CoreMatchers"/>
<disallow pkg="org.hamcrest.MatcherAssert"/>
<!-- until https://github.com/checkstyle/checkstyle/issues/9142 -->
<!-- Disallow Junit assert in favor of Truth asserts in few exceptions -->
<allow class="org.junit.jupiter.api.Assertions.assertThrows"/>
<allow class="org.junit.jupiter.api.Assertions.assertDoesNotThrow"/>
<disallow pkg="org.junit.jupiter.api.Assertions"/>

<!-- Reflection shouldn't be used in tests. -->
Expand Down
24 changes: 0 additions & 24 deletions config/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,6 @@
<!-- until https://github.com/checkstyle/checkstyle/issues/5234 -->
<suppress id="MatchXPathBranchContains" files="[\\/]DetailAstImplTest.java"/>

<!-- until https://github.com/checkstyle/checkstyle/issues/9142 -->
<suppress id="ImportControlTest"
files="[\\/]src[\\/]it[\\/]java[\\/]org[\\/]checkstyle[\\/]base[\\/]AbstractItModuleTestSupport.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]it[\\/]java[\\/]org[\\/]checkstyle[\\/]suppressionxpathfilter[\\/]AbstractXpathTestSupport.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]PropertyCacheFileTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]ant[\\/]CheckstyleAntTaskTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]header[\\/]HeaderCheckTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]javadoc[\\/]AbstractJavadocCheckTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]regexp[\\/]RegexpOnFilenameCheckTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]filters[\\/]SuppressionsLoaderTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]utils[\\/]ChainedPropertyUtilTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]utils[\\/]CheckUtilTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]xpath[\\/]AttributeNodeTest.java"/>

<!-- until https://github.com/checkstyle/checkstyle/issues/11123 -->
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]api[\\/]JavadocTokenTypesTest.java"/>
Expand Down
26 changes: 16 additions & 10 deletions src/it/java/org/checkstyle/base/AbstractItModuleTestSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

package org.checkstyle.base;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static com.google.common.truth.Truth.assertWithMessage;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -251,22 +250,29 @@ protected final void verify(Checker checker,
for (int i = 0; i < expected.length; i++) {
final String expectedResult = messageFileName + ":" + expected[i];
final String actual = lnr.readLine();
assertEquals(expectedResult, actual, "error message " + i);
assertWithMessage("error message %s", i)
.that(actual)
.isEqualTo(expectedResult);

String parseInt = removeDeviceFromPathOnWindows(actual);
parseInt = parseInt.substring(parseInt.indexOf(':') + 1);
parseInt = parseInt.substring(0, parseInt.indexOf(':'));
final int lineNumber = Integer.parseInt(parseInt);
assertTrue(previousLineNumber == lineNumber
|| theWarnings.remove((Integer) lineNumber),
"input file is expected to have a warning comment on line number "
+ lineNumber);
assertWithMessage(
"input file is expected to have a warning comment on line number %s",
lineNumber)
.that(previousLineNumber == lineNumber
|| theWarnings.remove((Integer) lineNumber))
.isTrue();
previousLineNumber = lineNumber;
}

assertEquals(expected.length,
errs, "unexpected output: " + lnr.readLine());
assertEquals(0, theWarnings.size(), "unexpected warnings " + theWarnings);
assertWithMessage("unexpected output: %s", lnr.readLine())
.that(errs)
.isEqualTo(expected.length);
assertWithMessage("unexpected warnings %s", theWarnings)
.that(theWarnings)
.isEmpty();
}

checker.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.checkstyle.suppressionxpathfilter;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static com.google.common.truth.Truth.assertWithMessage;

import java.io.File;
import java.io.Writer;
Expand Down Expand Up @@ -102,8 +102,9 @@ private static List<String> generateXpathQueries(File fileToProcess,
*/
private static void verifyXpathQueries(List<String> generatedXpathQueries,
List<String> expectedXpathQueries) {
assertEquals(expectedXpathQueries,
generatedXpathQueries, "Generated queries do not match expected ones");
assertWithMessage("Generated queries do not match expected ones")
.that(generatedXpathQueries)
.isEqualTo(expectedXpathQueries);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.puppycrawl.tools.checkstyle.filters;

import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.io.IOException;
Expand Down Expand Up @@ -184,8 +183,9 @@ public void testBadInt() throws IOException {
assertWithMessage("Exception is expected").fail();
}
catch (CheckstyleException ex) {
assertTrue(ex.getMessage().startsWith("Number format exception " + fn + " - "),
ex.getMessage());
assertWithMessage(ex.getMessage())
.that(ex.getMessage())
.startsWith("Number format exception " + fn + " - ");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static com.google.common.truth.Truth.assertWithMessage;
import static com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.findTokenInAstByPredicate;
import static com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.isUtilsClassHasPrivateConstructor;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -154,7 +153,8 @@ public void testGetAccessModifierFromModifiersTokenWrongTokenType() {

try {
CheckUtil.getAccessModifierFromModifiersToken(modifiers);
fail(IllegalArgumentException.class.getSimpleName() + " was expected.");
assertWithMessage("%s was expected.", IllegalArgumentException.class.getSimpleName())
.fail();
}
catch (IllegalArgumentException exc) {
final String expectedExceptionMsg = "expected non-null AST-token with type 'MODIFIERS'";
Expand Down Expand Up @@ -452,9 +452,9 @@ private static DetailAST getNode(DetailAST root, int type) {
final Optional<DetailAST> node = findTokenInAstByPredicate(root,
ast -> ast.getType() == type);

if (!node.isPresent()) {
fail("Cannot find node of specified type: " + type);
}
assertWithMessage("Cannot find node of specified type: %s", type)
.that(node.isPresent())
.isTrue();

return node.get();
}
Expand Down

0 comments on commit a1c3c35

Please sign in to comment.