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

Issue #9142: resolve Assertions.assertNull #11130

Merged
merged 1 commit into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 0 additions & 12 deletions config/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]PropertyCacheFileTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]SuppressionsStringPrinterTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]XmlLoaderTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]XpathFileGeneratorAstFilterTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]ant[\\/]CheckstyleAntTaskTest.java"/>
<suppress id="ImportControlTest"
Expand All @@ -148,8 +144,6 @@
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]imports[\\/]CustomImportOrderCheckTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]imports[\\/]ImportControlLoaderTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]imports[\\/]PkgImportControlTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]javadoc[\\/]AbstractJavadocCheckTest.java"/>
<suppress id="ImportControlTest"
Expand All @@ -160,18 +154,12 @@
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]modifier[\\/]ModifierOrderCheckTest.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[\\/]SuppressWithPlainTextCommentFilterTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]filters[\\/]SuppressionCommentFilterTest.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[\\/]grammar[\\/]GeneratedJavaTokenTypesTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]grammar[\\/]javadoc[\\/]GeneratedJavadocTokenTypesTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]gui[\\/]MainFrameModelTest.java"/>
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]gui[\\/]ParseTreeTablePresentationTest.java"/>
<suppress id="ImportControlTest"
Expand Down
25 changes: 16 additions & 9 deletions src/test/java/com/puppycrawl/tools/checkstyle/CheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static com.puppycrawl.tools.checkstyle.DefaultLogger.AUDIT_FINISHED_MESSAGE;
import static com.puppycrawl.tools.checkstyle.DefaultLogger.AUDIT_STARTED_MESSAGE;
import static com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck.MSG_KEY_NO_NEWLINE_EOF;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -369,8 +368,9 @@ public void testFileExtensions() throws Exception {
assertWithMessage("Audit was finished on larger amount of files than expected")
.that(auditAdapter.getNumFilesFinished())
.isEqualTo(numLegalFiles);
assertNull(cache.get(new File("file.java").getCanonicalPath()),
"Cache shout not contain any file");
assertWithMessage("Cache shout not contain any file")
.that(cache.get(new File("file.java").getCanonicalPath()))
.isNull();
}

@Test
Expand Down Expand Up @@ -752,8 +752,10 @@ public void testClearCacheWhenCacheFileIsNotSet() {
// the invocation of clearCache method does not throw an exception.
final Checker checker = new Checker();
checker.clearCache();
assertNull(TestUtil.getInternalState(checker, "cacheFile"),
"If cache file is not set the cache should default to null");
final PropertyCacheFile cache = TestUtil.getInternalState(checker, "cacheFile");
assertWithMessage("If cache file is not set the cache should default to null")
.that(cache)
.isNull();
}

/**
Expand Down Expand Up @@ -986,8 +988,9 @@ public void testCacheAndCheckWhichAddsNewResourceLocationButKeepsSameCheckerInst
assertWithMessage("Number of items in cache differs from expected")
.that(cacheAfterSecondRun)
.hasSize(expectedNumberOfObjectsInCacheAfterSecondRun);
assertNull(cacheAfterFirstRun.getProperty(secondExternalResourceKey),
"Cache has not null as a resource key");
assertWithMessage("Cache has not null as a resource key")
.that(cacheAfterFirstRun.getProperty(secondExternalResourceKey))
.isNull();
assertWithMessage("Cache has null as a resource key")
.that(cacheAfterSecondRun.getProperty(secondExternalResourceKey))
.isNotNull();
Expand Down Expand Up @@ -1096,7 +1099,9 @@ public void testExceptionWithCache() throws Exception {
assertWithMessage("Cache has unexpected size")
.that(cache)
.hasSize(1);
assertNull(cache.getProperty(filePath), "testFile is not in cache");
assertWithMessage("testFile is not in cache")
.that(cache.getProperty(filePath))
.isNull();
}
}

Expand Down Expand Up @@ -1166,7 +1171,9 @@ public File getAbsoluteFile() {
assertWithMessage("Cache has unexpected size")
.that(cache)
.hasSize(1);
assertNull(cache.getProperty("testFile"), "testFile is not in cache");
assertWithMessage("testFile is not in cache")
.that(cache.getProperty("testFile"))
.isNull();
}
}

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.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;

import java.io.File;
Expand Down Expand Up @@ -171,9 +170,15 @@ public void testGetChildCount() throws Exception {
.that(root.getNumberOfChildren())
.isEqualTo(2);

assertNull(root.getPreviousSibling(), "Previous sibling should be null");
assertNull(firstLevelA.getPreviousSibling(), "Previous sibling should be null");
assertNull(secondLevelA.getPreviousSibling(), "Previous sibling should be null");
assertWithMessage("Previous sibling should be null")
.that(root.getPreviousSibling())
.isNull();
assertWithMessage("Previous sibling should be null")
.that(firstLevelA.getPreviousSibling())
.isNull();
assertWithMessage("Previous sibling should be null")
.that(secondLevelA.getPreviousSibling())
.isNull();
assertWithMessage("Invalid previous sibling")
.that(firstLevelB.getPreviousSibling())
.isEqualTo(firstLevelA);
Expand Down Expand Up @@ -485,7 +490,9 @@ public void testAddNextSiblingNullParent() {
assertWithMessage("Invalid parent")
.that(newSibling.getParent())
.isEqualTo(oldParent);
assertNull(newSibling.getNextSibling(), "Invalid next sibling");
assertWithMessage("Invalid next sibling")
.that(newSibling.getNextSibling())
.isNull();
assertSame(newSibling, child.getNextSibling(), "Invalid child");
}

Expand Down Expand Up @@ -571,7 +578,9 @@ public void testFindFirstToken() {
root.addChild(secondChild);
root.addChild(thirdChild);

assertNull(firstChild.findFirstToken(TokenTypes.IDENT), "Invalid result");
assertWithMessage("Invalid result")
.that(firstChild.findFirstToken(TokenTypes.IDENT))
.isNull();
final DetailAST ident = root.findFirstToken(TokenTypes.IDENT);
assertWithMessage("Invalid result")
.that(ident)
Expand All @@ -580,7 +589,9 @@ public void testFindFirstToken() {
assertWithMessage("Invalid result")
.that(expr)
.isEqualTo(secondChild);
assertNull(root.findFirstToken(0), "Invalid result");
assertWithMessage("Invalid result")
.that(root.findFirstToken(0))
.isNull();
}

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

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

import java.io.File;
Expand Down Expand Up @@ -52,7 +51,9 @@ public void testIsProperUtilsClass() throws ReflectiveOperationException {

@Test
public void testNullRootWithComments() {
assertNull(JavaParser.appendHiddenCommentNodes(null), "Invalid return root");
assertWithMessage("Invalid return root")
.that(JavaParser.appendHiddenCommentNodes(null))
.isNull();
}

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

import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mockStatic;
Expand Down Expand Up @@ -128,7 +127,9 @@ public void testPopulateDetails() throws IOException {
assertWithMessage("Config hash key should not be null")
.that(hash)
.isNotNull();
assertNull(cache.get("key"), "Should return null if key is not in cache");
assertWithMessage("Should return null if key is not in cache")
.that(cache.get("key"))
.isNull();

cache.load();

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 com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.isUtilsClassHasPrivateConstructor;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -58,7 +57,9 @@ public void testResolveEntityDefault() throws Exception {
final Map<String, String> map = new HashMap<>();
map.put("predefined", "/google.xml");
final DummyLoader dummyLoader = new DummyLoader(map);
assertNull(dummyLoader.resolveEntity("notPredefined", "BAD"), "Invalid entity");
assertWithMessage("Invalid entity")
.that(dummyLoader.resolveEntity("notPredefined", "BAD"))
.isNull();
}

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

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

import java.io.File;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -53,8 +52,9 @@ public void testAcceptNoToken() {

final AuditEvent auditEvent = new AuditEvent(this, "Test.java", violation);

assertNull(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent),
"filter has no queries");
assertWithMessage("filter has no queries")
.that(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent))
.isNull();
}

@Test
Expand Down Expand Up @@ -95,8 +95,9 @@ public void testNoXpathQuery() throws Exception {
final AuditEvent auditEvent = new AuditEvent(this,
getPath("InputXpathFileGeneratorAstFilter.java"), violation);

assertNull(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent),
"expected null");
assertWithMessage("expected null")
.that(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent))
.isNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -147,7 +146,9 @@ public void testBundleReloadUrlNull() throws IOException {
"com.puppycrawl.tools.checkstyle.checks.coding.messages",
Locale.ENGLISH, "java.class",
Thread.currentThread().getContextClassLoader(), true);
assertNull(bundle, "Bundle should be null when reload is true and URL is null");
assertWithMessage("Bundle should be null when reload is true and URL is null")
.that(bundle)
.isNull();
}

/**
Expand Down Expand Up @@ -272,7 +273,9 @@ protected URLConnection openConnection(URL u) {
"com.puppycrawl.tools.checkstyle.checks.coding.messages",
Locale.ENGLISH, "java.class",
new TestUrlsClassLoader(url), true);
assertNull(bundle, "Bundle should be null when stream is null");
assertWithMessage("Bundle should be null when stream is null")
.that(bundle)
.isNull();
}

@Test
Expand Down
Loading