Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #12331: Test case added for FinalLocalVariableCheck to kill mut… #12611

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions config/pitest-suppressions/pitest-coding-2-suppressions.xml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}
}
Original file line number Diff line number Diff line change
@@ -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'
}
}