Issue #1288: 'StaticVariableNameCheck' was refactored, UT coverage improved
This commit is contained in:
parent
1203691be0
commit
4fd6b3ee59
1
pom.xml
1
pom.xml
|
|
@ -878,7 +878,6 @@
|
|||
<regex><pattern>.*.checks.naming.MethodNameCheck</pattern><branchRate>100</branchRate><lineRate>93</lineRate></regex>
|
||||
<regex><pattern>.*.checks.naming.PackageNameCheck</pattern><branchRate>100</branchRate><lineRate>88</lineRate></regex>
|
||||
<regex><pattern>.*.checks.naming.ParameterNameCheck</pattern><branchRate>75</branchRate><lineRate>80</lineRate></regex>
|
||||
<regex><pattern>.*.checks.naming.StaticVariableNameCheck</pattern><branchRate>81</branchRate><lineRate>87</lineRate></regex>
|
||||
|
||||
<regex><pattern>.*.checks.regexp.CommentSuppressor</pattern><branchRate>75</branchRate><lineRate>100</lineRate></regex>
|
||||
<regex><pattern>.*.checks.regexp.DetectorOptions</pattern><branchRate>100</branchRate><lineRate>96</lineRate></regex>
|
||||
|
|
|
|||
|
|
@ -68,10 +68,8 @@ public class StaticVariableNameCheck
|
|||
protected final boolean mustCheckName(DetailAST ast) {
|
||||
final DetailAST modifiersAST =
|
||||
ast.findFirstToken(TokenTypes.MODIFIERS);
|
||||
final boolean isStatic = modifiersAST != null
|
||||
&& modifiersAST.branchContains(TokenTypes.LITERAL_STATIC);
|
||||
final boolean isFinal = modifiersAST != null
|
||||
&& modifiersAST.branchContains(TokenTypes.FINAL);
|
||||
final boolean isStatic = modifiersAST.branchContains(TokenTypes.LITERAL_STATIC);
|
||||
final boolean isFinal = modifiersAST.branchContains(TokenTypes.FINAL);
|
||||
|
||||
return isStatic
|
||||
&& !isFinal
|
||||
|
|
|
|||
|
|
@ -19,11 +19,16 @@
|
|||
|
||||
package com.puppycrawl.tools.checkstyle.checks.naming;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN;
|
||||
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
|
||||
public class StaticVariableNameCheckTest
|
||||
extends BaseCheckTestSupport {
|
||||
|
|
@ -53,5 +58,29 @@ public class StaticVariableNameCheckTest
|
|||
};
|
||||
verify(checkConfig, getPath("InputSimple.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterfaceOrAnnotationBlock()
|
||||
throws Exception {
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(StaticVariableNameCheck.class);
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(checkConfig,
|
||||
new File("src/test/resources/com/puppycrawl/tools/"
|
||||
+ "checkstyle/naming/InputStaticVariableName.java").getCanonicalPath(),
|
||||
expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAcceptableTokens() {
|
||||
StaticVariableNameCheck staticVariableNameCheckObj = new StaticVariableNameCheck();
|
||||
int[] actual = staticVariableNameCheckObj.getAcceptableTokens();
|
||||
int[] expected = new int[] {
|
||||
TokenTypes.VARIABLE_DEF,
|
||||
};
|
||||
Assert.assertNotNull(actual);
|
||||
Assert.assertArrayEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.puppycrawl.tools.checkstyle.naming;
|
||||
|
||||
public class InputStaticVariableName {
|
||||
|
||||
/** Interface fields should be skipped */
|
||||
interface A {
|
||||
public static int VAL_0 = 1;
|
||||
}
|
||||
|
||||
/** Annotation fields should be skipped */
|
||||
@interface B {
|
||||
String name() default "";
|
||||
int version() default 0;
|
||||
public static int VAL_1 = 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue