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 protected 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 + "Cannot set property 'option' to 'invalid_option'");
336 }
337 }
338
339 @Test
340 public void testLambdaAssignment() throws Exception {
341 final String[] expected = {
342 "20:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
343 "20:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
344 "25:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
345 "28:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
346 "31:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
347 "31:50: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
348 "36:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
349 "36:57: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
350 "41:61: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
351 "41:63: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
352 "47:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
353 "47:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
354 };
355 verifyWithInlineConfigParser(
356 getPath("InputParenPadLambda.java"), expected);
357 }
358
359 @Test
360 public void testLambdaAssignmentWithSpace() throws Exception {
361 final String[] expected = {
362 "20:41: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
363 "20:43: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
364 "25:41: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
365 "28:44: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
366 "31:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
367 "31:49: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
368 "36:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
369 "36:56: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
370 "44:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
371 "44:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
372 };
373 verifyWithInlineConfigParser(
374 getPath("InputParenPadLambdaWithSpace.java"), expected);
375 }
376
377 @Test
378 public void testLambdaCheckDisabled() throws Exception {
379 final String[] expected = {
380 "27:61: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
381 "27:63: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
382 "33:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
383 "33:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
384 };
385 verifyWithInlineConfigParser(
386 getPath("InputParenPadWithDisabledLambda.java"), expected);
387 }
388
389 @Test
390 public void testLambdaCheckDisabledWithSpace() throws Exception {
391 final String[] expected = {
392 "30:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
393 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
394 };
395 verifyWithInlineConfigParser(
396 getPath("InputParenPadWithSpaceAndDisabledLambda.java"), expected);
397 }
398
399 @Test
400 public void testLambdaCheckOnly() throws Exception {
401 final String[] expected = {
402 "17:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
403 "17:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
404 "22:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
405 "25:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
406 "28:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
407 "28:50: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
408 "33:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
409 "33:57: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
410 };
411 verifyWithInlineConfigParser(
412 getPath("InputParenPadLambdaOnly.java"), expected);
413 }
414
415 @Test
416 public void testLambdaCheckOnlyWithSpace() throws Exception {
417 final String[] expected = {
418 "17:41: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
419 "17:43: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
420 "22:41: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
421 "25:44: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
422 "28:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
423 "28:49: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
424 "33:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
425 "33:56: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
426 };
427 verifyWithInlineConfigParser(
428 getPath("InputParenPadLambdaOnlyWithSpace.java"), expected);
429 }
430
431 @Test
432 public void testLambdaCheckOnlyWithSpace1() throws Exception {
433 final String[] expected = {
434 "16:2: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
435 };
436 verifyWithInlineConfigParser(
437 getPath("InputParenPadStartOfTheLine.java"), expected);
438 }
439
440 @Test
441 public void testTryWithResources() throws Exception {
442 final String[] expected = {
443 "20:37: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
444 "21:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
445 "23:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
446 };
447 verifyWithInlineConfigParser(
448 getPath("InputParenPadTryWithResources.java"), expected);
449 }
450
451 @Test
452 public void testTryWithResourcesAndSuppression() throws Exception {
453 final String[] expectedFiltered = CommonUtil.EMPTY_STRING_ARRAY;
454 final String[] expectedUnfiltered = {
455 "23:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
456 };
457 verifyFilterWithInlineConfigParser(
458 getPath("InputParenPadTryWithResourcesAndSuppression.java"),
459 expectedUnfiltered,
460 expectedFiltered);
461 }
462
463 @Test
464 public void testNoStackoverflowError()
465 throws Exception {
466 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
467 verifyWithLimitedResources(getPath("InputParenPadNoStackoverflowError.java"),
468 expected);
469 }
470
471 @Test
472 public void testParenPadCheckRecords() throws Exception {
473
474 final String[] expected = {
475 "20:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
476 "20:23: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
477 "25:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
478 "25:26: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
479 "31:16: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
480 "37:16: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
481 "40:31: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
482 "46:19: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
483 "57:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
484 "58:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
485 "58:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
486 "62:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
487 "63:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
488 };
489 verifyWithInlineConfigParser(
490 getPath("InputParenPadCheckRecords.java"), expected);
491 }
492
493 @Test
494 public void testParenPadCheckRecordsWithSpace() throws Exception {
495
496 final String[] expected = {
497 "25:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
498 "31:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
499 "34:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
500 "35:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
501 "35:25: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
502 "43:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
503 "45:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
504 "45:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
505 "57:31: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
506 "59:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
507 "60:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
508 "62:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
509 };
510 verifyWithInlineConfigParser(
511 getPath("InputParenPadCheckRecordsSpace.java"), expected);
512 }
513
514 @Test
515 public void testParenPadCheckEmoji() throws Exception {
516
517 final String[] expected = {
518 "25:45: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
519 "29:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
520 "33:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
521 "37:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
522 "43:9: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
523 "43:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
524 };
525 verifyWithInlineConfigParser(
526 getPath("InputParenPadCheckEmoji.java"), expected);
527 }
528
529 @Test
530 public void testParenPadForSynchronized() throws Exception {
531
532 final String[] expected = {
533 "18:29: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
534 };
535 verifyWithInlineConfigParser(
536 getPath("InputParenPadForSynchronized.java"), expected);
537 }
538
539 @Test
540 public void testParenPadForEnum() throws Exception {
541
542 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
543 verifyWithInlineConfigParser(
544 getPath("InputParenPadForEnum.java"), expected);
545 }
546
547
548
549
550
551
552
553
554
555
556 @Test
557 public void testIsAcceptableToken() throws Exception {
558 final ParenPadCheck check = new ParenPadCheck();
559 final DetailAstImpl ast = new DetailAstImpl();
560 final String message = "Expected that all acceptable tokens will pass isAcceptableToken "
561 + "method, but some token don't: ";
562
563 for (int token : check.getAcceptableTokens()) {
564 ast.setType(token);
565 assertWithMessage(message + TokenUtil.getTokenName(token))
566 .that(TestUtil.invokeMethod(check, "isAcceptableToken", Boolean.class, ast))
567 .isTrue();
568 }
569 }
570
571 @Test
572 public void testParenPadWithWhenExpression() throws Exception {
573 final String[] expected = {
574 "21:38: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
575 "25:33: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
576 "27:41: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
577 "29:43: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
578 "29:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
579 };
580 verifyWithInlineConfigParser(
581 getPath("InputParenPadCheckWhenExpression.java"), expected);
582 }
583
584 @Test
585 public void testParenPadForRecordPattern() throws Exception {
586 final String[] expected = {
587 "14:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
588 "16:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
589 "16:60: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
590 "22:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
591 "22:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
592 "26:46: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
593 "26:61: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
594 "26:73: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
595 "31:40: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
596 "31:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
597 "31:62: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
598 "31:74: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
599 "42:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
600 "44:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
601 "44:38: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
602 "52:30: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
603 "52:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
604 "56:36: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
605 "56:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
606 "56:63: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
607 "61:30: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
608 "61:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
609 "61:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
610 "61:64: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
611 };
612 verifyWithInlineConfigParser(
613 getPath("InputParenPadForRecordPattern.java"), expected);
614 }
615
616 @Test
617 public void testParenPadForRecordPatternWithSpaceOption() throws Exception {
618 final String[] expected = {
619 "14:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
620 "14:58: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
621 "18:59: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
622 "23:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
623 "23:46: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
624 "23:59: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
625 "23:70: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
626 "29:61: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
627 "29:72: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
628 "33:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
629 "41:30: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
630 "41:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
631 "45:37: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
632 };
633 verifyWithInlineConfigParser(
634 getPath("InputParenPadForRecordPatternWithSpaceOption.java"),
635 expected);
636 }
637
638 }