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 28, 2022
1 parent c666b0e commit 2a06f77
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
Expand Up @@ -36,15 +36,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'> if (toVisit == null) {</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>"
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
@@ -0,0 +1,46 @@
/*
RequireThis
checkFields = (default)true
checkMethods = (default)true
validateOnlyOverlapping = (default)true
*/

package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;

public class InputRequireThisAnonymousInnerClass {
int a = 12;

void method() {
int a = 1;
InputRequireThisAnonymousInnerClass obj =
new InputRequireThisAnonymousInnerClass() {
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 2a06f77

Please sign in to comment.