Skip to content

Commit

Permalink
Issue #9142: finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Jan 3, 2022
1 parent 1d5f86a commit 2f9dd0d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 53 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 most assertions for Truth -->
<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 @@ -100,30 +100,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
25 changes: 15 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,28 @@ 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 " + 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 "
+ 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: " + lnr.readLine())
.that(errs)
.isEqualTo(expected.length);
assertWithMessage("unexpected warnings " + 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 @@ -21,7 +21,6 @@

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

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -223,7 +222,9 @@ public void testFinishLocalSetup() {
@Test
public void testLanguageIsValid() {
final String language = DEFAULT_LOCALE.getLanguage();
assumeFalse(language.isEmpty(), "Locale not set");
assertWithMessage("Locale not set")
.that(language)
.isNotEmpty();
assertWithMessage("Invalid language")
.that(Arrays.asList(Locale.getISOLanguages()))
.contains(language);
Expand All @@ -235,7 +236,9 @@ public void testLanguageIsValid() {
@Test
public void testCountryIsValid() {
final String country = DEFAULT_LOCALE.getCountry();
assumeFalse(country.isEmpty(), "Locale not set");
assertWithMessage("Locale not set")
.that(country)
.isEmpty();
assertWithMessage("Invalid country")
.that(Arrays.asList(Locale.getISOCountries()))
.contains(country);
Expand All @@ -248,8 +251,9 @@ public void testCountryIsValid() {
@Test
public void testLocaleIsSupported() throws Exception {
final String language = DEFAULT_LOCALE.getLanguage();
assumeFalse(language.isEmpty() || Locale.ENGLISH.getLanguage().equals(language),
"Custom locale not set");
assertWithMessage("Custom locale not set")
.that(language.isEmpty() || Locale.ENGLISH.getLanguage().equals(language))
.isFalse();
final Class<?> localizedMessage = getDefaultLoggerClass().getDeclaredClasses()[0];
final Object messageCon = localizedMessage.getConstructor(String.class, String[].class)
.newInstance(DefaultLogger.ADD_EXCEPTION_MESSAGE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +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;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -75,7 +73,9 @@ public void testLoadFromUrl() throws Exception {
}
}

assumeTrue(actualFilterSet != null, "No Internet connection.");
assertWithMessage("No Internet connection.")
.that(actualFilterSet)
.isNotNull();
final FilterSet expectedFilterSet = new FilterSet();
assertWithMessage("Failed to load from url")
.that(actualFilterSet.getFilters())
Expand Down Expand Up @@ -184,8 +184,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(IllegalArgumentException.class.getSimpleName() + " was expected.")
.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: " + type)
.that(node.isPresent())
.isTrue();

return node.get();
}
Expand Down

0 comments on commit 2f9dd0d

Please sign in to comment.