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