Skip to content

Commit

Permalink
Issue checkstyle#12331: Test case added for FinalLocalVariableCheck t…
Browse files Browse the repository at this point in the history
…o kill mutation
  • Loading branch information
Kevin222004 committed Jan 9, 2023
1 parent 4e7f18c commit 312b77b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
9 changes: 0 additions & 9 deletions config/pitest-suppressions/pitest-coding-2-suppressions.xml
Expand Up @@ -72,15 +72,6 @@
<lineContent>prevScopeUninitializedVariables.pop();</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>FinalLocalVariableCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck</mutatedClass>
<mutatedMethod>leaveToken</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_2</mutator>
<description>RemoveSwitch 2 (case value 8)</description>
<lineContent>switch (ast.getType()) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>FinalLocalVariableCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck</mutatedClass>
Expand Down
Expand Up @@ -307,4 +307,17 @@ public void testFinalLocalVariableSwitchStatement() throws Exception {
expected);
}

@Test
public void testConstructor() throws Exception {
final String[] expected = {
"14:44: " + getCheckMessage(MSG_KEY, "a"),
"18:44: " + getCheckMessage(MSG_KEY, "a"),
"19:43: " + getCheckMessage(MSG_KEY, "b"),
"22:47: " + getCheckMessage(MSG_KEY, "str"),
"35:21: " + getCheckMessage(MSG_KEY, "str"),
};
verifyWithInlineConfigParser(
getPath("InputFinalLocalVariableConstructor.java"),
expected);
}
}
@@ -0,0 +1,38 @@
/*
FinalLocalVariable
validateEnhancedForLoopVariable = (default)false
tokens = PARAMETER_DEF
*/


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

public class InputFinalLocalVariableConstructor {

InputFinalLocalVariableConstructor(int a) {
// violation above 'Variable 'a' should be declared final'
}

InputFinalLocalVariableConstructor(int a, // violation 'Variable 'a' should be declared final'
int b) { // violation 'Variable 'b' should be declared final'
}

InputFinalLocalVariableConstructor(String str) {
// violation above 'Variable 'str' should be declared final'
}
}

class Mutation {

Mutation(final int a) { // ok
}

Mutation(final String check) { // ok
}

Mutation(String str, final int b) {
// violation above 'Variable 'str' should be declared final'
}
}

0 comments on commit 312b77b

Please sign in to comment.