Skip to content

Commit

Permalink
Issue checkstyle#13809: Kill mutation in Tree-Walker-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin222004 authored and romani committed Nov 11, 2023
1 parent bbeef6d commit b219f03
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,4 @@
<description>removed call to java/util/Comparator::naturalOrder</description>
<lineContent>Comparator.nullsLast(Comparator.naturalOrder()))</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>TreeWalker.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.TreeWalker</mutatedClass>
<mutatedMethod>lambda$createNewCheckSortedSet$3</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator</mutator>
<description>replaced return value with &quot;&quot; for com/puppycrawl/tools/checkstyle/TreeWalker::lambda$createNewCheckSortedSet$3</description>
<lineContent>Comparator.&lt;AbstractCheck, String&gt;comparing(check -&gt; check.getClass().getName())</lineContent>
</mutation>
</suppressedMutations>
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ private void verifyViolations(Configuration config,
* @return list of actual violations.
* @throws Exception if exception occurs during verification process.
*/
private List<String> getActualViolationsForFile(Configuration config,
protected List<String> getActualViolationsForFile(Configuration config,
String file) throws Exception {
stream.flush();
stream.reset();
Expand Down
84 changes: 84 additions & 0 deletions src/test/java/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -679,6 +680,41 @@ public void testExternalResourceFiltersWithNoExternalResource() throws Exception
verify(checkerConfig, filePath, expected);
}

/**
* This test is required for pitest coverage.
* Order of Check execution is not visiable from outside
* as we order violations by line and column.
* This test is checking that Checks execution ordered by name and then by id.
*
* @throws Exception is file is not found
*/
@Test
public void testOrderOfCheckExecution() throws Exception {

final DefaultConfiguration configuration1 = createModuleConfig(AaCheck.class);
configuration1.addProperty("id", "2");
final DefaultConfiguration configuration2 = createModuleConfig(BbCheck.class);
configuration2.addProperty("id", "1");

final DefaultConfiguration treeWalkerConfig = createModuleConfig(TreeWalker.class);
treeWalkerConfig.addChild(configuration2);
treeWalkerConfig.addChild(configuration1);

final List<File> files =
Collections.singletonList(new File(getPath("InputTreeWalker2.java")));
final Checker checker = createChecker(treeWalkerConfig);

try {
checker.process(files);
assertWithMessage("exception is expected").fail();
}
catch (CheckstyleException exception) {
assertWithMessage("wrong order of Check executions")
.that(exception.getCause().getMessage())
.isEqualTo(AaCheck.class.toString());
}
}

public static class BadJavaDocCheck extends AbstractCheck {

@Override
Expand Down Expand Up @@ -773,6 +809,54 @@ public boolean isCommentNodesRequired() {

}

public static class AaCheck extends AbstractCheck {

@Override
public int[] getDefaultTokens() {
return new int[0];
}

@Override
public int[] getAcceptableTokens() {
return new int[0];
}

@Override
public int[] getRequiredTokens() {
return new int[0];
}

@Override
public void beginTree(DetailAST rootAST) {
throw new IllegalStateException(AaCheck.class.toString());
}

}

public static class BbCheck extends AbstractCheck {

@Override
public int[] getDefaultTokens() {
return new int[0];
}

@Override
public int[] getAcceptableTokens() {
return new int[0];
}

@Override
public int[] getRequiredTokens() {
return new int[0];
}

@Override
public void beginTree(DetailAST rootAST) {
throw new IllegalStateException(BbCheck.class.toString());
}

}

public static class RequiredTokenIsEmptyIntArray extends AbstractCheck {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.puppycrawl.tools.checkstyle.treewalker;

public class InputTreeWalker2 {
// void fn1(int v1) {}
protected void fn2(int V2) {} // violation "Parameter name 'V2' must match pattern"
// private void fn3(int a) {}

public void method() {
boolean test = true;
if(test) {
}
}
}

0 comments on commit b219f03

Please sign in to comment.