View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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              "32:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
54              "32:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
55              "34:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
56              "42:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
57              "43:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
58              "43:10: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
59              "44:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+="),
60              "44:10: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+="),
61              "45:11: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "-="),
62              "53:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "synchronized"),
63              "55:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "try"),
64              "55:12: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
65              "57:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "catch"),
66              "57:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
67              "74:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
68              "92:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "return"),
69              "113:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "?"),
70              "113:29: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "?"),
71              "113:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
72              "113:34: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ":"),
73              "114:15: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "=="),
74              "114:15: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "=="),
75              "120:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "*"),
76              "120:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "*"),
77              "135:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "%"),
78              "136:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "%"),
79              "137:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "%"),
80              "137:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "%"),
81              "139:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "/"),
82              "140:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "/"),
83              "141:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "/"),
84              "141:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "/"),
85              "167:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "assert"),
86              "170:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
87              "170:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ":"),
88              "276:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
89              "305:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
90              "305:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
91              "305:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
92              "305: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             "105:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
111             "106:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
112             "107:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
113             "108:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
114             "109:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
115             "110: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             "25: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             "53:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
144             "70: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             "36:47: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
155             "36:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
156             "39:39: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
157             "39:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
158             "43:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
159             "43:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
160             "43:17: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
161             "43: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             "53:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
172             "70: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             "86:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
183             "86:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
184             "86:17: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
185             "86: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             "21:39: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
196             "25:37: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
197             "28:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
198             "36:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
199             "36:59: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
200             "38:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
201             "38:41: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
202             "43: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             "27:16: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "&"),
213             "27: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             "31:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
231             "32:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
232             "34:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
233             "34:88: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
234             "37:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
235             "37: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             "39: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             "45:94: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
256             "45:95: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
257             "46:32: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
258             "46:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
259             "47:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
260             "47: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             "56:65: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
271             "56:66: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
272             "58:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
273             "58:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
274             "60:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
275             "60:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
276             "66:35: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
277             "66:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
278             "76:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
279             "76: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             "26: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             "29: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             "31:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
390             "35:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
391             "39:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
392             "41:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
393             "41:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
394             "41:31: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
395             "43:30: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
396             "45:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
397             "45:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
398             "47:68: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
399             "47:69: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
400             "49:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
401             "52:12: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
402             "52:13: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
403             "56: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             "30:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
414             "34:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
415             "38:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
416             "40:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
417             "40:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
418             "40:31: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
419             "42:30: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
420             "48:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
421             "51:12: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
422             "51:13: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
423             "55: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             "27:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
434             "27:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
435             "32:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
436             "32:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
437             "33:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
438             "33: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             "32:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
449             "32:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
450             "33:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
451             "33: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             "28:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "->"),
462             "28: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             "19:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
480             "20:37: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
481             "21:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
482             "21:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
483             "23:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
484             "23:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
485             "24:39: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
486             "24: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             "26:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
497             "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
498             "34:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
499             "34:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
500             "35:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
501             "35:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
502             "36:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
503             "36:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
504             "41:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
505             "43:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
506             "44:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
507             "44:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
508             "53:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
509             "54:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
510             "54:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
511             "62:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
512             "63:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
513             "63:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
514             "70:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
515             "74:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
516             "74: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             "26:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
527             "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
528             "34:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
529             "34:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
530             "35:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
531             "35:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
532             "36:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
533             "36:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
534             "41:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
535             "43:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
536             "44:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
537             "44:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
538             "53:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
539             "54:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
540             "54:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
541             "67:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
542             "80:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
543             "84:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
544             "84:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
545             "84:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
546             "89: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             "27:29: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "<"),
566             "27:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "<"),
567             "27:35: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "<"),
568             "27:35: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "<"),
569             "27:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "?"),
570             "27:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "?"),
571             "27:37: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ">"),
572             "27:37: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ">"),
573             "27: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             "25:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
583             "26:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
584             "27:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
585             "27:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
586             "29:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
587             "29:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
588             "29:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
589             "29:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
590             "29:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
591             "29:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
592             "29:32: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
593             "29:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
594             "29:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
595             "29:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
596             "29:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
597             "29: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             "21:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
607             "23:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
608             "25:39: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
609             "30:38: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
610             "30:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "when"),
611             "34:38: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
612             "34:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "when"),
613             "53:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
614             "64:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
615             "67: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             "25:53: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
626             "25:53: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
627             "25:54: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
628             "26:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
629             "26:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
630             "26:41: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
631             "27:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
632             "27:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
633             "27: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                 getPath("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 }