Skip to content

Commit

Permalink
Issue checkstyle#11720: Kill surviving mutation in RequireThisCheck r…
Browse files Browse the repository at this point in the history
…elated to anonymous inner class
  • Loading branch information
Vyom-Yadav committed Jun 29, 2022
1 parent c8c2d8c commit e3aea5f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
Expand Up @@ -27,15 +27,6 @@
<lineContent>&amp;&amp; ast.getParent().getType() != TokenTypes.LITERAL_CATCH) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>RequireThisCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck</mutatedClass>
<mutatedMethod>endCollectingDeclarations</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE</mutator>
<description>removed conditional - replaced equality check with false</description>
<lineContent>if (isAnonymousClassDef(ast)) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>RequireThisCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck</mutatedClass>
Expand Down
1 change: 0 additions & 1 deletion .ci/pitest-survival-check-html.sh
Expand Up @@ -199,7 +199,6 @@ pitest-coding-2)
pitest-coding-require-this-check)
declare -a ignoredItems=(
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; ast.getParent().getType() != TokenTypes.LITERAL_CATCH) {</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> if (isAnonymousClassDef(ast)) {</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; parent.getType() != TokenTypes.CTOR_DEF</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; lastChild.getType() == TokenTypes.OBJBLOCK;</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> if (definitionToken.getType() == TokenTypes.STATIC_INIT) {</span></pre></td></tr>"
Expand Down
Expand Up @@ -175,9 +175,9 @@ public void testTokensNotNull() {
@Test
public void testWithAnonymousClass() throws Exception {
final String[] expected = {
"28:25: " + getCheckMessage(MSG_METHOD, "doSideEffect", ""),
"32:24: " + getCheckMessage(MSG_VARIABLE, "bar", "InputRequireThisAnonymousEmpty."),
"55:17: " + getCheckMessage(MSG_VARIABLE, "foobar", ""),
"29:25: " + getCheckMessage(MSG_METHOD, "doSideEffect", ""),
"33:24: " + getCheckMessage(MSG_VARIABLE, "bar", "InputRequireThisAnonymousEmpty."),
"56:17: " + getCheckMessage(MSG_VARIABLE, "foobar", ""),
};
verifyWithInlineConfigParser(
getPath("InputRequireThisAnonymousEmpty.java"),
Expand Down Expand Up @@ -443,6 +443,14 @@ public void testRecordsDefault() throws Exception {
expected);
}

@Test
public void testAnonymousInnerClass() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verifyWithInlineConfigParser(
getPath("InputRequireThisAnonymousInnerClass.java"), expected);
}

@Test
public void testUnusedMethod() throws Exception {
final DetailAstImpl ident = new DetailAstImpl();
Expand Down
Expand Up @@ -12,6 +12,7 @@
public class InputRequireThisAnonymousEmpty {

private int bar;
int a;

interface AnonWithEmpty {
public void fooEmpty();
Expand Down Expand Up @@ -56,4 +57,36 @@ public void fooEmpty() {
}
};
}

void method2() {
int a = 1;
InputRequireThisAnonymousEmpty obj =
new InputRequireThisAnonymousEmpty() {
void method() {
a += 1;
}
};
}

void anotherMethod() {
int var1 = 12;
int var2 = 13;
Foo obj = new Foo() {
void method() {
var2 += var1;
}
};
obj.getClass();
}
}

class SharkFoo {
int var1 = 12;
}

class Foo {
int var2 = 13;

class SharkFoo {
}
}

0 comments on commit e3aea5f

Please sign in to comment.