Skip to content

Commit b04eb41

Browse files
Kevin222004romani
authored andcommitted
Issue checkstyle#13809: Kill mutation in Tree-Walker-2
1 parent d52eb5d commit b04eb41

File tree

3 files changed

+85
-9
lines changed

3 files changed

+85
-9
lines changed

config/pitest-suppressions/pitest-tree-walker-suppressions.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,4 @@
8080
<description>removed call to java/util/Comparator::naturalOrder</description>
8181
<lineContent>Comparator.nullsLast(Comparator.naturalOrder()))</lineContent>
8282
</mutation>
83-
84-
<mutation unstable="false">
85-
<sourceFile>TreeWalker.java</sourceFile>
86-
<mutatedClass>com.puppycrawl.tools.checkstyle.TreeWalker</mutatedClass>
87-
<mutatedMethod>lambda$createNewCheckSortedSet$3</mutatedMethod>
88-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator</mutator>
89-
<description>replaced return value with &quot;&quot; for com/puppycrawl/tools/checkstyle/TreeWalker::lambda$createNewCheckSortedSet$3</description>
90-
<lineContent>Comparator.&lt;AbstractCheck, String&gt;comparing(check -&gt; check.getClass().getName())</lineContent>
91-
</mutation>
9283
</suppressedMutations>

src/test/java/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.ArrayList;
3434
import java.util.Arrays;
3535
import java.util.Collection;
36+
import java.util.Collections;
3637
import java.util.HashSet;
3738
import java.util.List;
3839
import java.util.Set;
@@ -679,6 +680,38 @@ public void testExternalResourceFiltersWithNoExternalResource() throws Exception
679680
verify(checkerConfig, filePath, expected);
680681
}
681682

683+
/**
684+
* This test is checking that Checks execution ordered by name.
685+
*
686+
* @throws Exception if file is not found
687+
*/
688+
@Test
689+
public void testOrderOfCheckExecution() throws Exception {
690+
691+
final DefaultConfiguration configuration1 = createModuleConfig(AaCheck.class);
692+
configuration1.addProperty("id", "2");
693+
final DefaultConfiguration configuration2 = createModuleConfig(BbCheck.class);
694+
configuration2.addProperty("id", "1");
695+
696+
final DefaultConfiguration treeWalkerConfig = createModuleConfig(TreeWalker.class);
697+
treeWalkerConfig.addChild(configuration2);
698+
treeWalkerConfig.addChild(configuration1);
699+
700+
final List<File> files =
701+
Collections.singletonList(new File(getPath("InputTreeWalker2.java")));
702+
final Checker checker = createChecker(treeWalkerConfig);
703+
704+
try {
705+
checker.process(files);
706+
assertWithMessage("exception is expected").fail();
707+
}
708+
catch (CheckstyleException exception) {
709+
assertWithMessage("wrong order of Check executions")
710+
.that(exception.getCause().getMessage())
711+
.isEqualTo(AaCheck.class.toString());
712+
}
713+
}
714+
682715
public static class BadJavaDocCheck extends AbstractCheck {
683716

684717
@Override
@@ -773,6 +806,54 @@ public boolean isCommentNodesRequired() {
773806

774807
}
775808

809+
public static class AaCheck extends AbstractCheck {
810+
811+
@Override
812+
public int[] getDefaultTokens() {
813+
return new int[0];
814+
}
815+
816+
@Override
817+
public int[] getAcceptableTokens() {
818+
return new int[0];
819+
}
820+
821+
@Override
822+
public int[] getRequiredTokens() {
823+
return new int[0];
824+
}
825+
826+
@Override
827+
public void beginTree(DetailAST rootAST) {
828+
throw new IllegalStateException(AaCheck.class.toString());
829+
}
830+
831+
}
832+
833+
public static class BbCheck extends AbstractCheck {
834+
835+
@Override
836+
public int[] getDefaultTokens() {
837+
return new int[0];
838+
}
839+
840+
@Override
841+
public int[] getAcceptableTokens() {
842+
return new int[0];
843+
}
844+
845+
@Override
846+
public int[] getRequiredTokens() {
847+
return new int[0];
848+
}
849+
850+
@Override
851+
public void beginTree(DetailAST rootAST) {
852+
throw new IllegalStateException(BbCheck.class.toString());
853+
}
854+
855+
}
856+
776857
public static class RequiredTokenIsEmptyIntArray extends AbstractCheck {
777858

778859
@Override
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.puppycrawl.tools.checkstyle.treewalker;
2+
3+
public class InputTreeWalker2 {
4+
}

0 commit comments

Comments
 (0)