aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/ParenPadCheckTest.java
blob: 76628ee112f014de220b989cb6278c4ff0087afb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2017 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle.checks.whitespace;

import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_FOLLOWED;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_NOT_FOLLOWED;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_NOT_PRECEDED;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_PRECEDED;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.lang.reflect.Method;

import org.junit.Test;
import org.powermock.reflect.Whitebox;

import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
import com.puppycrawl.tools.checkstyle.utils.TokenUtils;

public class ParenPadCheckTest
    extends AbstractModuleTestSupport {

    @Override
    protected String getPackageLocation() {
        return "com/puppycrawl/tools/checkstyle/checks/whitespace/parenpad";
    }

    @Test
    public void testDefault()
            throws Exception {
        final DefaultConfiguration checkConfig =
            createModuleConfig(ParenPadCheck.class);
        final String[] expected = {
            "58:12: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "58:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "74:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "74:18: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "232:27: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "241:24: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "241:30: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "277:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "277:23: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadWhitespace.java"), expected);
    }

    @Test
    public void testSpace()
            throws Exception {
        final DefaultConfiguration checkConfig =
            createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", PadOption.SPACE.toString());
        final String[] expected = {
            "29:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "29:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "37:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "37:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "41:15: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "41:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "76:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "76:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "97:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "97:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "98:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "98:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "150:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "150:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "153:16: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "153:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "160:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "160:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "162:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "165:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "178:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "178:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "225:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "235:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "235:39: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "252:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "252:93: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "273:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "273:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "275:29: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "275:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "276:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "276:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "287:55: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "287:70: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadWhitespace.java"), expected);
    }

    @Test
    public void testDefaultForIterator()
            throws Exception {
        final DefaultConfiguration checkConfig =
            createModuleConfig(ParenPadCheck.class);
        final String[] expected = {
            "17:34: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "20:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "40:14: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "40:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "43:14: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "48:27: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "51:26: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadForWhitespace.java"), expected);
    }

    @Test
    public void testSpaceEmptyForIterator()
            throws Exception {
        final DefaultConfiguration checkConfig =
            createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", PadOption.SPACE.toString());
        final String[] expected = {
            "11:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "11:35: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "14:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "14:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "17:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "20:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "23:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "27:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "32:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
        };
        verify(checkConfig, getPath("InputParenPadForWhitespace.java"), expected);
    }

    @Test
    public void test1322879() throws Exception {
        final DefaultConfiguration checkConfig =
            createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", PadOption.SPACE.toString());
        final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
        verify(checkConfig, getPath("InputParenPadWithSpace.java"),
               expected);
    }

    @Test
    public void testNospaceWithComplexInput() throws Exception {
        final DefaultConfiguration checkConfig =
            createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", PadOption.NOSPACE.toString());
        final String[] expected = {
            "44:27: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "44:27: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "45:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "48:27: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "49:19: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "49:19: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "52:27: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "53:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "54:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "54:52: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "54:52: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "57:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "58:22: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "59:24: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "60:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "60:51: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "60:57: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "61:29: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "62:43: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "63:41: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "65:43: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "78:28: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "78:28: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "79:19: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "82:33: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "83:19: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "83:19: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "86:29: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "87:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "88:51: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "88:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "88:53: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "90:38: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "91:32: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "92:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "93:30: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "94:60: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "94:62: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "94:69: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "95:34: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "96:47: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "97:42: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "99:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "112:17: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "113:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "113:25: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "113:31: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "114:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "114:28: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "114:34: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "114:50: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "115:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "115:28: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "115:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "115:53: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "115:55: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "119:17: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "119:22: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "123:30: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "123:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "126:22: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "126:22: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "130:19: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "130:19: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "139:10: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "139:20: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "145:33: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "145:46: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "153:34: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "154:48: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "155:36: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "155:46: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "159:26: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "159:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "160:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "160:29: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "160:48: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "160:50: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "163:32: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "163:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "163:48: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "163:60: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "166:39: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "167:25: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "167:50: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "173:38: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "174:48: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "175:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "175:48: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "185:17: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "185:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "186:20: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "186:38: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "190:30: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "190:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "191:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "191:38: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "192:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "192:39: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "200:81: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "200:83: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "201:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "202:23: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "203:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "203:24: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "206:14: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "206:22: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "206:32: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "207:18: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "207:46: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "210:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "210:74: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "210:80: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "210:82: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "211:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "212:49: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "212:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "212:53: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadLeftRightAndNoSpace.java"), expected);
    }

    @Test
    public void testConfigureTokens() throws Exception {
        final DefaultConfiguration checkConfig =
                createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("tokens", "METHOD_CALL");
        final String[] expected = {
            "90:38: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "113:23: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "115:53: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "145:33: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "145:46: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "153:34: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "154:48: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "155:36: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "155:46: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "163:32: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "163:35: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "163:48: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "163:60: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "201:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "202:23: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "203:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "203:24: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "206:32: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "210:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "210:74: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "210:80: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "210:82: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "211:37: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "212:49: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "212:51: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "212:53: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadLeftRightAndNoSpace.java"), expected);
    }

    @Test
    public void testInvalidOption() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", "invalid_option");

        try {
            final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;

            verify(checkConfig, getPath("InputParenPadLeftRightAndNoSpace.java"), expected);
            fail("exception expected");
        }
        catch (CheckstyleException ex) {
            final String messageStart = "cannot initialize module "
                + "com.puppycrawl.tools.checkstyle.TreeWalker - Cannot set property 'option' to "
                + "'invalid_option' in module";
            assertTrue("Invalid exception message, should start with: " + messageStart,
                ex.getMessage().startsWith(messageStart));
        }
    }

    @Test
    public void testLambdaAssignment() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        final String[] expected = {
            "9:42: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "9:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "11:43: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "13:42: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "15:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "15:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "17:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "17:56: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "19:62: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "19:62: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "22:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "22:34: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadLambda.java"), expected);
    }

    @Test
    public void testLambdaAssignmentWithSpace() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", PadOption.SPACE.toString());
        final String[] expected = {
            "9:42: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "9:43: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "11:42: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "13:44: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "15:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "15:49: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "17:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "17:56: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "22:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "22:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadLambdaWithSpace.java"), expected);
    }

    @Test
    public void testLambdaCheckDisabled() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("tokens", "EXPR, METHOD_CALL, METHOD_DEF");
        final String[] expected = {
            "19:62: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "19:62: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "22:21: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "22:34: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadWithDisabledLambda.java"), expected);
    }

    @Test
    public void testLambdaCheckDisabledWithSpace() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", PadOption.SPACE.toString());
        checkConfig.addAttribute("tokens", "EXPR, METHOD_CALL, METHOD_DEF");
        final String[] expected = {
            "22:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "22:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadWithSpaceAndDisabledLambda.java"), expected);
    }

    @Test
    public void testLambdaCheckOnly() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("tokens", "LAMBDA");
        final String[] expected = {
            "9:42: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "9:44: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "11:43: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "13:42: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "15:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "15:49: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "17:47: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
            "17:56: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadLambdaOnly.java"), expected);
    }

    @Test
    public void testLambdaCheckOnlyWithSpace() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", PadOption.SPACE.toString());
        checkConfig.addAttribute("tokens", "LAMBDA");
        final String[] expected = {
            "9:42: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "9:43: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "11:42: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "13:44: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "15:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "15:49: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
            "17:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
            "17:56: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadLambdaOnlyWithSpace.java"), expected);
    }

    @Test
    public void testLambdaCheckOnlyWithSpace1() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        checkConfig.addAttribute("option", PadOption.SPACE.toString());
        final String[] expected = {
            "5:2: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadStartOfTheLine.java"), expected);
    }

    @Test
    public void testTryWithResources() throws Exception {
        final DefaultConfiguration checkConfig = createModuleConfig(ParenPadCheck.class);
        final String[] expected = {
            "9:36: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
            "10:60: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
        };
        verify(checkConfig, getPath("InputParenPadTryWithResources.java"), expected);
    }

    /**
     * Pitest requires us to specify more concrete lower bound for condition for
     * ParenPadCheck#isAcceptableToken as nodes of first several types like CTOR_DEF,
     * METHOD_DEF will never reach this method. It is hard to recreate conditions for
     * all tokens to go through this method. We do not want to change main code to have
     * this set ok tokens more exact, because it will not be ease to understand.
     * So we have to use reflection to be sure all
     * acceptable tokens pass that check.
     */
    @Test
    public void testIsAcceptableToken() throws Exception {
        final ParenPadCheck check = new ParenPadCheck();
        final Method method = Whitebox.getMethod(ParenPadCheck.class,
            "isAcceptableToken", DetailAST.class);
        final DetailAST ast = new DetailAST();
        final String message = "Expected that all accaptable tokens will pass isAccaptableToken "
            + "method, but some token don't: ";

        for (int token : check.getAcceptableTokens()) {
            ast.setType(token);
            assertTrue(message + TokenUtils.getTokenName(token),
                    (boolean) method.invoke(check, ast));
        }
    }
}