1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter.naming;
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.checkstyle.suppressionxpathfilter.AbstractXpathTestSupport;
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
29 import com.puppycrawl.tools.checkstyle.checks.naming.GoogleMethodNameCheck;
30
31 public class XpathRegressionGoogleMethodNameTest extends AbstractXpathTestSupport {
32
33 private static final Class<GoogleMethodNameCheck> CLASS = GoogleMethodNameCheck.class;
34
35 @Override
36 protected String getCheckName() {
37 return CLASS.getSimpleName();
38 }
39
40 @Override
41 public String getPackageLocation() {
42 return "org/checkstyle/suppressionxpathfilter/naming/googlemethodname";
43 }
44
45 @Test
46 public void testRegularMethodName() throws Exception {
47 final File fileToProcess = new File(
48 getPath("InputXpathGoogleMethodName.java"));
49
50 final DefaultConfiguration moduleConfig = createModuleConfig(CLASS);
51
52 final String[] expectedViolation = {
53 "5:10: " + getCheckMessage(CLASS, GoogleMethodNameCheck.MSG_KEY_FORMAT_REGULAR,
54 "Foo"),
55 };
56
57 final List<String> expectedXpathQueries = List.of(
58 "/COMPILATION_UNIT/CLASS_DEF"
59 + "[./IDENT[@text='InputXpathGoogleMethodName']]"
60 + "/OBJBLOCK/METHOD_DEF/IDENT[@text='Foo']"
61 );
62
63 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
64 }
65
66 @Test
67 public void testInsideInterface() throws Exception {
68 final File fileToProcess = new File(
69 getPath("InputXpathGoogleMethodNameInterface.java"));
70
71 final DefaultConfiguration moduleConfig = createModuleConfig(CLASS);
72
73 final String[] expectedViolation = {
74 "8:10: " + getCheckMessage(CLASS, GoogleMethodNameCheck.MSG_KEY_UNDERSCORE_TEST,
75 "test_1"),
76 };
77
78 final List<String> expectedXpathQueries = List.of(
79 "/COMPILATION_UNIT/INTERFACE_DEF"
80 + "[./IDENT[@text='InputXpathGoogleMethodNameInterface']]"
81 + "/OBJBLOCK/METHOD_DEF/IDENT[@text='test_1']"
82 );
83
84 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
85 }
86
87 @Test
88 public void testInsideRecord() throws Exception {
89 final File fileToProcess = new File(
90 getPath("InputXpathGoogleMethodNameRecord.java"));
91
92 final DefaultConfiguration moduleConfig = createModuleConfig(CLASS);
93
94 final String[] expectedViolation = {
95 "5:10: " + getCheckMessage(CLASS, GoogleMethodNameCheck.MSG_KEY_FORMAT_REGULAR,
96 "f"),
97 };
98
99 final List<String> expectedXpathQueries = List.of(
100 "/COMPILATION_UNIT/RECORD_DEF"
101 + "[./IDENT[@text='InputXpathGoogleMethodNameRecord']]"
102 + "/OBJBLOCK/METHOD_DEF/IDENT[@text='f']"
103 );
104
105 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
106 }
107
108 }