1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.checks.whitespace;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_FOLLOWED;
24 import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_NOT_FOLLOWED;
25 import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_NOT_PRECEDED;
26 import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_PRECEDED;
27
28 import org.junit.jupiter.api.Test;
29
30 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
31 import com.puppycrawl.tools.checkstyle.DetailAstImpl;
32 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
33 import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
34 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
35 import com.puppycrawl.tools.checkstyle.utils.TokenUtil;
36
37 public class ParenPadCheckTest
38 extends AbstractModuleTestSupport {
39
40 @Override
41 public String getPackageLocation() {
42 return "com/puppycrawl/tools/checkstyle/checks/whitespace/parenpad";
43 }
44
45 @Test
46 public void testDefault()
47 throws Exception {
48 final String[] expected = {
49 "65:11: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
50 "65:37: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
51 "84:12: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
52 "84:19: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
53 "245:28: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
54 "254:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
55 "254:31: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
56 "293:17: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
57 "293:24: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
58 };
59 verifyWithInlineConfigParser(
60 getPath("InputParenPadWhitespace.java"), expected);
61 }
62
63 @Test
64 public void testSpace()
65 throws Exception {
66 final String[] expected = {
67 "36:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
68 "36:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
69 "47:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
70 "47:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
71 "54:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
72 "54:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
73 "92:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
74 "92:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
75 "116:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
76 "116:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
77 "120:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
78 "120:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
79 "175:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
80 "175:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
81 "181:15: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
82 "181:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
83 "191:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
84 "191:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
85 "196:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
86 "199:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
87 "212:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
88 "212:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
89 "262:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
90 "272:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
91 "272:39: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
92 "292:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
93 "292:93: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
94 "315:25: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
95 "315:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
96 "320:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
97 "320:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
98 "324:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
99 "324:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
100 "338:54: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
101 "338:70: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
102 };
103 verifyWithInlineConfigParser(
104 getPath("InputParenPadWhitespace2.java"), expected);
105 }
106
107 @Test
108 public void testDefaultForIterator()
109 throws Exception {
110 final String[] expected = {
111 "24:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
112 "27:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
113 "47:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
114 "47:37: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
115 "53:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
116 "58:28: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
117 "61:27: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
118 };
119 verifyWithInlineConfigParser(
120 getPath("InputParenPadForWhitespace.java"), expected);
121 }
122
123 @Test
124 public void testSpaceEmptyForIterator()
125 throws Exception {
126 final String[] expected = {
127 "18:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
128 "18:35: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
129 "24:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
130 "24:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
131 "30:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
132 "33:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
133 "36:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
134 "40:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
135 "45:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
136 };
137 verifyWithInlineConfigParser(
138 getPath("InputParenPadForWhitespace2.java"), expected);
139 }
140
141 @Test
142 public void test1322879() throws Exception {
143 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
144 verifyWithInlineConfigParser(
145 getPath("InputParenPadWithSpace.java"),
146 expected);
147 }
148
149 @Test
150 public void testTrimOptionProperty() throws Exception {
151 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
152 verifyWithInlineConfigParser(
153 getPath("InputParenPadToCheckTrimFunctionInOptionProperty.java"), expected);
154 }
155
156 @Test
157 public void testNospaceWithComplexInput() throws Exception {
158 final String[] expected = {
159 "55:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
160 "55:28: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
161 "59:17: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
162 "62:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
163 "63:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
164 "63:20: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
165 "69:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
166 "70:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
167 "71:17: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
168 "71:51: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
169 "71:53: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
170 "78:25: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
171 "79:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
172 "80:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
173 "81:25: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
174 "81:50: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
175 "81:56: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
176 "86:28: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
177 "87:42: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
178 "88:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
179 "90:42: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
180 "103:27: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
181 "103:29: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
182 "107:20: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
183 "110:34: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
184 "111:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
185 "111:20: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
186 "117:30: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
187 "118:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
188 "119:50: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
189 "119:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
190 "119:54: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
191 "125:39: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
192 "126:33: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
193 "127:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
194 "128:31: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
195 "129:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
196 "129:63: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
197 "129:70: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
198 "134:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
199 "135:48: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
200 "136:43: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
201 "138:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
202 "151:16: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
203 "152:22: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
204 "152:24: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
205 "152:32: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
206 "157:25: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
207 "157:27: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
208 "157:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
209 "157:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
210 "163:25: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
211 "163:27: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
212 "163:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
213 "163:54: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
214 "163:56: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
215 "173:16: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
216 "173:23: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
217 "180:29: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
218 "180:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
219 "186:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
220 "186:23: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
221 "193:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
222 "193:20: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
223 "205:9: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
224 "205:21: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
225 "214:32: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
226 "214:47: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
227 "225:33: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
228 "226:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
229 "227:35: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
230 "227:47: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
231 "234:25: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
232 "234:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
233 "238:12: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
234 "238:28: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
235 "238:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
236 "238:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
237 "246:31: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
238 "246:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
239 "246:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
240 "246:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
241 "254:40: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
242 "255:24: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
243 "255:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
244 "264:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
245 "265:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
246 "266:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
247 "266:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
248 "279:16: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
249 "279:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
250 "283:19: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
251 "283:39: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
252 "290:29: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
253 "290:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
254 "294:12: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
255 "294:39: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
256 "298:22: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
257 "298:40: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
258 "307:80: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
259 "307:84: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
260 "311:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
261 "312:24: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
262 "313:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
263 "313:25: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
264 "319:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
265 "319:23: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
266 "319:31: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
267 "324:17: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
268 "324:47: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
269 "330:36: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
270 "330:73: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
271 "330:81: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
272 "330:83: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
273 "336:36: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
274 "338:48: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
275 "338:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
276 "338:54: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
277 "347:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
278 "347:20: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
279 "352:21: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
280 };
281 verifyWithInlineConfigParser(
282 getPath("InputParenPadLeftRightAndNoSpace1.java"), expected);
283 }
284
285 @Test
286 public void testConfigureTokens() throws Exception {
287 final String[] expected = {
288 "98:39: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
289 "121:22: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
290 "123:54: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
291 "154:32: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
292 "154:47: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
293 "165:33: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
294 "166:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
295 "167:35: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
296 "167:47: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
297 "178:31: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
298 "178:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
299 "178:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
300 "178:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
301 "221:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
302 "222:24: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
303 "223:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
304 "223:25: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
305 "229:31: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
306 "233:36: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
307 "233:73: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
308 "233:81: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
309 "233:83: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
310 "239:36: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
311 "241:48: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
312 "241:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
313 "241:54: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
314 };
315 verifyWithInlineConfigParser(
316 getPath("InputParenPadLeftRightAndNoSpace2.java"), expected);
317 }
318
319 @Test
320 public void testInvalidOption() throws Exception {
321
322 try {
323 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
324
325 verifyWithInlineConfigParser(
326 getPath("InputParenPadLeftRightAndNoSpace3.java"), expected);
327 assertWithMessage("exception expected").fail();
328 }
329 catch (CheckstyleException exc) {
330 assertWithMessage("Invalid exception message")
331 .that(exc.getMessage())
332 .isEqualTo("cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - "
333 + "cannot initialize module com.puppycrawl.tools.checkstyle.checks."
334 + "whitespace.ParenPadCheck");
335 }
336 }
337
338 @Test
339 public void testLambdaAssignment() throws Exception {
340 final String[] expected = {
341 "20:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
342 "20:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
343 "25:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
344 "28:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
345 "31:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
346 "31:50: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
347 "36:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
348 "36:57: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
349 "41:61: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
350 "41:63: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
351 "47:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
352 "47:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
353 };
354 verifyWithInlineConfigParser(
355 getPath("InputParenPadLambda.java"), expected);
356 }
357
358 @Test
359 public void testLambdaAssignmentWithSpace() throws Exception {
360 final String[] expected = {
361 "20:41: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
362 "20:43: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
363 "25:41: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
364 "28:44: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
365 "31:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
366 "31:49: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
367 "36:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
368 "36:56: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
369 "44:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
370 "44:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
371 };
372 verifyWithInlineConfigParser(
373 getPath("InputParenPadLambdaWithSpace.java"), expected);
374 }
375
376 @Test
377 public void testLambdaCheckDisabled() throws Exception {
378 final String[] expected = {
379 "27:61: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
380 "27:63: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
381 "33:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
382 "33:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
383 };
384 verifyWithInlineConfigParser(
385 getPath("InputParenPadWithDisabledLambda.java"), expected);
386 }
387
388 @Test
389 public void testLambdaCheckDisabledWithSpace() throws Exception {
390 final String[] expected = {
391 "30:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
392 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
393 };
394 verifyWithInlineConfigParser(
395 getPath("InputParenPadWithSpaceAndDisabledLambda.java"), expected);
396 }
397
398 @Test
399 public void testLambdaCheckOnly() throws Exception {
400 final String[] expected = {
401 "17:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
402 "17:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
403 "22:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
404 "25:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
405 "28:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
406 "28:50: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
407 "33:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
408 "33:57: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
409 };
410 verifyWithInlineConfigParser(
411 getPath("InputParenPadLambdaOnly.java"), expected);
412 }
413
414 @Test
415 public void testLambdaCheckOnlyWithSpace() throws Exception {
416 final String[] expected = {
417 "17:41: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
418 "17:43: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
419 "22:41: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
420 "25:44: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
421 "28:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
422 "28:49: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
423 "33:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
424 "33:56: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
425 };
426 verifyWithInlineConfigParser(
427 getPath("InputParenPadLambdaOnlyWithSpace.java"), expected);
428 }
429
430 @Test
431 public void testLambdaCheckOnlyWithSpace1() throws Exception {
432 final String[] expected = {
433 "16:2: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
434 };
435 verifyWithInlineConfigParser(
436 getPath("InputParenPadStartOfTheLine.java"), expected);
437 }
438
439 @Test
440 public void testTryWithResources() throws Exception {
441 final String[] expected = {
442 "20:37: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
443 "21:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
444 "23:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
445 };
446 verifyWithInlineConfigParser(
447 getPath("InputParenPadTryWithResources.java"), expected);
448 }
449
450 @Test
451 public void testTryWithResourcesAndSuppression() throws Exception {
452 final String[] expectedFiltered = CommonUtil.EMPTY_STRING_ARRAY;
453 final String[] expectedUnfiltered = {
454 "23:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
455 };
456 verifyFilterWithInlineConfigParser(
457 getPath("InputParenPadTryWithResourcesAndSuppression.java"),
458 expectedUnfiltered,
459 expectedFiltered);
460 }
461
462 @Test
463 public void testNoStackoverflowError()
464 throws Exception {
465 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
466 verifyWithLimitedResources(getPath("InputParenPadNoStackoverflowError.java"),
467 expected);
468 }
469
470 @Test
471 public void testParenPadCheckRecords() throws Exception {
472
473 final String[] expected = {
474 "20:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
475 "20:23: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
476 "25:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
477 "25:26: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
478 "31:16: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
479 "37:16: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
480 "40:31: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
481 "46:19: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
482 "57:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
483 "58:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
484 "58:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
485 "62:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
486 "63:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
487 };
488 verifyWithInlineConfigParser(
489 getPath("InputParenPadCheckRecords.java"), expected);
490 }
491
492 @Test
493 public void testParenPadCheckRecordsWithSpace() throws Exception {
494
495 final String[] expected = {
496 "25:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
497 "31:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
498 "34:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
499 "35:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
500 "35:25: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
501 "43:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
502 "45:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
503 "45:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
504 "57:31: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
505 "59:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
506 "60:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
507 "62:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
508 };
509 verifyWithInlineConfigParser(
510 getPath("InputParenPadCheckRecordsSpace.java"), expected);
511 }
512
513 @Test
514 public void testParenPadCheckEmoji() throws Exception {
515
516 final String[] expected = {
517 "25:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
518 "29:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
519 "33:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
520 "37:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
521 "43:9: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
522 "43:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
523 };
524 verifyWithInlineConfigParser(
525 getPath("InputParenPadCheckEmoji.java"), expected);
526 }
527
528 @Test
529 public void testParenPadForSynchronized() throws Exception {
530
531 final String[] expected = {
532 "18:29: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
533 };
534 verifyWithInlineConfigParser(
535 getPath("InputParenPadForSynchronized.java"), expected);
536 }
537
538 @Test
539 public void testParenPadForEnum() throws Exception {
540
541 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
542 verifyWithInlineConfigParser(
543 getPath("InputParenPadForEnum.java"), expected);
544 }
545
546
547
548
549
550
551
552
553
554
555 @Test
556 public void testIsAcceptableToken() throws Exception {
557 final ParenPadCheck check = new ParenPadCheck();
558 final DetailAstImpl ast = new DetailAstImpl();
559 final String message = "Expected that all acceptable tokens will pass isAcceptableToken "
560 + "method, but some token don't: ";
561
562 for (int token : check.getAcceptableTokens()) {
563 ast.setType(token);
564 assertWithMessage("%s%s", message, TokenUtil.getTokenName(token))
565 .that(TestUtil.invokeMethod(check, "isAcceptableToken", Boolean.class, ast))
566 .isTrue();
567 }
568 }
569
570 @Test
571 public void testParenPadWithWhenExpression() throws Exception {
572 final String[] expected = {
573 "21:38: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
574 "25:33: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
575 "27:41: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
576 "29:43: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
577 "29:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
578 };
579 verifyWithInlineConfigParser(
580 getPath("InputParenPadCheckWhenExpression.java"), expected);
581 }
582
583 @Test
584 public void testParenPadForRecordPattern() throws Exception {
585 final String[] expected = {
586 "14:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
587 "16:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
588 "16:60: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
589 "22:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
590 "22:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
591 "26:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
592 "26:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
593 "26:73: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
594 "31:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
595 "31:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
596 "31:62: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
597 "31:74: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
598 "42:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
599 "44:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
600 "44:38: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
601 "52:30: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
602 "52:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
603 "56:36: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
604 "56:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
605 "56:63: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
606 "61:30: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
607 "61:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
608 "61:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
609 "61:64: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
610 };
611 verifyWithInlineConfigParser(
612 getPath("InputParenPadForRecordPattern.java"), expected);
613 }
614
615 @Test
616 public void testParenPadForRecordPatternWithSpaceOption() throws Exception {
617 final String[] expected = {
618 "14:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
619 "14:58: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
620 "18:59: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
621 "23:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
622 "23:46: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
623 "23:59: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
624 "23:70: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
625 "29:61: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
626 "29:72: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
627 "33:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
628 "41:30: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
629 "41:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
630 "45:37: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
631 };
632 verifyWithInlineConfigParser(
633 getPath("InputParenPadForRecordPatternWithSpaceOption.java"),
634 expected);
635 }
636
637 }