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