Skip to content

Commit

Permalink
Issue checkstyle#11446: update TreeWalkerTest to remove verify usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mahfouz72 authored and romani committed Feb 5, 2024
1 parent 8e33b96 commit ff18405
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/test/java/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ public void testWithCheckNotHavingTreeWalkerAsParent() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(JavadocPackageCheck.class);

try {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(createChecker(createTreeWalkerConfig(checkConfig)),
File.createTempFile("junit", null, temporaryFolder).getPath(), expected);
execute(createTreeWalkerConfig(checkConfig),
File.createTempFile("junit", null, temporaryFolder).getPath());
assertWithMessage("CheckstyleException is expected").fail();
}
catch (CheckstyleException exception) {
Expand Down Expand Up @@ -414,13 +413,16 @@ public void testProcessWithRecognitionException() throws Exception {

@Test
public void testRequiredTokenIsEmptyIntArray() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(RequiredTokenIsEmptyIntArray.class);
final String pathToEmptyFile =
File.createTempFile("file", ".java", temporaryFolder).getPath();

final File file = new File(temporaryFolder, "file.java");
try (Writer writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
final String configComment = "/*\n"
+ "com.puppycrawl.tools.checkstyle.TreeWalkerTest"
+ "$RequiredTokenIsEmptyIntArray\n\n"
+ "*/";
writer.write(configComment);
}
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, pathToEmptyFile, expected);
verifyWithInlineConfigParser(file.getPath(), expected);
}

@Test
Expand Down Expand Up @@ -554,8 +556,7 @@ public void testCheckInitIsCalledInTreeWalker() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(VerifyInitCheck.class);
final File file = File.createTempFile("file", ".pdf", temporaryFolder);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, file.getPath(), expected);
execute(checkConfig, file.getPath());
assertWithMessage("Init was not called")
.that(VerifyInitCheck.isInitWasCalled())
.isTrue();
Expand All @@ -567,8 +568,7 @@ public void testCheckDestroyIsCalledInTreeWalker() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(VerifyDestroyCheck.class);
final File file = File.createTempFile("file", ".pdf", temporaryFolder);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, file.getPath(), expected);
execute(checkConfig, file.getPath());
assertWithMessage("Destroy was not called")
.that(VerifyDestroyCheck.isDestroyWasCalled())
.isTrue();
Expand All @@ -580,8 +580,7 @@ public void testCommentCheckDestroyIsCalledInTreeWalker() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(VerifyDestroyCommentCheck.class);
final File file = File.createTempFile("file", ".pdf", temporaryFolder);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, file.getPath(), expected);
execute(checkConfig, file.getPath());
assertWithMessage("Destroy was not called")
.that(VerifyDestroyCheck.isDestroyWasCalled())
.isTrue();
Expand All @@ -600,10 +599,9 @@ public void testCacheWhenFileExternalResourceContentDoesNotChange() throws Excep

final String filePath = File.createTempFile("file", ".java", temporaryFolder).getPath();

final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkerConfig, filePath, expected);
execute(checkerConfig, filePath);
// One more time to use cache.
verify(checkerConfig, filePath, expected);
execute(checkerConfig, filePath);

assertWithMessage("External resource is not present in cache")
.that(Files.readString(cacheFile.toPath()))
Expand Down

0 comments on commit ff18405

Please sign in to comment.