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.WhitespaceAroundCheck.MSG_WS_NOT_FOLLOWED;
24 import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck.MSG_WS_NOT_PRECEDED;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
29 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
30 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
31
32 public class WhitespaceAroundCheckTest
33 extends AbstractModuleTestSupport {
34
35 @Override
36 public String getPackageLocation() {
37 return "com/puppycrawl/tools/checkstyle/checks/whitespace/whitespacearound";
38 }
39
40 @Test
41 public void testGetRequiredTokens() {
42 final WhitespaceAroundCheck checkObj = new WhitespaceAroundCheck();
43 assertWithMessage(
44 "WhitespaceAroundCheck#getRequiredTokens should return empty array by default")
45 .that(checkObj.getRequiredTokens())
46 .isEmpty();
47 }
48
49 @Test
50 public void testKeywordsAndOperators()
51 throws Exception {
52 final String[] expected = {
53 "33:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
54 "33:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
55 "38:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
56 "46:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
57 "47:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
58 "47:10: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
59 "51:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+="),
60 "51:10: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+="),
61 "55:11: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "-="),
62 "63:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "synchronized"),
63 "65:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "try"),
64 "65:12: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
65 "70:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "catch"),
66 "70:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
67 "90:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
68 "108:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "return"),
69 };
70 verifyWithInlineConfigParser(
71 getPath("InputWhitespaceAroundKeywordsAndOperators.java"), expected);
72 }
73
74 @Test
75 public void testOperators() throws Exception {
76 final String[] expected = {
77 "41:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "?"),
78 "41:29: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "?"),
79 "41:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
80 "41:34: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ":"),
81 "47:15: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "=="),
82 "47:15: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "=="),
83 "56:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "*"),
84 "56:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "*"),
85 "74:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "%"),
86 "75:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "%"),
87 "76:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "%"),
88 "76:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "%"),
89 "81:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "/"),
90 "82:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "/"),
91 "83:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "/"),
92 "83:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "/"),
93 "112:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "assert"),
94 "115:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
95 "115:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ":"),
96 };
97 verifyWithInlineConfigParser(
98 getPath("InputWhitespaceAroundOperators.java"), expected);
99 }
100
101 @Test
102 public void testAnonymousClasses() throws Exception {
103 verifyWithInlineConfigParser(
104 getPath("InputWhitespaceAroundAnonymousClasses.java"),
105 CommonUtil.EMPTY_STRING_ARRAY);
106 }
107
108 @Test
109 public void testForLoopsAndArrays() throws Exception {
110 final String[] expected = {
111 "71:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
112 "100:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
113 "100:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
114 "100:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
115 "100:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
116 };
117 verifyWithInlineConfigParser(
118 getPath("InputWhitespaceAroundForLoopsAndArrays.java"), expected);
119 }
120
121 @Test
122 public void testSimpleInputPart1()
123 throws Exception {
124 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
125 verifyWithInlineConfigParser(
126 getPath("InputWhitespaceAroundSimplePart1.java"), expected);
127 }
128
129 @Test
130 public void testSimpleInputPart2()
131 throws Exception {
132 final String[] expected = {
133 "106:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
134 "107:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
135 "108:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
136 "109:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
137 "110:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
138 "111:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
139 };
140 verifyWithInlineConfigParser(
141 getPath("InputWhitespaceAroundSimplePart2.java"), expected);
142 }
143
144 @Test
145 public void testSimpleInputPart3()
146 throws Exception {
147 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
148 verifyWithInlineConfigParser(
149 getPath("InputWhitespaceAroundSimplePart3.java"), expected);
150 }
151
152 @Test
153 public void testStartOfTheLine()
154 throws Exception {
155 final String[] expected = {
156 "26:2: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
157 };
158 verifyWithInlineConfigParser(
159 getPath("InputWhitespaceAroundStartOfTheLine.java"), expected);
160 }
161
162 @Test
163 public void testBracesPart1()
164 throws Exception {
165 final String[] expected = {
166 "54:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
167 "71:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "for"),
168 };
169 verifyWithInlineConfigParser(
170 getPath("InputWhitespaceAroundBracesPart1.java"), expected);
171 }
172
173 @Test
174 public void testBracesPart2()
175 throws Exception {
176 final String[] expected = {
177 "37:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
178 "37:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
179 "43:39: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
180 "43:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
181 "50:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
182 "50:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
183 "50:17: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
184 "50:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
185 };
186 verifyWithInlineConfigParser(
187 getPath("InputWhitespaceAroundBracesPart2.java"), expected);
188 }
189
190 @Test
191 public void testBracesInMethodsAndConstructorsPart1()
192 throws Exception {
193 final String[] expected = {
194 "54:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
195 "71:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "for"),
196 };
197 verifyWithInlineConfigParser(
198 getPath("InputWhitespaceAroundBraces2Part1.java"), expected);
199 }
200
201 @Test
202 public void testBracesInMethodsAndConstructorsPart2()
203 throws Exception {
204 final String[] expected = {
205 "87:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
206 "87:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
207 "87:17: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
208 "87:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
209 };
210 verifyWithInlineConfigParser(
211 getPath("InputWhitespaceAroundBraces2Part2.java"), expected);
212 }
213
214 @Test
215 public void testArrayInitialization()
216 throws Exception {
217 final String[] expected = {
218 "22:39: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
219 "26:37: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
220 "29:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
221 "37:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
222 "37:59: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
223 "42:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
224 "42:41: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
225 "50:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
226 };
227 verifyWithInlineConfigParser(
228 getPath("InputWhitespaceAroundArrayInitialization.java"), expected);
229 }
230
231 @Test
232 public void testGenericsTokensAreFlagged()
233 throws Exception {
234 final String[] expected = {
235 "28:16: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "&"),
236 "28:16: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "&"),
237 };
238 verifyWithInlineConfigParser(
239 getPath("InputWhitespaceAroundGenerics.java"), expected);
240 }
241
242 @Test
243 public void test1322879And1649038() throws Exception {
244 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
245 verifyWithInlineConfigParser(
246 getPath("InputWhitespaceAround1.java"),
247 expected);
248 }
249
250 @Test
251 public void testAllowDoubleBraceInitialization() throws Exception {
252 final String[] expected = {
253 "32:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
254 "33:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
255 "38:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
256 "38:88: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
257 "41:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
258 "41:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
259 };
260 verifyWithInlineConfigParser(
261 getPath("InputWhitespaceAroundDoubleBraceInitialization.java"),
262 expected);
263 }
264
265 @Test
266 public void testIgnoreEnhancedForColon() throws Exception {
267 final String[] expected = {
268 "40:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
269 };
270 verifyWithInlineConfigParser(
271 getPath("InputWhitespaceAround2.java"),
272 expected);
273 }
274
275 @Test
276 public void testEmptyTypes() throws Exception {
277 final String[] expected = {
278 "46:94: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
279 "46:95: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
280 "50:32: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
281 "50:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
282 "54:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
283 "54:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
284 };
285 verifyWithInlineConfigParser(
286 getPath("InputWhitespaceAroundEmptyTypesAndCycles.java"),
287 expected);
288 }
289
290 @Test
291 public void testEmptyLoops() throws Exception {
292 final String[] expected = {
293 "57:65: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
294 "57:66: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
295 "62:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
296 "62:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
297 "67:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
298 "67:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
299 "76:37: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
300 "76:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
301 "89:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
302 "89:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
303 };
304 verifyWithInlineConfigParser(
305 getPath("InputWhitespaceAroundEmptyTypesAndCycles2.java"),
306 expected);
307 }
308
309 @Test
310 public void testSwitchWhitespaceAround() throws Exception {
311 final String[] expected = {
312 "27:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "switch"),
313 };
314 verifyWithInlineConfigParser(
315 getPath("InputWhitespaceAroundSwitch.java"), expected);
316 }
317
318 @Test
319 public void testSwitchExpressionWhitespaceAround() throws Exception {
320 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
321 verifyWithInlineConfigParser(
322 getPath("InputWhitespaceAroundSwitchExpressions.java"), expected);
323 }
324
325 @Test
326 public void testDoWhileWhitespaceAround() throws Exception {
327 final String[] expected = {
328 "30:11: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
329 };
330 verifyWithInlineConfigParser(
331 getPath("InputWhitespaceAroundDoWhile.java"), expected);
332 }
333
334 @Test
335 public void allowEmptyMethods() throws Exception {
336 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
337 verifyWithInlineConfigParser(
338 getPath("InputWhitespaceAround3.java"), expected);
339 }
340
341 @Test
342 public void testGetAcceptableTokens() {
343 final WhitespaceAroundCheck whitespaceAroundCheckObj = new WhitespaceAroundCheck();
344 final int[] actual = whitespaceAroundCheckObj.getAcceptableTokens();
345 final int[] expected = {
346 TokenTypes.ASSIGN,
347 TokenTypes.ARRAY_INIT,
348 TokenTypes.BAND,
349 TokenTypes.BAND_ASSIGN,
350 TokenTypes.BOR,
351 TokenTypes.BOR_ASSIGN,
352 TokenTypes.BSR,
353 TokenTypes.BSR_ASSIGN,
354 TokenTypes.BXOR,
355 TokenTypes.BXOR_ASSIGN,
356 TokenTypes.COLON,
357 TokenTypes.DIV,
358 TokenTypes.DIV_ASSIGN,
359 TokenTypes.DO_WHILE,
360 TokenTypes.EQUAL,
361 TokenTypes.GE,
362 TokenTypes.GT,
363 TokenTypes.LAMBDA,
364 TokenTypes.LAND,
365 TokenTypes.LCURLY,
366 TokenTypes.LE,
367 TokenTypes.LITERAL_CATCH,
368 TokenTypes.LITERAL_DO,
369 TokenTypes.LITERAL_ELSE,
370 TokenTypes.LITERAL_FINALLY,
371 TokenTypes.LITERAL_FOR,
372 TokenTypes.LITERAL_IF,
373 TokenTypes.LITERAL_RETURN,
374 TokenTypes.LITERAL_SWITCH,
375 TokenTypes.LITERAL_SYNCHRONIZED,
376 TokenTypes.LITERAL_TRY,
377 TokenTypes.LITERAL_WHILE,
378 TokenTypes.LOR,
379 TokenTypes.LT,
380 TokenTypes.MINUS,
381 TokenTypes.MINUS_ASSIGN,
382 TokenTypes.MOD,
383 TokenTypes.MOD_ASSIGN,
384 TokenTypes.NOT_EQUAL,
385 TokenTypes.PLUS,
386 TokenTypes.PLUS_ASSIGN,
387 TokenTypes.QUESTION,
388 TokenTypes.RCURLY,
389 TokenTypes.SL,
390 TokenTypes.SLIST,
391 TokenTypes.SL_ASSIGN,
392 TokenTypes.SR,
393 TokenTypes.SR_ASSIGN,
394 TokenTypes.STAR,
395 TokenTypes.STAR_ASSIGN,
396 TokenTypes.LITERAL_ASSERT,
397 TokenTypes.TYPE_EXTENSION_AND,
398 TokenTypes.WILDCARD_TYPE,
399 TokenTypes.GENERIC_START,
400 TokenTypes.GENERIC_END,
401 TokenTypes.ELLIPSIS,
402 TokenTypes.LITERAL_WHEN,
403 };
404 assertWithMessage("Default acceptable tokens are invalid")
405 .that(actual)
406 .isEqualTo(expected);
407 }
408
409 @Test
410 public void testAllowEmptyTypesIsSetToFalseAndNonEmptyClasses() throws Exception {
411 final String[] expected = {
412 "32:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
413 "36:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
414 "40:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
415 "42:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
416 "42:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
417 "42:31: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
418 "48:30: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
419 "50:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
420 "50:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
421 "55:68: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
422 "55:69: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
423 "60:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
424 "63:12: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
425 "63:13: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
426 "70:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
427 };
428 verifyWithInlineConfigParser(
429 getPath("InputWhitespaceAroundAllowEmptyTypesAndNonEmptyClasses.java"),
430 expected);
431 }
432
433 @Test
434 public void testAllowEmptyTypesIsSetToTrueAndNonEmptyClasses() throws Exception {
435 final String[] expected = {
436 "31:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
437 "35:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
438 "39:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
439 "41:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
440 "41:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
441 "41:31: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
442 "47:30: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
443 "53:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
444 "56:12: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
445 "56:13: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
446 "63:35: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
447 };
448 verifyWithInlineConfigParser(
449 getPath("InputWhitespaceAroundAllowEmptyTypesAndNonEmptyClasses2.java"),
450 expected);
451 }
452
453 @Test
454 public void testNotAllowEmptyLambdaExpressionsByDefault() throws Exception {
455 final String[] expected = {
456 "28:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
457 "28:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
458 "36:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
459 "36:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
460 "40:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
461 "40:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
462 };
463 verifyWithInlineConfigParser(
464 getPath("InputWhitespaceAroundAllowEmptyLambdaExpressions.java"),
465 expected);
466 }
467
468 @Test
469 public void testAllowEmptyLambdaExpressionsWithAllowEmptyLambdaParameter() throws Exception {
470 final String[] expected = {
471 "33:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
472 "33:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
473 "37:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
474 "37:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
475 };
476 verifyWithInlineConfigParser(
477 getPath("InputWhitespaceAroundAllowEmptyLambdaExpressions2.java"),
478 expected);
479 }
480
481 @Test
482 public void testWhitespaceAroundLambda() throws Exception {
483 final String[] expected = {
484 "29:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "->"),
485 "29:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
486 };
487 verifyWithInlineConfigParser(
488 getPath("InputWhitespaceAroundLambda.java"), expected);
489 }
490
491 @Test
492 public void testWhitespaceAroundEmptyCatchBlock() throws Exception {
493 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
494 verifyWithInlineConfigParser(
495 getPath("InputWhitespaceAroundCatch.java"),
496 expected);
497 }
498
499 @Test
500 public void testWhitespaceAroundVarargs() throws Exception {
501 final String[] expected = {
502 "20:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
503 "21:37: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
504 "22:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
505 "22:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
506 "27:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
507 "27:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
508 "31:39: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
509 "31:39: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
510 };
511 verifyWithInlineConfigParser(
512 getPath("InputWhitespaceAroundVarargs.java"), expected);
513 }
514
515 @Test
516 public void testWhitespaceAroundRecords()
517 throws Exception {
518 final String[] expected = {
519 "27:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
520 "27:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
521 "38:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
522 "38:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
523 "42:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
524 "42:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
525 "46:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
526 "46:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
527 "54:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
528 "56:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
529 "57:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
530 "57:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
531 "69:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
532 "70:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
533 "70:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
534 "81:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
535 "82:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
536 "82:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
537 "92:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
538 "96:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
539 "96:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
540 };
541 verifyWithInlineConfigParser(
542 getPath("InputWhitespaceAroundRecords.java"), expected);
543 }
544
545 @Test
546 public void testWhitespaceAroundAllowEmptyCompactCtors()
547 throws Exception {
548 final String[] expected = {
549 "27:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
550 "27:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
551 "38:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
552 "38:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
553 "42:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
554 "42:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
555 "46:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
556 "46:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
557 "54:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
558 "56:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
559 "57:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
560 "57:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
561 "69:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
562 "70:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
563 "70:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
564 "86:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
565 "99:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
566 "103:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
567 "103:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
568 "103:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
569 "112:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
570 };
571 verifyWithInlineConfigParser(
572 getPath("InputWhitespaceAroundAllowEmptyCompactCtors.java"),
573 expected);
574 }
575
576 @Test
577 public void testWhitespaceAroundRecordsAllowEmptyTypes()
578 throws Exception {
579 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
580 verifyWithInlineConfigParser(
581 getPath("InputWhitespaceAroundRecordsAllowEmptyTypes.java"),
582 expected);
583 }
584
585 @Test
586 public void testWhitespaceAroundAllTokens() throws Exception {
587 final String[] expected = {
588 "28:29: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "<"),
589 "28:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "<"),
590 "28:35: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "<"),
591 "28:35: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "<"),
592 "28:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "?"),
593 "28:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "?"),
594 "28:37: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ">"),
595 "28:37: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ">"),
596 "28:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ">"),
597 };
598 verifyWithInlineConfigParser(
599 getPath("InputWhitespaceAroundAllTokens.java"), expected);
600 }
601
602 @Test
603 public void testWhitespaceAroundAfterEmoji() throws Exception {
604 final String[] expected = {
605 "26:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
606 "27:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
607 "28:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
608 "28:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
609 "33:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
610 "33:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
611 "33:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
612 "33:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
613 "33:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
614 "33:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
615 "33:32: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
616 "33:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
617 "33:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
618 "33:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
619 "33:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
620 "33:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
621 };
622 verifyWithInlineConfigParser(
623 getPath("InputWhitespaceAroundAfterEmoji.java"), expected);
624 }
625
626 @Test
627 public void testLiteralWhen() throws Exception {
628 final String[] expected = {
629 "22:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
630 "24:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
631 "26:39: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
632 "31:38: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
633 "31:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "when"),
634 "35:38: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
635 "35:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "when"),
636 "54:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
637 "65:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
638 "68:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "when"),
639 };
640 verifyWithInlineConfigParser(
641 getPath("InputWhitespaceAroundLiteralWhen.java"),
642 expected);
643 }
644
645 @Test
646 public void testWhitespaceAroundAfterPermitsList() throws Exception {
647 final String[] expected = {
648 "26:53: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
649 "26:53: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
650 "26:54: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
651 "31:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
652 "31:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
653 "31:41: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
654 "36:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
655 "36:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
656 "36:49: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
657 };
658 verifyWithInlineConfigParser(
659 getPath("InputWhitespaceAroundAfterPermitsList.java"), expected);
660 }
661
662 @Test
663 public void testWhitespaceAroundUnnamedPatterns() throws Exception {
664 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
665 verifyWithInlineConfigParser(
666 getNonCompilablePath("InputWhitespaceAroundUnnamedPattern.java"), expected);
667 }
668
669 @Test
670 public void testSwitchCasesParens() throws Exception {
671 final String[] expected = {
672 "33:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
673 "33:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
674 "37:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
675 "37:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
676 "47:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
677 "47:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
678 "51:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
679 "51:25: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
680 "59:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
681 "59:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
682 "68:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
683 "68:47: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
684 "76:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
685 "76:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
686 "81:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
687 "81:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
688 "89:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
689 "89:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
690 "89:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
691 "89:25: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
692 "96:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
693 "96:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
694 "100:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
695 "100:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
696 "100:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
697 "100:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
698 "100:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
699 "100:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
700 "108:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
701 "108:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
702 "115:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
703 };
704 verifyWithInlineConfigParser(
705 getPath("InputWhitespaceAroundSwitchCasesParens.java"),
706 expected);
707 }
708
709 @Test
710 public void testSwitchCasesParensWithAllowEmptySwitchBlockStatements() throws Exception {
711 final String fileName =
712 "InputWhitespaceAroundSwitchCasesParensWithAllowEmptySwitchBlockStatements.java";
713
714 final String[] expected = {
715 "49:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
716 "49:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
717 "59:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
718 "59:47: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
719 "68:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
720 "68:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
721 "73:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
722 "73:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
723 "84:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
724 "84:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
725 "88:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
726 "88:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
727 "88:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
728 "88:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
729 "88:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
730 "88:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
731 "96:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
732 "96:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
733 };
734 verifyWithInlineConfigParser(
735 getPath(fileName),
736 expected);
737 }
738
739 }