forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#6207: Add XPath IT Regression test for ParameterNumb…
…erCheck
- Loading branch information
Showing
5 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionParameterNumberTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/////////////////////////////////////////////////////////////////////////////////////////////// | ||
// checkstyle: Checks Java source code and other text files for adherence to a set of rules. | ||
// Copyright (C) 2001-2024 the original author or authors. | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
/////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
package org.checkstyle.suppressionxpathfilter; | ||
|
||
import static com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck.MSG_KEY; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration; | ||
import com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck; | ||
|
||
public class XpathRegressionParameterNumberTest extends AbstractXpathTestSupport { | ||
|
||
@Override | ||
protected String getCheckName() { | ||
return ParameterNumberCheck.class.getSimpleName(); | ||
} | ||
|
||
@Test | ||
public void testDefault() throws Exception { | ||
final File fileToProcess = | ||
new File(getPath("SuppressionXpathRegressionParameterNumberDefault.java")); | ||
|
||
final DefaultConfiguration moduleConfig = createModuleConfig(ParameterNumberCheck.class); | ||
|
||
final String[] expectedViolations = { | ||
"5:10: " + getCheckMessage(ParameterNumberCheck.class, MSG_KEY, 7, 11), | ||
}; | ||
|
||
final List<String> expectedXpathQueries = Collections.singletonList( | ||
"/COMPILATION_UNIT/CLASS_DEF" | ||
+ "[./IDENT[@text='SuppressionXpathRegressionParameterNumberDefault']]" | ||
+ "/OBJBLOCK/METHOD_DEF/IDENT[@text='myMethod']" | ||
); | ||
|
||
runVerifications(moduleConfig, fileToProcess, expectedViolations, expectedXpathQueries); | ||
|
||
} | ||
|
||
@Test | ||
public void testMethods() throws Exception { | ||
final File fileToProcess = | ||
new File(getPath("SuppressionXpathRegressionParameterNumberMethods.java")); | ||
|
||
final DefaultConfiguration moduleConfig = createModuleConfig(ParameterNumberCheck.class); | ||
moduleConfig.addProperty("max", "10"); | ||
moduleConfig.addProperty("tokens", "METHOD_DEF"); | ||
|
||
final String[] expectedViolations = { | ||
"7:10: " + getCheckMessage(ParameterNumberCheck.class, MSG_KEY, 10, 11), | ||
}; | ||
|
||
final List<String> expectedXpathQueries = Collections.singletonList( | ||
"/COMPILATION_UNIT/CLASS_DEF" | ||
+ "[./IDENT[@text='SuppressionXpathRegressionParameterNumberMethods']]" | ||
+ "/OBJBLOCK/METHOD_DEF/IDENT[@text='myMethod']" | ||
); | ||
|
||
runVerifications(moduleConfig, fileToProcess, expectedViolations, expectedXpathQueries); | ||
} | ||
|
||
@Test | ||
public void testIgnoreOverriddenMethods() throws Exception { | ||
final String filePath = | ||
getPath("SuppressionXpathRegressionParameterNumberIgnoreOverriddenMethods.java"); | ||
final File fileToProcess = new File(filePath); | ||
|
||
final DefaultConfiguration moduleConfig = createModuleConfig(ParameterNumberCheck.class); | ||
moduleConfig.addProperty("ignoreOverriddenMethods", "true"); | ||
|
||
final String[] expectedViolations = { | ||
"6:13: " + getCheckMessage(ParameterNumberCheck.class, MSG_KEY, 7, 8), | ||
}; | ||
|
||
final List<String> expectedXpathQueries = Collections.singletonList( | ||
"/COMPILATION_UNIT/CLASS_DEF[./IDENT" | ||
+ "[@text='SuppressionXpathRegressionParameterNumberIgnoreOverriddenMethods']]" | ||
+ "/OBJBLOCK/CTOR_DEF/IDENT" | ||
+ "[@text='SuppressionXpathRegressionParameterNumberIgnoreOverriddenMethods']" | ||
); | ||
|
||
runVerifications(moduleConfig, fileToProcess, expectedViolations, expectedXpathQueries); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...pressionxpathfilter/parameternumber/SuppressionXpathRegressionParameterNumberDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.checkstyle.suppressionxpathfilter.parameternumber; | ||
|
||
public class SuppressionXpathRegressionParameterNumberDefault { | ||
|
||
void myMethod(int a, int b, int c, int d, int e, int f, int g, int h, // warn | ||
int i, int j, int k) { | ||
} | ||
|
||
public SuppressionXpathRegressionParameterNumberDefault() { // ok | ||
} | ||
|
||
void myMethod2(int a, int b, int c, int d) { // ok | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ter/parameternumber/SuppressionXpathRegressionParameterNumberIgnoreOverriddenMethods.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.checkstyle.suppressionxpathfilter.parameternumber; | ||
|
||
public class SuppressionXpathRegressionParameterNumberIgnoreOverriddenMethods | ||
extends SuppressionXpathRegressionParameterNumberDefault { | ||
|
||
public SuppressionXpathRegressionParameterNumberIgnoreOverriddenMethods(int a, // warn | ||
int b, int c, int d, int e, int f, int g, int h) | ||
{ | ||
} | ||
@Override | ||
void myMethod(int a, int b, int c, int d, int e, int f, int g, int h, // ok | ||
int k, int l, int m) { | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...pressionxpathfilter/parameternumber/SuppressionXpathRegressionParameterNumberMethods.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.checkstyle.suppressionxpathfilter.parameternumber; | ||
|
||
public class SuppressionXpathRegressionParameterNumberMethods | ||
extends SuppressionXpathRegressionParameterNumberDefault { | ||
|
||
@Override | ||
void myMethod(int a, int b, int c, int d, int e, int f, int g, int h, // warn | ||
int k, int l, int m) { | ||
} | ||
public SuppressionXpathRegressionParameterNumberMethods(int a, int b, int c, // ok | ||
int d, int e, int f, int g, int h, int k, int l, int m) | ||
{ | ||
} | ||
void myMethod3(int a, int b, int c, int d, int e, int f, int g, int h) { // ok | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters