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