View Javadoc
1   package com.google.checkstyle.test.chapter5naming.rule523methodnames;
2   
3   import org.junit.jupiter.api.BeforeAll;
4   import org.junit.jupiter.api.RepeatedTest;
5   import org.junit.jupiter.api.Test;
6   import org.junit.jupiter.params.ParameterizedTest;
7   import org.junit.jupiter.params.provider.ValueSource;
8   
9   /**
10   * Test input for MethodNameCheck specifically whether the method name equals the class name.
11   *
12   * @author Travis Schneeberger
13   */
14  public class InputMethodName {
15    void foo() {}
16  
17    void Foo() {} // violation 'Method name 'Foo' must match pattern'
18  
19    void fOo() {} // violation 'Method name 'fOo' must match pattern'
20  
21    void f0o() {}
22  
23    void f$o() {} // violation 'Method name 'f\$o' must match pattern'
24  
25    void f_oo() {} // violation 'Method name 'f_oo' must match pattern'
26  
27    void f() {} // violation 'Method name 'f' must match pattern'
28  
29    void fO() {} // violation 'Method name 'fO' must match pattern'
30  
31    @Test
32    void testing_foo() {
33      class LocalFoo {
34        void foo() {}
35  
36        // violation below 'Method name 'testing_foo' must match pattern'
37        void testing_foo() {}
38      }
39  
40      new Object() {
41        void foo() {}
42  
43        // violation below 'Method name 'testing_foo' must match pattern'
44        void testing_foo() {}
45      };
46    }
47  
48    void testing_foo(@FooTest String str) {
49      // violation above 'Method name 'testing_foo' must match pattern'
50      class LocalFoo {
51        void foo() {}
52  
53        // violation below 'Method name 'testing_foo' must match pattern'
54        void testing_foo() {}
55      }
56  
57      new Object() {
58        void foo() {}
59  
60        // violation below 'Method name 'testing_foo' must match pattern'
61        void testing_foo() {}
62      };
63    }
64  
65    @Test
66    void testing_Foo() {} // violation 'Method name 'testing_Foo' must match pattern'
67  
68    @Test
69    void testing_fOo() {} // violation 'Method name 'testing_fOo' must match pattern'
70  
71    @Test
72    void testingFoo() {}
73  
74    @Test
75    void testingFoo_foo() {}
76  
77    @Test
78    void testing_0123() {} // violation 'Method name 'testing_0123' must match pattern'
79  
80    @Test
81    void testing_0123_() {} // violation 'Method name 'testing_0123_' must match pattern'
82  
83    @Test
84    void testing__0123() {} // violation 'Method name 'testing__0123' must match pattern'
85  
86    @Test
87    void testing__0123_() {} // violation 'Method name 'testing__0123_' must match pattern'
88  
89    @Test
90    void testing__0123__() {} // violation 'Method name 'testing__0123__' must match pattern'
91  
92    @Test
93    void Testing_Foo() {} // violation 'Method name 'Testing_Foo' must match pattern'
94  
95    @Test
96    void t_esting() {} // violation 'Method name 't_esting' must match pattern'
97  
98    @Test
99    void _testing() {} // violation 'Method name '_testing' must match pattern'
100 
101   void Testing_Foo2() {} // violation 'Method name 'Testing_Foo2' must match pattern'
102 
103   @Test
104   void TestingFooBad() {} // violation 'Method name 'TestingFooBad' must match pattern'
105 
106   @Test
107   void testing_foo_() {} // violation 'Method name 'testing_foo_' must match pattern'
108 
109   @Test
110   void testing_Foo_() {} // violation 'Method name 'testing_Foo_' must match pattern'
111 
112   @Test
113   void testing__foo() {} // violation 'Method name 'testing__foo' must match pattern'
114 
115   @Test
116   void testing__Foo() {} // violation 'Method name 'testing__Foo' must match pattern'
117 
118   @Test
119   void testing__foo_() {} // violation 'Method name 'testing__foo_' must match pattern'
120 
121   @Test
122   void testing__Foo_() {} // violation 'Method name 'testing__Foo_' must match pattern'
123 
124   @ParameterizedTest
125   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
126   void testing_foo1(String str) {
127     class LocalFoo {
128       void foo() {}
129 
130       // violation below 'Method name 'testing_foo' must match pattern'
131       void testing_foo() {}
132     }
133 
134     new Object() {
135       void foo() {}
136 
137       // violation below 'Method name 'testing_foo' must match pattern'
138       void testing_foo() {}
139     };
140   }
141 
142   @ParameterizedTest
143   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
144   void testing_Foo1(String str) {} // violation 'Method name 'testing_Foo1' must match pattern'
145 
146   @ParameterizedTest
147   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
148   void testing_fOo1(String str) {} // violation 'Method name 'testing_fOo1' must match pattern'
149 
150   @ParameterizedTest
151   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
152   void testingFoo1(String str) {}
153 
154   @ParameterizedTest
155   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
156   void testingFoo_foo1(String str) {}
157 
158   @ParameterizedTest
159   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
160   void testing_01231(String str) {} // violation 'Method name 'testing_01231' must match pattern'
161 
162   @ParameterizedTest
163   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
164   void Testing_Foo1(String str) {} // violation 'Method name 'Testing_Foo1' must match pattern'
165 
166   @ParameterizedTest
167   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
168   void t_esting1(String str) {} // violation 'Method name 't_esting1' must match pattern'
169 
170   @ParameterizedTest
171   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
172   void _testing1(String str) {} // violation 'Method name '_testing1' must match pattern'
173 
174   @ParameterizedTest
175   @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
176   void TestingFooBad1(String str) {} // violation 'Method name 'TestingFooBad1' must match pattern'
177 
178   @RepeatedTest(2)
179   void testing_foo2() {}
180 
181   @RepeatedTest(2)
182   void testing_Foo2() {} // violation 'Method name 'testing_Foo2' must match pattern'
183 
184   @RepeatedTest(2)
185   void testing_fOo2() {} // violation 'Method name 'testing_fOo2' must match pattern'
186 
187   @RepeatedTest(2)
188   void testingFoo2() {}
189 
190   @RepeatedTest(2)
191   void testingFoo_foo2() {}
192 
193   @RepeatedTest(2)
194   void testing_01232() {} // violation 'Method name 'testing_01232' must match pattern'
195 
196   @RepeatedTest(2)
197   void Testing_Foo3() {} // violation 'Method name 'Testing_Foo3' must match pattern'
198 
199   @RepeatedTest(2)
200   void t_esting2() {} // violation 'Method name 't_esting2' must match pattern'
201 
202   @RepeatedTest(2)
203   void _testing2() {} // violation 'Method name '_testing2' must match pattern'
204 
205   @RepeatedTest(2)
206   void TestingFooBad2() {} // violation 'Method name 'TestingFooBad2' must match pattern'
207 
208   @BeforeAll
209   static void _testingFoooo() {} // violation 'Method name '_testingFoooo' must match pattern'
210 
211   @org.junit.jupiter.api.Test
212   void testing_fq() {}
213 
214   class InnerFoo {
215     void foo() {}
216 
217     void Foo() {} // violation 'Method name 'Foo' must match pattern'
218 
219     void fOo() {} // violation 'Method name 'fOo' must match pattern'
220 
221     void f0o() {}
222 
223     void f$o() {} // violation 'Method name 'f\$o' must match pattern'
224 
225     void f_oo() {} // violation 'Method name 'f_oo' must match pattern'
226 
227     void f() {} // violation 'Method name 'f' must match pattern'
228 
229     void fO() {} // violation 'Method name 'fO' must match pattern'
230 
231     void testing_foo() {} // violation 'Method name 'testing_foo' must match pattern'
232 
233     void testing_Foo() {} // violation 'Method name 'testing_Foo' must match pattern'
234 
235     void testing_fOo() {} // violation 'Method name 'testing_fOo' must match pattern'
236 
237     void testingFoo() {}
238 
239     void testingFoo_foo() {} // violation 'Method name 'testingFoo_foo' must match pattern'
240 
241     void testing_0123() {} // violation 'Method name 'testing_0123' must match pattern'
242 
243     void TestingFooBad() {} // violation 'Method name 'TestingFooBad' must match pattern'
244   }
245 
246   InnerFoo anon =
247       new InnerFoo() {
248         void foo() {}
249 
250         void Foo() {} // violation 'Method name 'Foo' must match pattern'
251 
252         void fOo() {} // violation 'Method name 'fOo' must match pattern'
253 
254         void f0o() {}
255 
256         void f$o() {} // violation 'Method name 'f\$o' must match pattern'
257 
258         void f_oo() {} // violation 'Method name 'f_oo' must match pattern'
259 
260         void f() {} // violation 'Method name 'f' must match pattern'
261 
262         void fO() {} // violation 'Method name 'fO' must match pattern'
263       };
264 
265   interface FooIn {
266     void foo();
267 
268     void Foo(); // violation 'Method name 'Foo' must match pattern'
269 
270     void fOo(); // violation 'Method name 'fOo' must match pattern'
271 
272     void f0o();
273 
274     void f$o(); // violation 'Method name 'f\$o' must match pattern'
275 
276     void f_oo(); // violation 'Method name 'f_oo' must match pattern'
277 
278     void f(); // violation 'Method name 'f' must match pattern'
279 
280     void fO(); // violation 'Method name 'fO' must match pattern'
281   }
282 
283   @interface FooTest {}
284 }