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 10, 2023
1 parent bbeef6d commit 1886593
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,4 @@
<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
46 changes: 46 additions & 0 deletions src/test/java/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,52 @@ public void testExternalResourceFiltersWithNoExternalResource() throws Exception
verify(checkerConfig, filePath, expected);
}

@Test
public void testMultiCheckOfSameType() throws Exception {

final DefaultConfiguration configuration1 = createModuleConfig(ParameterNameCheck.class);
configuration1.addProperty("format", "^[a-z]([a-z0-9][a-zA-Z0-9]*)?$");
configuration1.addProperty("accessModifiers", "protected, package, private");
configuration1.addProperty("id", "check1");
final DefaultConfiguration configuration2 = createModuleConfig(ParameterNameCheck.class);
configuration2.addProperty("format", "^[0-1]([a-z0-9][a-zA-Z0-9]*)?$");
configuration2.addProperty("accessModifiers", "protected, package, private");
configuration2.addProperty("id", "check2");
final DefaultConfiguration configuration3 = createModuleConfig(WhitespaceAfterCheck.class);
configuration3.addProperty("id", "check3");
final DefaultConfiguration configuration4 = createModuleConfig(WhitespaceAroundCheck.class);
configuration4.addProperty("id", "check4");

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

final String[] expected = {
"5:28: " + getCheckMessage(ParameterNameCheck.class,
"name.invalidPattern", "V2", "^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"),
"5:28: " + getCheckMessage(ParameterNameCheck.class,
"name.invalidPattern", "V2", "^[0-1]([a-z0-9][a-zA-Z0-9]*)?$"),
"5:32: " + getCheckMessage(WhitespaceAfterCheck.class, "ws.notFollowed", "{"),
"5:33: " + getCheckMessage(WhitespaceAroundCheck.class, "ws.notPreceded", "}"),
"10:9: " + getCheckMessage(WhitespaceAfterCheck.class, "ws.notFollowed", "if"),
"10:9: " + getCheckMessage(WhitespaceAroundCheck.class, "ws.notFollowed", "if"),
};

List<String> violations =
getActualViolationsForFile(treeWalkerConfig, getPath("InputTreeWalker2.java"));

for(int index = 0; index < expected.length - 1; index++) {
String expectedViolationMessagePosition = expected[index].substring(0,4);
String detectedViolationMessagePosition = violations.get(index).substring(0,4);
assertWithMessage("")
.that(detectedViolationMessagePosition)
.isEqualTo(expectedViolationMessagePosition);
}

}

public static class BadJavaDocCheck 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 1886593

Please sign in to comment.