-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #6207: Add Xpath regression test for MethodTypeParameterName
- Loading branch information
Showing
5 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
...ava/org/checkstyle/suppressionxpathfilter/XpathRegressionMethodTypeParameterNameTest.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,126 @@ | ||
/////////////////////////////////////////////////////////////////////////////////////////////// | ||
// 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.naming.MethodTypeParameterNameCheck.MSG_INVALID_PATTERN; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration; | ||
import com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterNameCheck; | ||
|
||
public class XpathRegressionMethodTypeParameterNameTest extends AbstractXpathTestSupport { | ||
|
||
private final String checkName = MethodTypeParameterNameCheck.class.getSimpleName(); | ||
|
||
@Override | ||
protected String getCheckName() { | ||
return checkName; | ||
} | ||
|
||
@Test | ||
public void test1() throws Exception { | ||
final File fileToProcess = | ||
new File(getPath("SuppressionXpathRegressionMethodTypeParameterName1.java")); | ||
|
||
final DefaultConfiguration moduleConfig = | ||
createModuleConfig(MethodTypeParameterNameCheck.class); | ||
|
||
final String[] expectedViolation = { | ||
"4:11: " + getCheckMessage(MethodTypeParameterNameCheck.class, | ||
MSG_INVALID_PATTERN, "TT", "^[A-Z]$"), | ||
}; | ||
|
||
final List<String> expectedXpathQueries = Arrays.asList( | ||
"/COMPILATION_UNIT/CLASS_DEF[./" | ||
+ "IDENT[@text='SuppressionXpathRegressionMethodTypeParameterName1']]" | ||
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='foo']]/TYPE_PARAMETERS" | ||
+ "/TYPE_PARAMETER[./IDENT[@text='TT']]", "/COMPILATION_UNIT" | ||
+ "/CLASS_DEF[./IDENT[" | ||
+ "@text='SuppressionXpathRegressionMethodTypeParameterName1']]" | ||
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='foo']]" | ||
+ "/TYPE_PARAMETERS/TYPE_PARAMETER/IDENT[@text='TT']" | ||
); | ||
|
||
runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries); | ||
} | ||
|
||
@Test | ||
public void test2() throws Exception { | ||
final File fileToProcess = | ||
new File(getPath("SuppressionXpathRegressionMethodTypeParameterName2.java")); | ||
|
||
final DefaultConfiguration moduleConfig = | ||
createModuleConfig(MethodTypeParameterNameCheck.class); | ||
moduleConfig.addProperty("format", "^foo$"); | ||
|
||
final String[] expectedViolation = { | ||
"6:10: " + getCheckMessage(MethodTypeParameterNameCheck.class, | ||
MSG_INVALID_PATTERN, "fo_", "^foo$"), | ||
}; | ||
|
||
final List<String> expectedXpathQueries = Arrays.asList( | ||
"/COMPILATION_UNIT/CLASS_DEF[./IDENT[" | ||
+ "@text='SuppressionXpathRegressionMethodTypeParameterName2']]" | ||
+ "/OBJBLOCK/CLASS_DEF[./IDENT[@text='Junk']]/OBJBLOCK" | ||
+ "/METHOD_DEF[./IDENT[@text='foo']]/TYPE_PARAMETERS" | ||
+ "/TYPE_PARAMETER[./IDENT[@text='fo_']]", "/COMPILATION_UNIT" | ||
+ "/CLASS_DEF[./IDENT[@text=" | ||
+ "'SuppressionXpathRegressionMethodTypeParameterName2']]" | ||
+ "/OBJBLOCK/CLASS_DEF[./IDENT[@text='Junk']]/OBJBLOCK" | ||
+ "/METHOD_DEF[./IDENT[@text='foo']]/TYPE_PARAMETERS" | ||
+ "/TYPE_PARAMETER/IDENT[@text='fo_']" | ||
); | ||
|
||
runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries); | ||
} | ||
|
||
@Test | ||
public void test3() throws Exception { | ||
final File fileToProcess = | ||
new File(getPath("SuppressionXpathRegressionMethodTypeParameterName3.java")); | ||
|
||
final DefaultConfiguration moduleConfig = | ||
createModuleConfig(MethodTypeParameterNameCheck.class); | ||
moduleConfig.addProperty("format", "^[a-z]$"); | ||
|
||
final String[] expectedViolation = { | ||
"7:6: " + getCheckMessage(MethodTypeParameterNameCheck.class, | ||
MSG_INVALID_PATTERN, "a_a", "^[a-z]$"), | ||
}; | ||
|
||
final List<String> expectedXpathQueries = Arrays.asList( | ||
"/COMPILATION_UNIT/CLASS_DEF[./IDENT" | ||
+ "[@text='SuppressionXpathRegressionMethodTypeParameterName3']]" | ||
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='myMethod']]/TYPE_PARAMETERS" | ||
+ "/TYPE_PARAMETER[./IDENT[@text='a_a']]", "/COMPILATION_UNIT" | ||
+ "/CLASS_DEF[./IDENT[@text=" | ||
+ "'SuppressionXpathRegressionMethodTypeParameterName3']]" | ||
+ "/OBJBLOCK/METHOD_DEF[./IDENT[@text='myMethod']]" | ||
+ "/TYPE_PARAMETERS/TYPE_PARAMETER/IDENT[@text='a_a']" | ||
); | ||
|
||
runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...athfilter/methodtypeparametername/SuppressionXpathRegressionMethodTypeParameterName1.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,5 @@ | ||
package org.checkstyle.suppressionxpathfilter.methodtypeparametername; | ||
|
||
public class SuppressionXpathRegressionMethodTypeParameterName1{ | ||
public <TT> void foo() { } // warn | ||
} |
9 changes: 9 additions & 0 deletions
9
...athfilter/methodtypeparametername/SuppressionXpathRegressionMethodTypeParameterName2.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,9 @@ | ||
package org.checkstyle.suppressionxpathfilter.methodtypeparametername; | ||
|
||
public class SuppressionXpathRegressionMethodTypeParameterName2 <T>{ | ||
|
||
static class Junk <T> { | ||
<fo_ extends T> void foo() { // warn | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...athfilter/methodtypeparametername/SuppressionXpathRegressionMethodTypeParameterName3.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,9 @@ | ||
package org.checkstyle.suppressionxpathfilter.methodtypeparametername; | ||
|
||
import java.util.List; | ||
|
||
public class SuppressionXpathRegressionMethodTypeParameterName3<T> { | ||
|
||
<a_a> a_a myMethod(List<? super T> list) {return null;} // warn | ||
|
||
} |
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