Skip to content

Commit

Permalink
Issue checkstyle#14715: Enforced new naming convention in IT area 12
Browse files Browse the repository at this point in the history
  • Loading branch information
MANISH-K-07 authored and rnveach committed Apr 13, 2024
1 parent a11afaa commit 86195e0
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ protected String getCheckName() {
}

@Test
public void testDefault() throws Exception {
public void testDefaultMax() throws Exception {
final File fileToProcess = new File(getPath(
"SuppressionXpathRegressionLambdaBodyLength1.java"));
"InputXpathLambdaBodyLengthDefaultMax.java"));
final DefaultConfiguration moduleConfig = createModuleConfig(CLASS);
final String[] expectedViolation = {
"7:48: " + getCheckMessage(CLASS, LambdaBodyLengthCheck.MSG_KEY, 11, 10),
};

final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLambdaBodyLength1']]"
+ "[./IDENT[@text='InputXpathLambdaBodyLengthDefaultMax']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test']]/SLIST"
+ "/VARIABLE_DEF[./IDENT[@text='trimmer']]/ASSIGN/LAMBDA");

runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
}

@Test
public void testMaxIsNotDefault() throws Exception {
public void testCustomMax() throws Exception {
final File fileToProcess = new File(getPath(
"SuppressionXpathRegressionLambdaBodyLength2.java"));
"InputXpathLambdaBodyLengthCustomMax.java"));
final DefaultConfiguration moduleConfig = createModuleConfig(CLASS);
moduleConfig.addProperty("max", "5");
final String[] expectedViolation = {
Expand All @@ -69,7 +69,7 @@ public void testMaxIsNotDefault() throws Exception {

final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLambdaBodyLength2']]"
+ "[./IDENT[@text='InputXpathLambdaBodyLengthCustomMax']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test']]/SLIST"
+ "/VARIABLE_DEF[./IDENT[@text='r']]/ASSIGN/LAMBDA");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ protected String getCheckName() {
}

@Test
public void testOne() throws Exception {
public void testDefault() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionLambdaParameterName1.java"));
new File(getPath("InputXpathLambdaParameterNameDefault.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(LambdaParameterNameCheck.class);
Expand All @@ -55,7 +55,7 @@ public void testOne() throws Exception {

final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLambdaParameterName1']]"
+ "[./IDENT[@text='InputXpathLambdaParameterNameDefault']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test']]/SLIST/VARIABLE_DEF["
+ "./IDENT[@text='trimmer']]/ASSIGN/LAMBDA/IDENT[@text='S']"
);
Expand All @@ -65,9 +65,9 @@ public void testOne() throws Exception {
}

@Test
public void testTwo() throws Exception {
public void testNonDefaultPattern() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionLambdaParameterName2.java"));
new File(getPath("InputXpathLambdaParameterNameNonDefaultPattern.java"));

final String nonDefaultPattern = "^_[a-zA-Z0-9]*$";

Expand All @@ -82,30 +82,30 @@ public void testTwo() throws Exception {

final List<String> expectedXpathQueries = Arrays.asList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLambdaParameterName2']]"
+ "[./IDENT[@text='InputXpathLambdaParameterNameNonDefaultPattern']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test']]/SLIST/"
+ "VARIABLE_DEF[./IDENT[@text='trimmer']]/ASSIGN/LAMBDA/PARAMETERS",

"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLambdaParameterName2']]"
+ "[./IDENT[@text='InputXpathLambdaParameterNameNonDefaultPattern']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test']]/SLIST/"
+ "VARIABLE_DEF[./IDENT[@text='trimmer']]/ASSIGN/LAMBDA/PARAMETERS"
+ "/PARAMETER_DEF[./IDENT[@text='s']]",

"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLambdaParameterName2']]"
+ "[./IDENT[@text='InputXpathLambdaParameterNameNonDefaultPattern']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test']]/SLIST"
+ "/VARIABLE_DEF[./IDENT[@text='trimmer']]/ASSIGN/LAMBDA/PARAMETERS"
+ "/PARAMETER_DEF[./IDENT[@text='s']]/MODIFIERS",

"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLambdaParameterName2']]"
+ "[./IDENT[@text='InputXpathLambdaParameterNameNonDefaultPattern']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test']]/SLIST/"
+ "VARIABLE_DEF[./IDENT[@text='trimmer']]/ASSIGN/LAMBDA/PARAMETERS"
+ "/PARAMETER_DEF[./IDENT[@text='s']]/TYPE",

"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLambdaParameterName2']]"
+ "[./IDENT[@text='InputXpathLambdaParameterNameNonDefaultPattern']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test']]/SLIST/"
+ "VARIABLE_DEF[./IDENT[@text='trimmer']]/ASSIGN/LAMBDA/PARAMETERS"
+ "/PARAMETER_DEF/IDENT[@text='s']"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected String getCheckName() {
@Test
public void testOne() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionLeftCurlyOne.java"));
new File(getPath("InputXpathLeftCurlyOne.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(LeftCurlyCheck.class);
Expand All @@ -54,9 +54,9 @@ public void testOne() throws Exception {

final List<String> expectedXpathQueries = Arrays.asList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLeftCurlyOne']]/OBJBLOCK",
+ "[./IDENT[@text='InputXpathLeftCurlyOne']]/OBJBLOCK",
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLeftCurlyOne']]/OBJBLOCK/LCURLY"
+ "[./IDENT[@text='InputXpathLeftCurlyOne']]/OBJBLOCK/LCURLY"
);

runVerifications(moduleConfig, fileToProcess, expectedViolation,
Expand All @@ -66,22 +66,22 @@ public void testOne() throws Exception {
@Test
public void testTwo() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionLeftCurlyTwo.java"));
new File(getPath("InputXpathLeftCurlyTwo.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(LeftCurlyCheck.class);
moduleConfig.addProperty("option", LeftCurlyOption.NL.toString());

final String[] expectedViolation = {
"3:53: " + getCheckMessage(LeftCurlyCheck.class,
LeftCurlyCheck.MSG_KEY_LINE_NEW, "{", 53),
"3:37: " + getCheckMessage(LeftCurlyCheck.class,
LeftCurlyCheck.MSG_KEY_LINE_NEW, "{", 37),
};

final List<String> expectedXpathQueries = Arrays.asList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLeftCurlyTwo']]/OBJBLOCK",
+ "[./IDENT[@text='InputXpathLeftCurlyTwo']]/OBJBLOCK",
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLeftCurlyTwo']]/OBJBLOCK/LCURLY"
+ "[./IDENT[@text='InputXpathLeftCurlyTwo']]/OBJBLOCK/LCURLY"
);

runVerifications(moduleConfig, fileToProcess, expectedViolation,
Expand All @@ -91,7 +91,7 @@ public void testTwo() throws Exception {
@Test
public void testThree() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionLeftCurlyThree.java"));
new File(getPath("InputXpathLeftCurlyThree.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(LeftCurlyCheck.class);
Expand All @@ -103,7 +103,7 @@ public void testThree() throws Exception {

final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionLeftCurlyThree']]/OBJBLOCK"
+ "[./IDENT[@text='InputXpathLeftCurlyThree']]/OBJBLOCK"
+ "/METHOD_DEF[./IDENT[@text='sample']]/SLIST/LITERAL_IF/SLIST"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected String getCheckName() {
@Test
public void testResource() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionLocalFinalVariableNameResource.java"));
new File(getPath("InputXpathLocalFinalVariableNameResource.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(LocalFinalVariableNameCheck.class);
Expand All @@ -56,7 +56,7 @@ public void testResource() throws Exception {

final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT/CLASS_DEF[./IDENT["
+ "@text='SuppressionXpathRegressionLocalFinalVariableNameResource']]"
+ "@text='InputXpathLocalFinalVariableNameResource']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='MyMethod']]/SLIST/LITERAL_TRY"
+ "/RESOURCE_SPECIFICATION/RESOURCES/RESOURCE/IDENT[@text='scanner']"
);
Expand All @@ -67,7 +67,7 @@ public void testResource() throws Exception {
@Test
public void testVariable() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionLocalFinalVariableNameVar.java"));
new File(getPath("InputXpathLocalFinalVariableNameVar.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(LocalFinalVariableNameCheck.class);
Expand All @@ -80,7 +80,7 @@ public void testVariable() throws Exception {

final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT/CLASS_DEF[./IDENT["
+ "@text='SuppressionXpathRegressionLocalFinalVariableNameVar']]"
+ "@text='InputXpathLocalFinalVariableNameVar']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='MyMethod']]/SLIST/VARIABLE_DEF"
+ "/IDENT[@text='VAR1']"
);
Expand All @@ -91,7 +91,7 @@ public void testVariable() throws Exception {
@Test
public void testInnerClass() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionLocalFinalVariableNameInner.java"));
new File(getPath("InputXpathLocalFinalVariableNameInner.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(LocalFinalVariableNameCheck.class);
Expand All @@ -104,7 +104,7 @@ public void testInnerClass() throws Exception {

final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT/CLASS_DEF[./IDENT["
+ "@text='SuppressionXpathRegressionLocalFinalVariableNameInner']]"
+ "@text='InputXpathLocalFinalVariableNameInner']]"
+ "/OBJBLOCK/CLASS_DEF[./IDENT[@text='InnerClass']]/OBJBLOCK"
+ "/METHOD_DEF[./IDENT[@text='MyMethod']]/SLIST/VARIABLE_DEF"
+ "/IDENT[@text='VAR1']"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected String getCheckName() {
@Test
public void testVariable() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionMagicNumberVariable.java"));
new File(getPath("InputXpathMagicNumberVariable.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(MagicNumberCheck.class);
Expand All @@ -49,11 +49,11 @@ public void testVariable() throws Exception {

final List<String> expectedXpathQueries = Arrays.asList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionMagicNumberVariable']]"
+ "[./IDENT[@text='InputXpathMagicNumberVariable']]"
+ "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='d']]"
+ "/ASSIGN/EXPR[./NUM_INT[@text='5']]",
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionMagicNumberVariable']]"
+ "[./IDENT[@text='InputXpathMagicNumberVariable']]"
+ "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='d']]"
+ "/ASSIGN/EXPR/NUM_INT[@text='5']"
);
Expand All @@ -65,7 +65,7 @@ public void testVariable() throws Exception {
@Test
public void testMethodDef() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionMagicNumberMethodDef.java"));
new File(getPath("InputXpathMagicNumberMethodDef.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(MagicNumberCheck.class);
Expand All @@ -76,12 +76,12 @@ public void testMethodDef() throws Exception {

final List<String> expectedXpathQueries = Arrays.asList(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionMagicNumberMethodDef']]"
+ "[./IDENT[@text='InputXpathMagicNumberMethodDef']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='methodWithMagicNumber']]"
+ "/SLIST/VARIABLE_DEF[./IDENT[@text='x']]/ASSIGN/EXPR[./"
+ "NUM_INT[@text='20']]",
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionMagicNumberMethodDef']]"
+ "[./IDENT[@text='InputXpathMagicNumberMethodDef']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='methodWithMagicNumber']]"
+ "/SLIST/VARIABLE_DEF[./IDENT[@text='x']]/ASSIGN/EXPR/NU"
+ "M_INT[@text='20']"
Expand All @@ -93,7 +93,7 @@ public void testMethodDef() throws Exception {
@Test
public void testAnotherVariable() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionMagicNumberAnotherVariable.java"));
new File(getPath("InputXpathMagicNumberAnotherVariable.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(MagicNumberCheck.class);
Expand All @@ -104,7 +104,7 @@ public void testAnotherVariable() throws Exception {

final List<String> expectedXpathQueries = List.of(
"/COMPILATION_UNIT/CLASS_DEF"
+ "[./IDENT[@text='SuppressionXpathRegressionMagicNumberAnotherVariable']]"
+ "[./IDENT[@text='InputXpathMagicNumberAnotherVariable']]"
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='performOperation']]"
+ "/SLIST/LITERAL_TRY/LITERAL_CATCH/SLIST/LITERAL_IF"
+ "/LITERAL_ELSE/SLIST/EXPR/ASSIGN"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ protected String getCheckName() {
}

@Test
public void test1() throws Exception {
public void testDefault() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionMemberName1.java"));
new File(getPath("InputXpathMemberNameDefault.java"));

final String pattern = "^[a-z][a-zA-Z0-9]*$";
final DefaultConfiguration moduleConfig =
Expand All @@ -55,17 +55,17 @@ public void test1() throws Exception {
final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT"
+ "/CLASS_DEF[./IDENT[@text"
+ "='SuppressionXpathRegressionMemberName1']]"
+ "='InputXpathMemberNameDefault']]"
+ "/OBJBLOCK/VARIABLE_DEF/IDENT[@text='NUM2']"
);
runVerifications(moduleConfig, fileToProcess, expectedViolation,
expectedXpathQueries);
}

@Test
public void test2() throws Exception {
public void testIgnoreProtected() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionMemberName2.java"));
new File(getPath("InputXpathMemberNameIgnoreProtected.java"));

final String pattern = "^m[A-Z][a-zA-Z0-9]*$";
final DefaultConfiguration moduleConfig =
Expand All @@ -82,7 +82,7 @@ public void test2() throws Exception {
final List<String> expectedXpathQueries = Collections.singletonList(
"/COMPILATION_UNIT"
+ "/CLASS_DEF[./IDENT[@text"
+ "='SuppressionXpathRegressionMemberName2']]"
+ "='InputXpathMemberNameIgnoreProtected']]"
+ "/OBJBLOCK/CLASS_DEF[./IDENT[@text='Inner']]"
+ "/OBJBLOCK/VARIABLE_DEF/IDENT[@text='NUM1']"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.Function;

public class SuppressionXpathRegressionLambdaBodyLength2 {
public class InputXpathLambdaBodyLengthCustomMax {
void test() {
Runnable r = () -> { // warn
method(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.Function;

public class SuppressionXpathRegressionLambdaBodyLength1 {
public class InputXpathLambdaBodyLengthDefaultMax {
void test() {
Function<String, String> trimmer = (s) -> // warn
s.trim()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.Function;

public class SuppressionXpathRegressionLambdaParameterName1 {
public class InputXpathLambdaParameterNameDefault {
void test() {
Function<String, String> trimmer = S -> S.trim(); // warn
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.Function;

public class SuppressionXpathRegressionLambdaParameterName2 {
public class InputXpathLambdaParameterNameNonDefaultPattern {
void test() {
Function<String, String> trimmer = (s) -> s.trim(); // warn
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.checkstyle.suppressionxpathfilter.leftcurly;

public class SuppressionXpathRegressionLeftCurlyOne
public class InputXpathLeftCurlyOne
{ //warn
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.checkstyle.suppressionxpathfilter.leftcurly;

public class SuppressionXpathRegressionLeftCurlyThree {
public class InputXpathLeftCurlyThree {
public void sample(boolean flag) {
if (flag) { String.CASE_INSENSITIVE_ORDER.equals("it is ok."); } //warn
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.checkstyle.suppressionxpathfilter.leftcurly;

public class InputXpathLeftCurlyTwo { //warn
}

This file was deleted.

Loading

0 comments on commit 86195e0

Please sign in to comment.