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.indentation;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_CHILD_ERROR;
24  import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_CHILD_ERROR_MULTI;
25  import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_ERROR;
26  import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_ERROR_MULTI;
27  
28  import java.io.BufferedReader;
29  import java.io.IOException;
30  import java.nio.file.Files;
31  import java.nio.file.Path;
32  import java.util.ArrayList;
33  import java.util.Arrays;
34  import java.util.Deque;
35  import java.util.List;
36  import java.util.Locale;
37  import java.util.regex.Matcher;
38  import java.util.regex.Pattern;
39  
40  import org.junit.jupiter.api.Test;
41  
42  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
43  import com.puppycrawl.tools.checkstyle.Checker;
44  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
45  import com.puppycrawl.tools.checkstyle.api.AuditEvent;
46  import com.puppycrawl.tools.checkstyle.api.AuditListener;
47  import com.puppycrawl.tools.checkstyle.api.Configuration;
48  import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
49  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
50  
51  /**
52   * Unit test for IndentationCheck.
53   */
54  public class IndentationCheckTest extends AbstractModuleTestSupport {
55  
56      private static final Pattern LINE_WITH_COMMENT_REGEX = Pattern.compile(
57          ".*?//(?:below )?indent:(\\d+)(?:"
58                  + " ioffset:(\\d+))? exp:(>=)?(\\d+(?:,\\d+)*?)( warn)?$");
59  
60      private static final IndentComment[] EMPTY_INDENT_COMMENT_ARRAY = new IndentComment[0];
61  
62      private static IndentComment[] getLinesWithWarnAndCheckComments(String aFileName,
63              final int tabWidth)
64              throws IOException {
65          final List<IndentComment> result = new ArrayList<>();
66          try (BufferedReader br = Files.newBufferedReader(Path.of(aFileName))) {
67              int lineNumber = 1;
68              String line = br.readLine();
69              IndentComment pendingBelowComment = null;
70  
71              while (line != null) {
72                  final Matcher match = LINE_WITH_COMMENT_REGEX.matcher(line);
73                  if (pendingBelowComment != null) {
74                      final int actualIndent = getLineStart(line, tabWidth);
75  
76                      processPendingBelowComment(pendingBelowComment, actualIndent,
77                              lineNumber, result);
78  
79                      pendingBelowComment = null;
80                  }
81                  else if (match.matches()) {
82                      final boolean isBelow = line.contains("//below indent:");
83                      final IndentComment warn = new IndentComment(match, lineNumber);
84  
85                      if (isBelow) {
86                          pendingBelowComment = warn;
87                      }
88                      else {
89                          final int actualIndent = getLineStart(line, tabWidth);
90                          processInlineComment(warn, actualIndent, lineNumber, aFileName, result);
91                      }
92                  }
93                  else if (!line.isEmpty()) {
94                      throw new IllegalStateException(String.format(Locale.ROOT,
95                              "File \"%1$s\" has no indentation comment or its format "
96                                      + "malformed. Error on line: %2$d",
97                              aFileName,
98                              lineNumber));
99                  }
100 
101                 line = br.readLine();
102                 lineNumber++;
103             }
104         }
105 
106         return result.toArray(EMPTY_INDENT_COMMENT_ARRAY);
107     }
108 
109     private static void processPendingBelowComment(IndentComment pendingBelowComment,
110             int actualIndent, int lineNumber, List<IndentComment> result) {
111         if (actualIndent != pendingBelowComment.getIndent()) {
112             throw new IllegalStateException(String.format(Locale.ROOT,
113                     "Incorrect indentation in 'below' comment. "
114                             + "Line %1$d (from line %2$d): comment:%3$d, actual:%4$d.",
115                     lineNumber,
116                     pendingBelowComment.getLineNumber(),
117                     pendingBelowComment.getIndent(),
118                     actualIndent));
119         }
120 
121         if (!isCommentConsistent(pendingBelowComment)) {
122             throw new IllegalStateException(String.format(Locale.ROOT,
123                     "Inconsistent 'below' comment on line %1$d",
124                     pendingBelowComment.getLineNumber()));
125         }
126 
127         if (pendingBelowComment.isWarning()) {
128             result.add(new IndentComment(pendingBelowComment, lineNumber));
129         }
130     }
131 
132     private static void processInlineComment(IndentComment warn, int actualIndent,
133         int lineNumber, String fileName, List<IndentComment> result) {
134 
135         if (actualIndent != warn.getIndent()) {
136             throw new IllegalStateException(String.format(Locale.ROOT,
137                     "File \"%1$s\" has incorrect indentation in comment. "
138                             + "Line %2$d: comment:%3$d, actual:%4$d.",
139                     fileName,
140                     lineNumber,
141                     warn.getIndent(),
142                     actualIndent));
143         }
144 
145         if (!isCommentConsistent(warn)) {
146             throw new IllegalStateException(String.format(Locale.ROOT,
147                     "File \"%1$s\" has inconsistent comment on line %2$d",
148                     fileName,
149                     lineNumber));
150         }
151 
152         if (warn.isWarning()) {
153             result.add(warn);
154         }
155     }
156 
157     private static boolean isCommentConsistent(IndentComment comment) {
158         final String[] levels = comment.getExpectedWarning().split(", ");
159         final int indent = comment.getIndent() + comment.getIndentOffset();
160         final boolean result;
161         if (levels.length > 1) {
162             // multi
163             final boolean containsActualLevel =
164                             Arrays.asList(levels).contains(String.valueOf(indent));
165 
166             result = containsActualLevel != comment.isWarning();
167         }
168         else {
169             final int expectedWarning = Integer.parseInt(comment.getExpectedWarning());
170 
171             final boolean test;
172             if (comment.isExpectedNonStrict()) {
173                 // non-strict
174                 test = indent >= expectedWarning;
175             }
176             else {
177                 // single
178                 test = expectedWarning == indent;
179             }
180             result = test != comment.isWarning();
181 
182         }
183         return result;
184     }
185 
186     private static int getLineStart(String line, final int tabWidth) {
187         int lineStart = 0;
188         for (int index = 0; index < line.length(); ++index) {
189             if (!Character.isWhitespace(line.charAt(index))) {
190                 lineStart = CommonUtil.lengthExpandedTabs(line, index, tabWidth);
191                 break;
192             }
193         }
194         return lineStart;
195     }
196 
197     private void verifyWarns(Configuration config, String filePath,
198                     String... expected)
199                     throws Exception {
200         final int tabWidth = Integer.parseInt(config.getProperty("tabWidth"));
201         final IndentComment[] linesWithWarn =
202                         getLinesWithWarnAndCheckComments(filePath, tabWidth);
203         verify(config, filePath, expected, linesWithWarn);
204         assertWithMessage("Expected warning count in UT does not match warn comment count "
205                 + "in input file")
206             .that(linesWithWarn.length)
207             .isEqualTo(expected.length);
208     }
209 
210     private void verify(Configuration config, String filePath, String[] expected,
211             final IndentComment... linesWithWarn) throws Exception {
212         final Checker checker = createChecker(config);
213         checker.addListener(new IndentAudit(linesWithWarn));
214         verify(checker, filePath, expected);
215     }
216 
217     @Override
218     public String getPackageLocation() {
219         return "com/puppycrawl/tools/checkstyle/checks/indentation/indentation";
220     }
221 
222     @Test
223     public void testGetRequiredTokens() {
224         final IndentationCheck checkObj = new IndentationCheck();
225         final int[] requiredTokens = checkObj.getRequiredTokens();
226         final HandlerFactory handlerFactory = new HandlerFactory();
227         final int[] expected = handlerFactory.getHandledTypes();
228         Arrays.sort(expected);
229         Arrays.sort(requiredTokens);
230         assertWithMessage("Default required tokens are invalid")
231             .that(requiredTokens)
232             .isEqualTo(expected);
233     }
234 
235     @Test
236     public void testGetAcceptableTokens() {
237         final IndentationCheck checkObj = new IndentationCheck();
238         final int[] acceptableTokens = checkObj.getAcceptableTokens();
239         final HandlerFactory handlerFactory = new HandlerFactory();
240         final int[] expected = handlerFactory.getHandledTypes();
241         Arrays.sort(expected);
242         Arrays.sort(acceptableTokens);
243         assertWithMessage("Default acceptable tokens are invalid")
244             .that(acceptableTokens)
245             .isEqualTo(expected);
246     }
247 
248     @Test
249     public void testThrowsIndentProperty() {
250         final IndentationCheck indentationCheck = new IndentationCheck();
251 
252         indentationCheck.setThrowsIndent(1);
253 
254         assertWithMessage("Invalid throws indent")
255             .that(indentationCheck.getThrowsIndent())
256             .isEqualTo(1);
257     }
258 
259     @Test
260     public void testStrictCondition() throws Exception {
261         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
262         checkConfig.addProperty("arrayInitIndent", "4");
263         checkConfig.addProperty("basicOffset", "4");
264         checkConfig.addProperty("braceAdjustment", "4");
265         checkConfig.addProperty("caseIndent", "4");
266         checkConfig.addProperty("forceStrictCondition", "true");
267         checkConfig.addProperty("lineWrappingIndentation", "8");
268         checkConfig.addProperty("tabWidth", "4");
269         checkConfig.addProperty("throwsIndent", "8");
270         final String[] expected = {
271             "10:29: " + getCheckMessage(MSG_ERROR_MULTI, "method def rcurly", 28, "16, 20, 24"),
272             "13:9: " + getCheckMessage(MSG_ERROR, "method def rcurly", 8, 4),
273             "14:5: " + getCheckMessage(MSG_ERROR, "class def rcurly", 4, 0),
274         };
275         verifyWarns(checkConfig, getPath("InputIndentationStrictCondition.java"), expected);
276     }
277 
278     @Test
279     public void forbidOldStyle() throws Exception {
280         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
281         checkConfig.addProperty("arrayInitIndent", "4");
282         checkConfig.addProperty("basicOffset", "4");
283         checkConfig.addProperty("braceAdjustment", "0");
284         checkConfig.addProperty("caseIndent", "4");
285         checkConfig.addProperty("forceStrictCondition", "true");
286         checkConfig.addProperty("lineWrappingIndentation", "8");
287         checkConfig.addProperty("tabWidth", "4");
288         checkConfig.addProperty("throwsIndent", "8");
289         final String[] expected = {
290             "20:30: " + getCheckMessage(MSG_ERROR, "int", 29, 12),
291             "21:30: " + getCheckMessage(MSG_ERROR, "int", 29, 12),
292         };
293         verifyWarns(checkConfig, getPath("InputIndentationMethodCStyle.java"), expected);
294     }
295 
296     @Test
297     public void testZeroCaseLevel() throws Exception {
298         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
299         checkConfig.addProperty("arrayInitIndent", "4");
300         checkConfig.addProperty("basicOffset", "4");
301         checkConfig.addProperty("braceAdjustment", "0");
302         checkConfig.addProperty("caseIndent", "0");
303         checkConfig.addProperty("forceStrictCondition", "false");
304         checkConfig.addProperty("lineWrappingIndentation", "4");
305         checkConfig.addProperty("tabWidth", "4");
306         checkConfig.addProperty("throwsIndent", "4");
307         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
308         verifyWarns(checkConfig, getPath("InputIndentationZeroCaseLevel.java"), expected);
309     }
310 
311     @Test
312     public void testAndroidStyle() throws Exception {
313         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
314         checkConfig.addProperty("arrayInitIndent", "4");
315         checkConfig.addProperty("basicOffset", "4");
316         checkConfig.addProperty("braceAdjustment", "0");
317         checkConfig.addProperty("caseIndent", "4");
318         checkConfig.addProperty("forceStrictCondition", "false");
319         checkConfig.addProperty("lineWrappingIndentation", "8");
320         checkConfig.addProperty("tabWidth", "4");
321         checkConfig.addProperty("throwsIndent", "8");
322         final String[] expected = {
323             "42:4: " + getCheckMessage(MSG_ERROR, "extends", 3, 8),
324             "44:4: " + getCheckMessage(MSG_ERROR, "member def type", 3, 4),
325             "47:9: " + getCheckMessage(MSG_ERROR, "foo", 8, 12),
326             "50:9: " + getCheckMessage(MSG_ERROR, "int", 8, 12),
327             "53:14: " + getCheckMessage(MSG_ERROR, "true", 13, 16),
328             "56:17: " + getCheckMessage(MSG_ERROR, "+", 16, 20),
329             "57:9: " + getCheckMessage(MSG_ERROR, "if", 8, 12),
330             "60:12: " + getCheckMessage(MSG_ERROR, "if rcurly", 11, 12),
331             "62:8: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 7, 8),
332         };
333         verifyWarns(checkConfig, getPath("InputIndentationAndroidStyle.java"), expected);
334     }
335 
336     @Test
337     public void testMethodCallLineWrap() throws Exception {
338         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
339 
340         checkConfig.addProperty("arrayInitIndent", "4");
341         checkConfig.addProperty("basicOffset", "4");
342         checkConfig.addProperty("braceAdjustment", "0");
343         checkConfig.addProperty("caseIndent", "4");
344         checkConfig.addProperty("forceStrictCondition", "false");
345         checkConfig.addProperty("lineWrappingIndentation", "4");
346         checkConfig.addProperty("tabWidth", "4");
347         checkConfig.addProperty("throwsIndent", "4");
348         final String[] expected = {
349             "53:19: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 18, 20),
350             "54:15: " + getCheckMessage(MSG_ERROR, "method call rparen", 14, 16),
351             "75:13: " + getCheckMessage(MSG_ERROR, "lambda arguments", 12, 16),
352             "81:16: " + getCheckMessage(MSG_ERROR, "method call rparen", 15, 8),
353         };
354         verifyWarns(checkConfig, getPath("InputIndentationMethodCallLineWrap.java"), expected);
355     }
356 
357     @Test
358     public void testMethodCallLineWrap1() throws Exception {
359         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
360 
361         checkConfig.addProperty("arrayInitIndent", "4");
362         checkConfig.addProperty("basicOffset", "4");
363         checkConfig.addProperty("braceAdjustment", "0");
364         checkConfig.addProperty("caseIndent", "4");
365         checkConfig.addProperty("forceStrictCondition", "false");
366         checkConfig.addProperty("lineWrappingIndentation", "4");
367         checkConfig.addProperty("tabWidth", "4");
368         checkConfig.addProperty("throwsIndent", "4");
369         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
370         verifyWarns(checkConfig, getPath("InputIndentationMethodCallLineWrap1.java"),
371                 expected);
372     }
373 
374     @Test
375     public void testDifficultAnnotations() throws Exception {
376         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
377 
378         checkConfig.addProperty("arrayInitIndent", "4");
379         checkConfig.addProperty("basicOffset", "4");
380         checkConfig.addProperty("braceAdjustment", "0");
381         checkConfig.addProperty("caseIndent", "4");
382         checkConfig.addProperty("forceStrictCondition", "false");
383         checkConfig.addProperty("lineWrappingIndentation", "4");
384         checkConfig.addProperty("tabWidth", "4");
385         checkConfig.addProperty("throwsIndent", "4");
386         final String[] expected = {
387             "41:1: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
388                     "annotation array initialization", 0, "4, 25, 72"),
389             "42:1: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
390                     "annotation array initialization", 0, "4, 25, 72"),
391             "51:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
392                     "annotation array initialization", 6, "8, 29, 72"),
393         };
394         verifyWarns(checkConfig, getPath("InputIndentationDifficultAnnotations.java"), expected);
395     }
396 
397     @Test
398     public void testAnnotationClosingParenthesisEndsInSameIndentationAsOpening() throws Exception {
399         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
400 
401         checkConfig.addProperty("basicOffset", "4");
402         checkConfig.addProperty("forceStrictCondition", "true");
403         checkConfig.addProperty("tabWidth", "4");
404 
405         final String[] expected = {
406             "34:17: " + getCheckMessage(MSG_ERROR, ")", 16, 0),
407             "36:17: " + getCheckMessage(MSG_ERROR, ")", 16, 0),
408             "40:9: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
409             "42:9: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
410             "46:9: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
411         };
412 
413         verifyWarns(checkConfig,
414             getPath("InputIndentation"
415                 + "AnnotationClosingParenthesisEndsInSameIndentationAsOpen.java"),
416                 expected);
417     }
418 
419     @Test
420     public void testAnnotationsFromGuava() throws Exception {
421         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
422 
423         checkConfig.addProperty("arrayInitIndent", "4");
424         checkConfig.addProperty("basicOffset", "2");
425         checkConfig.addProperty("braceAdjustment", "0");
426         checkConfig.addProperty("caseIndent", "4");
427         checkConfig.addProperty("forceStrictCondition", "false");
428         checkConfig.addProperty("lineWrappingIndentation", "4");
429         checkConfig.addProperty("tabWidth", "4");
430         checkConfig.addProperty("throwsIndent", "4");
431         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
432         verifyWarns(checkConfig, getPath("InputIndentationFromGuava.java"), expected);
433     }
434 
435     @Test
436     public void testAnnotationsFromGuava1() throws Exception {
437         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
438 
439         checkConfig.addProperty("arrayInitIndent", "4");
440         checkConfig.addProperty("basicOffset", "2");
441         checkConfig.addProperty("braceAdjustment", "0");
442         checkConfig.addProperty("caseIndent", "4");
443         checkConfig.addProperty("forceStrictCondition", "false");
444         checkConfig.addProperty("lineWrappingIndentation", "4");
445         checkConfig.addProperty("tabWidth", "4");
446         checkConfig.addProperty("throwsIndent", "4");
447         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
448         verifyWarns(checkConfig, getPath("InputIndentationFromGuava1.java"), expected);
449     }
450 
451     @Test
452     public void testAnnotationsFromGuava2() throws Exception {
453         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
454 
455         checkConfig.addProperty("arrayInitIndent", "4");
456         checkConfig.addProperty("basicOffset", "2");
457         checkConfig.addProperty("braceAdjustment", "0");
458         checkConfig.addProperty("caseIndent", "4");
459         checkConfig.addProperty("forceStrictCondition", "false");
460         checkConfig.addProperty("lineWrappingIndentation", "4");
461         checkConfig.addProperty("tabWidth", "4");
462         checkConfig.addProperty("throwsIndent", "4");
463         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
464         verifyWarns(checkConfig, getPath("InputIndentationFromGuava2.java"), expected);
465     }
466 
467     @Test
468     public void testAnnotationsFromGuava3() throws Exception {
469         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
470 
471         checkConfig.addProperty("arrayInitIndent", "4");
472         checkConfig.addProperty("basicOffset", "2");
473         checkConfig.addProperty("braceAdjustment", "0");
474         checkConfig.addProperty("caseIndent", "4");
475         checkConfig.addProperty("forceStrictCondition", "false");
476         checkConfig.addProperty("lineWrappingIndentation", "4");
477         checkConfig.addProperty("tabWidth", "4");
478         checkConfig.addProperty("throwsIndent", "4");
479         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
480         verifyWarns(checkConfig, getPath("InputIndentationFromGuava3.java"), expected);
481     }
482 
483     @Test
484     public void testAnnotationsFromGuava4() throws Exception {
485         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
486 
487         checkConfig.addProperty("arrayInitIndent", "4");
488         checkConfig.addProperty("basicOffset", "2");
489         checkConfig.addProperty("braceAdjustment", "0");
490         checkConfig.addProperty("caseIndent", "4");
491         checkConfig.addProperty("forceStrictCondition", "false");
492         checkConfig.addProperty("lineWrappingIndentation", "4");
493         checkConfig.addProperty("tabWidth", "4");
494         checkConfig.addProperty("throwsIndent", "4");
495         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
496         verifyWarns(checkConfig, getPath("InputIndentationFromGuava4.java"), expected);
497     }
498 
499     @Test
500     public void testCorrectIfAndParameters() throws Exception {
501         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
502 
503         checkConfig.addProperty("arrayInitIndent", "4");
504         checkConfig.addProperty("basicOffset", "2");
505         checkConfig.addProperty("braceAdjustment", "0");
506         checkConfig.addProperty("caseIndent", "4");
507         checkConfig.addProperty("forceStrictCondition", "false");
508         checkConfig.addProperty("lineWrappingIndentation", "4");
509         checkConfig.addProperty("tabWidth", "4");
510         checkConfig.addProperty("throwsIndent", "4");
511         final String[] expected = {
512             "66:15: " + getCheckMessage(MSG_ERROR_MULTI, "new", 14, "16, 18"),
513             "75:19: " + getCheckMessage(MSG_ERROR_MULTI, "new", 18, "40, 42"),
514             "96:17: " + getCheckMessage(MSG_ERROR_MULTI, "new", 16, "18, 20"),
515             "100:11: " + getCheckMessage(MSG_ERROR, "+", 10, 12),
516             "104:31: " + getCheckMessage(MSG_ERROR_MULTI, "new", 30, "38, 40"),
517             "106:17: " + getCheckMessage(MSG_CHILD_ERROR, "new", 16, 44),
518         };
519         verifyWarns(checkConfig, getPath("InputIndentationIfAndParameter.java"), expected);
520     }
521 
522     @Test
523     public void testCorrectIfAndParameters1() throws Exception {
524         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
525 
526         checkConfig.addProperty("arrayInitIndent", "4");
527         checkConfig.addProperty("basicOffset", "2");
528         checkConfig.addProperty("braceAdjustment", "0");
529         checkConfig.addProperty("caseIndent", "4");
530         checkConfig.addProperty("forceStrictCondition", "false");
531         checkConfig.addProperty("lineWrappingIndentation", "4");
532         checkConfig.addProperty("tabWidth", "4");
533         checkConfig.addProperty("throwsIndent", "4");
534         final String[] expected = {
535             "38:13: " + getCheckMessage(MSG_ERROR_MULTI, "new", 12, "14, 16"),
536             "42:17: " + getCheckMessage(MSG_CHILD_ERROR, "new", 16, 28),
537             "45:25: " + getCheckMessage(MSG_ERROR_MULTI, "new", 24, "42, 44"),
538         };
539         verifyWarns(checkConfig, getPath("InputIndentationCorrectIfAndParameter1.java"), expected);
540     }
541 
542     @Test
543     public void testAnonymousClasses() throws Exception {
544         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
545 
546         checkConfig.addProperty("arrayInitIndent", "4");
547         checkConfig.addProperty("basicOffset", "2");
548         checkConfig.addProperty("braceAdjustment", "0");
549         checkConfig.addProperty("caseIndent", "4");
550         checkConfig.addProperty("forceStrictCondition", "false");
551         checkConfig.addProperty("lineWrappingIndentation", "4");
552         checkConfig.addProperty("tabWidth", "4");
553         checkConfig.addProperty("throwsIndent", "4");
554         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
555         verifyWarns(checkConfig, getPath("InputIndentationAnonymousClasses.java"), expected);
556     }
557 
558     @Test
559     public void testArrays() throws Exception {
560         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
561 
562         checkConfig.addProperty("arrayInitIndent", "2");
563         checkConfig.addProperty("basicOffset", "2");
564         checkConfig.addProperty("braceAdjustment", "0");
565         checkConfig.addProperty("caseIndent", "4");
566         checkConfig.addProperty("forceStrictCondition", "false");
567         checkConfig.addProperty("lineWrappingIndentation", "4");
568         checkConfig.addProperty("tabWidth", "4");
569         checkConfig.addProperty("throwsIndent", "4");
570         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
571         verifyWarns(checkConfig, getPath("InputIndentationArrays.java"), expected);
572     }
573 
574     @Test
575     public void testLabels() throws Exception {
576         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
577 
578         checkConfig.addProperty("arrayInitIndent", "4");
579         checkConfig.addProperty("basicOffset", "2");
580         checkConfig.addProperty("braceAdjustment", "0");
581         checkConfig.addProperty("caseIndent", "4");
582         checkConfig.addProperty("forceStrictCondition", "false");
583         checkConfig.addProperty("lineWrappingIndentation", "4");
584         checkConfig.addProperty("tabWidth", "4");
585         checkConfig.addProperty("throwsIndent", "4");
586         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
587         verifyWarns(checkConfig, getPath("InputIndentationLabels.java"), expected);
588     }
589 
590     @Test
591     public void testLabels1() throws Exception {
592         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
593 
594         checkConfig.addProperty("arrayInitIndent", "4");
595         checkConfig.addProperty("basicOffset", "2");
596         checkConfig.addProperty("braceAdjustment", "0");
597         checkConfig.addProperty("caseIndent", "4");
598         checkConfig.addProperty("forceStrictCondition", "false");
599         checkConfig.addProperty("lineWrappingIndentation", "4");
600         checkConfig.addProperty("tabWidth", "4");
601         checkConfig.addProperty("throwsIndent", "4");
602         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
603         verifyWarns(checkConfig, getPath("InputIndentationLabels1.java"), expected);
604     }
605 
606     @Test
607     public void testClassesAndMethods() throws Exception {
608         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
609 
610         checkConfig.addProperty("arrayInitIndent", "4");
611         checkConfig.addProperty("basicOffset", "2");
612         checkConfig.addProperty("braceAdjustment", "0");
613         checkConfig.addProperty("caseIndent", "4");
614         checkConfig.addProperty("forceStrictCondition", "false");
615         checkConfig.addProperty("lineWrappingIndentation", "4");
616         checkConfig.addProperty("tabWidth", "4");
617         checkConfig.addProperty("throwsIndent", "4");
618         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
619         verifyWarns(checkConfig, getPath("InputIndentationClassesMethods.java"), expected);
620     }
621 
622     @Test
623     public void testCtorCall() throws Exception {
624         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
625 
626         checkConfig.addProperty("basicOffset", "2");
627         checkConfig.addProperty("braceAdjustment", "0");
628         checkConfig.addProperty("lineWrappingIndentation", "4");
629         checkConfig.addProperty("tabWidth", "4");
630         final String[] expected = {
631             "29:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
632             "30:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
633             "31:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
634             "35:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
635             "36:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
636             "40:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
637             "41:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
638             "42:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
639             "46:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
640             "47:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
641             "51:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
642             "52:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
643             "53:5: " + getCheckMessage(MSG_ERROR, "x", 4, 8),
644             "57:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
645             "58:5: " + getCheckMessage(MSG_ERROR, "method call lparen", 4, 6),
646             "63:5: " + getCheckMessage(MSG_ERROR, ".", 4, 10),
647             "64:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
648             "69:5: " + getCheckMessage(MSG_ERROR, "super", 4, 10),
649             "70:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
650             "76:11: " + getCheckMessage(MSG_ERROR_MULTI, "lambda arguments", 10, "12, 14"),
651         };
652         verifyWarns(checkConfig, getPath("InputIndentationCtorCall.java"), expected);
653     }
654 
655     @Test
656     public void testCtorCall1() throws Exception {
657         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
658 
659         checkConfig.addProperty("basicOffset", "2");
660         checkConfig.addProperty("braceAdjustment", "0");
661         checkConfig.addProperty("lineWrappingIndentation", "4");
662         checkConfig.addProperty("tabWidth", "4");
663         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
664         verifyWarns(checkConfig, getPath("InputIndentationCtorCall1.java"), expected);
665     }
666 
667     @Test
668     public void testMembers() throws Exception {
669         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
670 
671         checkConfig.addProperty("arrayInitIndent", "4");
672         checkConfig.addProperty("basicOffset", "2");
673         checkConfig.addProperty("braceAdjustment", "0");
674         checkConfig.addProperty("caseIndent", "4");
675         checkConfig.addProperty("forceStrictCondition", "false");
676         checkConfig.addProperty("lineWrappingIndentation", "4");
677         checkConfig.addProperty("tabWidth", "4");
678         checkConfig.addProperty("throwsIndent", "4");
679         final String[] expected = {
680             "22:6: " + getCheckMessage(MSG_ERROR, "=", 5, 6),
681             "57:4: " + getCheckMessage(MSG_ERROR, "class def rcurly", 3, 2),
682         };
683 
684         verifyWarns(checkConfig, getPath("InputIndentationMembers.java"), expected);
685     }
686 
687     @Test
688     public void testAnnotationArrayInit() throws Exception {
689         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
690 
691         checkConfig.addProperty("arrayInitIndent", "6");
692         checkConfig.addProperty("basicOffset", "2");
693         checkConfig.addProperty("braceAdjustment", "0");
694         checkConfig.addProperty("caseIndent", "4");
695         checkConfig.addProperty("forceStrictCondition", "false");
696         checkConfig.addProperty("lineWrappingIndentation", "4");
697         checkConfig.addProperty("tabWidth", "8");
698         checkConfig.addProperty("throwsIndent", "4");
699         final String[] expected = {
700             "15:1: " + getCheckMessage(MSG_ERROR, "com", 0, "4"),
701             "19:1: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization", 0,
702                 "4, 6, 34, 36"),
703             "24:14: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
704                     13, "4, 6, 36, 70"),
705             "25:3: " + getCheckMessage(MSG_ERROR_MULTI,
706                     "annotation array initialization rcurly", 2, "0, 4"),
707             "36:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization", 6,
708                 "8, 10, 33, 70"),
709             "37:3: " + getCheckMessage(MSG_ERROR_MULTI,
710                     "annotation array initialization rcurly", 2, "4, 8"),
711 
712             "53:6: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
713                     "annotation array initialization", 5, "6, 8, 10, 70"),
714             "55:6: " + getCheckMessage(MSG_ERROR_MULTI,
715                     "annotation array initialization rcurly", 5, "2, 6"),
716         };
717         final String fileName = getPath("InputIndentationAnnArrInit.java");
718         verifyWarns(checkConfig, fileName, expected);
719     }
720 
721     @Test
722     public void testAnnotationArrayInitTwo() throws Exception {
723         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
724 
725         checkConfig.addProperty("arrayInitIndent", "0");
726         checkConfig.addProperty("basicOffset", "2");
727         checkConfig.addProperty("braceAdjustment", "0");
728         checkConfig.addProperty("caseIndent", "4");
729         checkConfig.addProperty("forceStrictCondition", "false");
730         checkConfig.addProperty("lineWrappingIndentation", "0");
731         checkConfig.addProperty("tabWidth", "8");
732         checkConfig.addProperty("throwsIndent", "4");
733         final String[] expected = {
734 
735             "19:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
736                 "annotation array initialization", 4, "0, 33, 63"),
737             "32:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
738                 "annotation array initialization", 8, "4, 29, 63"),
739             "34:3: " + getCheckMessage(MSG_ERROR,
740                 "annotation array initialization rcurly", 2, 4),
741             "49:7: " + getCheckMessage(MSG_ERROR,
742                 "annotation array initialization lcurly", 6, 2),
743             "51:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
744                 "annotation array initialization", 4, "2, 6, 63"),
745         };
746         final String fileName = getPath("InputIndentationAnnArrInit2.java");
747         verifyWarns(checkConfig, fileName, expected);
748     }
749 
750     @Test
751     public void testAnnotationArrayInitWithEmoji() throws Exception {
752         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
753 
754         checkConfig.addProperty("arrayInitIndent", "0");
755         checkConfig.addProperty("basicOffset", "2");
756         checkConfig.addProperty("braceAdjustment", "0");
757         checkConfig.addProperty("caseIndent", "4");
758         checkConfig.addProperty("forceStrictCondition", "false");
759         checkConfig.addProperty("lineWrappingIndentation", "0");
760         checkConfig.addProperty("tabWidth", "8");
761         checkConfig.addProperty("throwsIndent", "4");
762         final String[] expected = {
763             "18:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
764                     "annotation array initialization", 4, "0, 41, 70"),
765             "31:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
766                     "annotation array initialization", 8, "4, 29, 70"),
767             "33:3: " + getCheckMessage(MSG_ERROR,
768                     "annotation array initialization rcurly", 2, 4),
769             "43:7: " + getCheckMessage(MSG_ERROR,
770                     "member def type", 6, "4"),
771             "48:7: " + getCheckMessage(MSG_ERROR,
772                     "annotation array initialization lcurly", 6, "2"),
773             "49:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
774                     "annotation array initialization", 10, "2, 6, 70"),
775             "50:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
776                     "annotation array initialization", 12, "2, 6, 70"),
777             "51:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
778                     "annotation array initialization", 20, "2, 6, 70"),
779             "53:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
780                     "annotation array initialization", 4, "2, 6, 70"),
781         };
782         final String fileName = getPath("InputIndentationAnnArrInitWithEmoji.java");
783         verifyWarns(checkConfig, fileName, expected);
784 
785     }
786 
787     @Test
788     public void testOddAnnotations()
789             throws Exception {
790         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
791 
792         checkConfig.addProperty("arrayInitIndent", "3");
793         checkConfig.addProperty("basicOffset", "4");
794         checkConfig.addProperty("braceAdjustment", "0");
795         checkConfig.addProperty("caseIndent", "4");
796 
797         checkConfig.addProperty("forceStrictCondition", "false");
798         checkConfig.addProperty("lineWrappingIndentation", "9");
799         checkConfig.addProperty("tabWidth", "4");
800         checkConfig.addProperty("throwsIndent", "4");
801         final String fileName = getPath("InputIndentationOddLineWrappingAndArrayInit.java");
802         final String[] expected = {
803             "26:17: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
804                     16, "11, 17, 54, 64"),
805         };
806         verifyWarns(checkConfig, fileName, expected);
807     }
808 
809     @Test
810     public void testAnnotationOddStyles() throws Exception {
811         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
812 
813         checkConfig.addProperty("tabWidth", "8");
814 
815         final String fileName = getPath("InputIndentationAnnotationArrayInitOldStyle.java");
816 
817         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
818 
819         verifyWarns(checkConfig, fileName, expected);
820     }
821 
822     @Test
823     public void testZeroAnnotationArrayInit()
824             throws Exception {
825         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
826 
827         checkConfig.addProperty("arrayInitIndent", "0");
828         checkConfig.addProperty("basicOffset", "4");
829         checkConfig.addProperty("braceAdjustment", "0");
830         checkConfig.addProperty("caseIndent", "4");
831         checkConfig.addProperty("forceStrictCondition", "false");
832         checkConfig.addProperty("lineWrappingIndentation", "4");
833         checkConfig.addProperty("tabWidth", "4");
834         checkConfig.addProperty("throwsIndent", "4");
835         final String fileName = getPath("InputIndentationZeroArrayInit.java");
836 
837         final String[] expected = {
838             "23:12: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
839                     11, "8, 12, 37, 66"),
840         };
841         verifyWarns(checkConfig, fileName, expected);
842     }
843 
844     @Test
845     public void testAnnotationArrayInitGoodCase()
846             throws Exception {
847         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
848 
849         checkConfig.addProperty("arrayInitIndent", "4");
850         checkConfig.addProperty("basicOffset", "4");
851         checkConfig.addProperty("braceAdjustment", "0");
852         checkConfig.addProperty("caseIndent", "4");
853         checkConfig.addProperty("forceStrictCondition", "false");
854         checkConfig.addProperty("lineWrappingIndentation", "4");
855         checkConfig.addProperty("tabWidth", "4");
856         checkConfig.addProperty("throwsIndent", "4");
857         final String fileName = getPath("InputIndentationAnnotationArrayInitGood.java");
858         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
859         verifyWarns(checkConfig, fileName, expected);
860     }
861 
862     @Test
863     public void testAnnotationArrayInitGoodCaseTwo()
864             throws Exception {
865         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
866 
867         checkConfig.addProperty("arrayInitIndent", "4");
868         checkConfig.addProperty("basicOffset", "4");
869         checkConfig.addProperty("braceAdjustment", "2");
870         checkConfig.addProperty("caseIndent", "4");
871         checkConfig.addProperty("forceStrictCondition", "false");
872         checkConfig.addProperty("lineWrappingIndentation", "4");
873         checkConfig.addProperty("tabWidth", "4");
874         checkConfig.addProperty("throwsIndent", "4");
875         final String fileName = getPath("InputIndentationAnnotationArrayInitGood.java");
876         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
877         verifyWarns(checkConfig, fileName, expected);
878     }
879 
880     @Test
881     public void testInvalidLabel() throws Exception {
882         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
883 
884         checkConfig.addProperty("arrayInitIndent", "4");
885         checkConfig.addProperty("basicOffset", "4");
886         checkConfig.addProperty("braceAdjustment", "0");
887         checkConfig.addProperty("caseIndent", "4");
888         checkConfig.addProperty("forceStrictCondition", "false");
889         checkConfig.addProperty("lineWrappingIndentation", "4");
890         checkConfig.addProperty("tabWidth", "4");
891         checkConfig.addProperty("throwsIndent", "4");
892         final String[] expected = {
893             "24:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 10, "8, 12"),
894             "33:3: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 2, "4, 8"),
895             "36:19: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 18, "8, 12"),
896             "37:19: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 18, 8),
897             "39:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 6, "8, 12"),
898             "41:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 6, "8, 12"),
899         };
900         verifyWarns(checkConfig, getPath("InputIndentationInvalidLabelIndent.java"), expected);
901     }
902 
903     @Test
904     public void testInvalidLabelWithWhileLoop() throws Exception {
905         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
906 
907         checkConfig.addProperty("arrayInitIndent", "4");
908         checkConfig.addProperty("basicOffset", "4");
909         checkConfig.addProperty("braceAdjustment", "0");
910         checkConfig.addProperty("caseIndent", "4");
911         checkConfig.addProperty("forceStrictCondition", "false");
912         checkConfig.addProperty("lineWrappingIndentation", "4");
913         checkConfig.addProperty("tabWidth", "4");
914         checkConfig.addProperty("throwsIndent", "4");
915         final String[] expected = {
916             "18:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 9, "4, 8"),
917             "19:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 9, "8, 12"),
918         };
919         verifyWarns(checkConfig, getPath("InputIndentationInvalidLabelWithWhileLoopIndent.java"),
920             expected);
921     }
922 
923     @Test
924     public void testValidLabel() throws Exception {
925         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
926 
927         checkConfig.addProperty("arrayInitIndent", "4");
928         checkConfig.addProperty("basicOffset", "4");
929         checkConfig.addProperty("braceAdjustment", "0");
930         checkConfig.addProperty("caseIndent", "4");
931         checkConfig.addProperty("forceStrictCondition", "false");
932         checkConfig.addProperty("lineWrappingIndentation", "4");
933         checkConfig.addProperty("tabWidth", "4");
934         checkConfig.addProperty("throwsIndent", "4");
935         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
936         verifyWarns(checkConfig, getPath("InputIndentationValidLabelIndent.java"), expected);
937     }
938 
939     @Test
940     public void testValidIfWithChecker() throws Exception {
941         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
942 
943         checkConfig.addProperty("arrayInitIndent", "4");
944         checkConfig.addProperty("basicOffset", "4");
945         checkConfig.addProperty("braceAdjustment", "0");
946         checkConfig.addProperty("caseIndent", "4");
947         checkConfig.addProperty("forceStrictCondition", "false");
948         checkConfig.addProperty("lineWrappingIndentation", "4");
949         checkConfig.addProperty("tabWidth", "4");
950         checkConfig.addProperty("throwsIndent", "4");
951         final String fileName = getPath("InputIndentationValidIfIndent.java");
952         final String[] expected = {
953             "95:9: " + getCheckMessage(MSG_ERROR, "(", 8, 12),
954         };
955         verifyWarns(checkConfig, fileName, expected);
956     }
957 
958     @Test
959     public void testValidIfWithChecker1() throws Exception {
960         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
961 
962         checkConfig.addProperty("arrayInitIndent", "4");
963         checkConfig.addProperty("basicOffset", "4");
964         checkConfig.addProperty("braceAdjustment", "0");
965         checkConfig.addProperty("caseIndent", "4");
966         checkConfig.addProperty("forceStrictCondition", "false");
967         checkConfig.addProperty("lineWrappingIndentation", "4");
968         checkConfig.addProperty("tabWidth", "4");
969         checkConfig.addProperty("throwsIndent", "4");
970         final String fileName = getPath("InputIndentationValidIfIndent1.java");
971         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
972         verifyWarns(checkConfig, fileName, expected);
973     }
974 
975     @Test
976     public void testValidIfWithChecker2() throws Exception {
977         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
978 
979         checkConfig.addProperty("arrayInitIndent", "4");
980         checkConfig.addProperty("basicOffset", "4");
981         checkConfig.addProperty("braceAdjustment", "0");
982         checkConfig.addProperty("caseIndent", "4");
983         checkConfig.addProperty("forceStrictCondition", "false");
984         checkConfig.addProperty("lineWrappingIndentation", "4");
985         checkConfig.addProperty("tabWidth", "4");
986         checkConfig.addProperty("throwsIndent", "4");
987         final String fileName = getPath("InputIndentationValidIfIndent2.java");
988         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
989         verifyWarns(checkConfig, fileName, expected);
990     }
991 
992     @Test
993     public void testValidDotWithChecker()
994             throws Exception {
995         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
996 
997         checkConfig.addProperty("arrayInitIndent", "4");
998         checkConfig.addProperty("basicOffset", "4");
999         checkConfig.addProperty("braceAdjustment", "0");
1000         checkConfig.addProperty("caseIndent", "4");
1001         checkConfig.addProperty("forceStrictCondition", "false");
1002         checkConfig.addProperty("lineWrappingIndentation", "4");
1003         checkConfig.addProperty("tabWidth", "4");
1004         checkConfig.addProperty("throwsIndent", "4");
1005         final String fileName = getPath("InputIndentationValidDotIndent.java");
1006         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1007         verifyWarns(checkConfig, fileName, expected);
1008     }
1009 
1010     @Test
1011     public void testValidMethodWithChecker()
1012             throws Exception {
1013         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1014 
1015         checkConfig.addProperty("arrayInitIndent", "4");
1016         checkConfig.addProperty("basicOffset", "4");
1017         checkConfig.addProperty("braceAdjustment", "0");
1018         checkConfig.addProperty("caseIndent", "4");
1019         checkConfig.addProperty("forceStrictCondition", "false");
1020         checkConfig.addProperty("lineWrappingIndentation", "4");
1021         checkConfig.addProperty("tabWidth", "4");
1022         checkConfig.addProperty("throwsIndent", "4");
1023         final String fileName = getPath("InputIndentationValidMethodIndent.java");
1024         final String[] expected = {
1025             "76:5: " + getCheckMessage(MSG_ERROR, "void", 4, 8),
1026             "77:5: " + getCheckMessage(MSG_ERROR, "method5", 4, 8),
1027         };
1028         verifyWarns(checkConfig, fileName, expected);
1029     }
1030 
1031     @Test
1032     public void testValidMethodWithChecker1()
1033             throws Exception {
1034         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1035 
1036         checkConfig.addProperty("arrayInitIndent", "4");
1037         checkConfig.addProperty("basicOffset", "4");
1038         checkConfig.addProperty("braceAdjustment", "0");
1039         checkConfig.addProperty("caseIndent", "4");
1040         checkConfig.addProperty("forceStrictCondition", "false");
1041         checkConfig.addProperty("lineWrappingIndentation", "4");
1042         checkConfig.addProperty("tabWidth", "4");
1043         checkConfig.addProperty("throwsIndent", "4");
1044         final String fileName = getPath("InputIndentationValidMethodIndent1.java");
1045         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1046         verifyWarns(checkConfig, fileName, expected);
1047     }
1048 
1049     @Test
1050     public void testInvalidMethodWithChecker1()
1051             throws Exception {
1052         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1053 
1054         checkConfig.addProperty("arrayInitIndent", "4");
1055         checkConfig.addProperty("basicOffset", "4");
1056         checkConfig.addProperty("braceAdjustment", "0");
1057         checkConfig.addProperty("caseIndent", "4");
1058         checkConfig.addProperty("forceStrictCondition", "false");
1059         checkConfig.addProperty("lineWrappingIndentation", "4");
1060         checkConfig.addProperty("tabWidth", "4");
1061         checkConfig.addProperty("throwsIndent", "4");
1062         final String fileName = getPath("InputIndentationInvalidMethodIndent1.java");
1063         final String[] expected = {
1064             "23:7: " + getCheckMessage(MSG_ERROR, "ctor def rcurly", 6, 4),
1065             "26:7: " + getCheckMessage(MSG_ERROR, "ctor def modifier", 6, 4),
1066             "27:3: " + getCheckMessage(MSG_ERROR, "ctor def lcurly", 2, 4),
1067             "28:7: " + getCheckMessage(MSG_ERROR, "ctor def rcurly", 6, 4),
1068             "31:3: " + getCheckMessage(MSG_ERROR, "method def modifier", 2, 4),
1069             "32:7: " + getCheckMessage(MSG_ERROR, "method def rcurly", 6, 4),
1070             "69:6: " + getCheckMessage(MSG_ERROR, "method def modifier", 5, 4),
1071             "70:6: " + getCheckMessage(MSG_ERROR, "final", 5, 9),
1072             "71:6: " + getCheckMessage(MSG_ERROR, "void", 5, 9),
1073             "72:5: " + getCheckMessage(MSG_ERROR, "method5", 4, 9),
1074             "86:11: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
1075             "89:11: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
1076             "99:7: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 6, 12),
1077         };
1078         verifyWarns(checkConfig, fileName, expected);
1079     }
1080 
1081     @Test
1082     public void testInvalidMethodWithChecker2()
1083             throws Exception {
1084         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1085 
1086         checkConfig.addProperty("arrayInitIndent", "4");
1087         checkConfig.addProperty("basicOffset", "4");
1088         checkConfig.addProperty("braceAdjustment", "0");
1089         checkConfig.addProperty("caseIndent", "4");
1090         checkConfig.addProperty("forceStrictCondition", "false");
1091         checkConfig.addProperty("lineWrappingIndentation", "4");
1092         checkConfig.addProperty("tabWidth", "4");
1093         checkConfig.addProperty("throwsIndent", "4");
1094         final String fileName = getPath("InputIndentationInvalidMethodIndent2.java");
1095         final String[] expected = {
1096             "23:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 8),
1097             "26:4: " + getCheckMessage(MSG_ERROR, "method def modifier", 3, 4),
1098             "27:4: " + getCheckMessage(MSG_ERROR, "final", 3, 7),
1099             "28:4: " + getCheckMessage(MSG_ERROR, "void", 3, 7),
1100             "29:6: " + getCheckMessage(MSG_ERROR, "method6", 5, 7),
1101             "39:7: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 6, 8),
1102             "40:7: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
1103             "41:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
1104             "42:7: " + getCheckMessage(MSG_ERROR, "if rcurly", 6, 8),
1105             "45:11: " + getCheckMessage(MSG_ERROR, "Arrays", 10, 12),
1106             "51:15: " + getCheckMessage(MSG_ERROR, "new", 14, 16),
1107             "54:11: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
1108             "59:15: " + getCheckMessage(MSG_ERROR, "new", 14, 16),
1109             "63:11: " + getCheckMessage(MSG_ERROR, "new", 10, 12),
1110             "67:11: " + getCheckMessage(MSG_ERROR, "new", 10, 12),
1111             "68:7: " + getCheckMessage(MSG_ERROR, ")", 6, 8),
1112             "72:7: " + getCheckMessage(MSG_ERROR, "method call rparen", 6, 8),
1113             "86:5: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 4, 8),
1114             "91:5: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 4, 8),
1115             "95:1: " + getCheckMessage(MSG_ERROR, "int", 0, 8),
1116             "96:5: " + getCheckMessage(MSG_ERROR, "method9", 4, 8),
1117             "106:13: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
1118         };
1119         verifyWarns(checkConfig, fileName, expected);
1120     }
1121 
1122     @Test
1123     public void testAlternativeGoogleStyleSwitchCaseAndEnums()
1124             throws Exception {
1125         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1126 
1127         checkConfig.addProperty("arrayInitIndent", "4");
1128         checkConfig.addProperty("basicOffset", "2");
1129         checkConfig.addProperty("braceAdjustment", "2");
1130         checkConfig.addProperty("caseIndent", "2");
1131         checkConfig.addProperty("forceStrictCondition", "false");
1132         checkConfig.addProperty("lineWrappingIndentation", "4");
1133         checkConfig.addProperty("tabWidth", "4");
1134         checkConfig.addProperty("throwsIndent", "4");
1135         final String fileName = getPath("InputIndentationSwitchCasesAndEnums.java");
1136         final String[] expected = {
1137             "18:7: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 4),
1138             "35:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
1139             "38:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 8),
1140             "54:5: " + getCheckMessage(MSG_ERROR, "block lcurly", 4, 2),
1141             "55:3: " + getCheckMessage(MSG_CHILD_ERROR, "block", 2, 4),
1142         };
1143         verifyWarns(checkConfig, fileName, expected);
1144     }
1145 
1146     @Test
1147     public void testInvalidSwitchWithChecker()
1148             throws Exception {
1149         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1150 
1151         checkConfig.addProperty("arrayInitIndent", "4");
1152         checkConfig.addProperty("basicOffset", "4");
1153         checkConfig.addProperty("braceAdjustment", "0");
1154         checkConfig.addProperty("caseIndent", "4");
1155         checkConfig.addProperty("forceStrictCondition", "false");
1156         checkConfig.addProperty("lineWrappingIndentation", "4");
1157         checkConfig.addProperty("tabWidth", "4");
1158         checkConfig.addProperty("throwsIndent", "4");
1159         final String fileName = getPath("InputIndentationInvalidSwitchIndent.java");
1160         final String[] expected = {
1161             "30:7: " + getCheckMessage(MSG_ERROR, "switch", 6, 8),
1162             "32:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
1163             "33:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1164             "37:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1165             "39:15: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 12),
1166             "40:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
1167             "43:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
1168             "44:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1169             "45:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1170             "53:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1171             "54:19: " + getCheckMessage(MSG_CHILD_ERROR, "block", 18, 16),
1172             "55:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
1173             "59:11: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
1174             "62:15: " + getCheckMessage(MSG_ERROR, "block rcurly", 14, 12),
1175             "66:15: " + getCheckMessage(MSG_ERROR, "block lcurly", 14, 12),
1176             "69:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
1177             "76:15: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 16),
1178             "81:15: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 16),
1179             "89:7: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
1180             "92:7: " + getCheckMessage(MSG_ERROR, "switch lcurly", 6, 8),
1181             "93:11: " + getCheckMessage(MSG_ERROR, "switch rcurly", 10, 8),
1182             "95:11: " + getCheckMessage(MSG_ERROR, "switch lcurly", 10, 8),
1183             "96:7: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
1184             "99:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
1185             "100:13: " + getCheckMessage(MSG_ERROR, "if", 12, 16),
1186             "101:17: " + getCheckMessage(MSG_CHILD_ERROR, "if", 16, 20),
1187             "102:13: " + getCheckMessage(MSG_ERROR, "else", 12, 16),
1188             "103:17: " + getCheckMessage(MSG_CHILD_ERROR, "else", 16, 20),
1189             "106:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 4, 12),
1190         };
1191         verifyWarns(checkConfig, fileName, expected);
1192     }
1193 
1194     @Test
1195     public void testIfElseWithNoCurly()
1196             throws Exception {
1197         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1198 
1199         checkConfig.addProperty("arrayInitIndent", "4");
1200         checkConfig.addProperty("basicOffset", "4");
1201         checkConfig.addProperty("braceAdjustment", "0");
1202         checkConfig.addProperty("caseIndent", "4");
1203         checkConfig.addProperty("forceStrictCondition", "false");
1204         checkConfig.addProperty("lineWrappingIndentation", "4");
1205         checkConfig.addProperty("tabWidth", "4");
1206         checkConfig.addProperty("throwsIndent", "4");
1207         final String fileName = getPath("InputIndentationIfElseWithNoCurly.java");
1208         final String[] expected = {
1209             "20:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
1210             "25:5: " + getCheckMessage(MSG_ERROR, "if", 4, 8),
1211             "26:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
1212             "37:13: " + getCheckMessage(MSG_ERROR, "else", 12, 8),
1213             "39:9: " + getCheckMessage(MSG_ERROR, "if", 8, 12),
1214             "43:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 16),
1215         };
1216         verifyWarns(checkConfig, fileName, expected);
1217     }
1218 
1219     @Test
1220     public void testWhileWithNoCurly()
1221             throws Exception {
1222         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1223 
1224         checkConfig.addProperty("arrayInitIndent", "4");
1225         checkConfig.addProperty("basicOffset", "4");
1226         checkConfig.addProperty("braceAdjustment", "0");
1227         checkConfig.addProperty("caseIndent", "4");
1228         checkConfig.addProperty("forceStrictCondition", "false");
1229         checkConfig.addProperty("lineWrappingIndentation", "4");
1230         checkConfig.addProperty("tabWidth", "4");
1231         checkConfig.addProperty("throwsIndent", "4");
1232         final String fileName = getPath("InputIndentationWhileNoCurly.java");
1233         final String[] expected = {
1234             "21:1: " + getCheckMessage(MSG_CHILD_ERROR, "while", 0, 12),
1235             "26:5: " + getCheckMessage(MSG_ERROR, "while", 4, 8),
1236             "27:9: " + getCheckMessage(MSG_CHILD_ERROR, "while", 8, 12),
1237             "32:9: " + getCheckMessage(MSG_ERROR, "while", 8, 12),
1238             "36:9: " + getCheckMessage(MSG_CHILD_ERROR, "while", 8, 16),
1239         };
1240         verifyWarns(checkConfig, fileName, expected);
1241     }
1242 
1243     @Test
1244     public void testForWithNoCurly()
1245             throws Exception {
1246         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1247 
1248         checkConfig.addProperty("arrayInitIndent", "4");
1249         checkConfig.addProperty("basicOffset", "4");
1250         checkConfig.addProperty("braceAdjustment", "0");
1251         checkConfig.addProperty("caseIndent", "4");
1252         checkConfig.addProperty("forceStrictCondition", "false");
1253         checkConfig.addProperty("lineWrappingIndentation", "4");
1254         checkConfig.addProperty("tabWidth", "4");
1255         checkConfig.addProperty("throwsIndent", "4");
1256         final String fileName = getPath("InputIndentationForWithoutCurly.java");
1257         final String[] expected = {
1258             "21:1: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
1259             "26:5: " + getCheckMessage(MSG_ERROR, "for", 4, 8),
1260             "27:9: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 12),
1261             "32:9: " + getCheckMessage(MSG_ERROR, "for", 8, 12),
1262             "33:9: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 16),
1263             "37:9: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 16),
1264 
1265         };
1266         verifyWarns(checkConfig, fileName, expected);
1267     }
1268 
1269     @Test
1270     public void testDoWhileWithoutCurly()
1271             throws Exception {
1272         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1273 
1274         checkConfig.addProperty("arrayInitIndent", "4");
1275         checkConfig.addProperty("basicOffset", "4");
1276         checkConfig.addProperty("braceAdjustment", "0");
1277         checkConfig.addProperty("caseIndent", "4");
1278         checkConfig.addProperty("forceStrictCondition", "false");
1279         checkConfig.addProperty("lineWrappingIndentation", "4");
1280         checkConfig.addProperty("tabWidth", "4");
1281         checkConfig.addProperty("throwsIndent", "4");
1282         final String fileName = getPath("InputIndentationDoWhile.java");
1283         final String[] expected = {
1284             "23:9: " + getCheckMessage(MSG_CHILD_ERROR, "do..while", 8, 12),
1285             "30:5: " + getCheckMessage(MSG_ERROR, "do..while while", 4, 8),
1286             "33:13: " + getCheckMessage(MSG_ERROR, "do..while while", 12, 8),
1287         };
1288         verifyWarns(checkConfig, fileName, expected);
1289     }
1290 
1291     @Test
1292     public void testValidSwitchWithChecker()
1293             throws Exception {
1294         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1295 
1296         checkConfig.addProperty("arrayInitIndent", "4");
1297         checkConfig.addProperty("basicOffset", "4");
1298         checkConfig.addProperty("braceAdjustment", "0");
1299         checkConfig.addProperty("caseIndent", "4");
1300         checkConfig.addProperty("forceStrictCondition", "false");
1301         checkConfig.addProperty("lineWrappingIndentation", "4");
1302         checkConfig.addProperty("tabWidth", "4");
1303         checkConfig.addProperty("throwsIndent", "4");
1304         final String fileName = getPath("InputIndentationValidSwitchIndent.java");
1305         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1306         verifyWarns(checkConfig, fileName, expected);
1307     }
1308 
1309     @Test
1310     public void testNewKeyword() throws Exception {
1311         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1312 
1313         checkConfig.addProperty("basicOffset", "4");
1314         checkConfig.addProperty("forceStrictCondition", "false");
1315         checkConfig.addProperty("lineWrappingIndentation", "8");
1316         checkConfig.addProperty("tabWidth", "4");
1317         checkConfig.addProperty("throwsIndent", "8");
1318         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1319         verifyWarns(checkConfig, getPath("InputIndentationNew.java"), expected);
1320     }
1321 
1322     @Test
1323     public void testNewKeywordChildren() throws Exception {
1324         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1325 
1326         checkConfig.addProperty("arrayInitIndent", "2");
1327         checkConfig.addProperty("basicOffset", "2");
1328         checkConfig.addProperty("braceAdjustment", "2");
1329         checkConfig.addProperty("caseIndent", "2");
1330         checkConfig.addProperty("forceStrictCondition", "false");
1331         checkConfig.addProperty("lineWrappingIndentation", "4");
1332         checkConfig.addProperty("tabWidth", "4");
1333         checkConfig.addProperty("throwsIndent", "4");
1334         final String[] expected = {
1335             "27:1: " + getCheckMessage(MSG_ERROR_MULTI, "new", 0, "14, 16"),
1336             "28:1: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "new", 0, "18, 20"),
1337             "36:1: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "new", 0, "18, 20"),
1338             "42:9: " + getCheckMessage(MSG_ERROR, "new", 8, 12),
1339             "43:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "object def", 10, "14, 16, 18"),
1340             "51:1: " + getCheckMessage(MSG_CHILD_ERROR, "new", 0, 16),
1341             "56:5: " + getCheckMessage(MSG_CHILD_ERROR, "new", 4, 8),
1342             "57:5: " + getCheckMessage(MSG_CHILD_ERROR, "new", 4, 8),
1343             "63:5: " + getCheckMessage(MSG_ERROR_MULTI, "lambda arguments", 4, "10, 12"),
1344             "64:1: " + getCheckMessage(MSG_CHILD_ERROR, "new", 0, 8),
1345         };
1346         verifyWarns(checkConfig, getPath("InputIndentationNewChildren.java"), expected);
1347     }
1348 
1349     @Test
1350     public void testNewKeywordChildrenSevntuConfig() throws Exception {
1351         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1352 
1353         checkConfig.addProperty("arrayInitIndent", "4");
1354         checkConfig.addProperty("basicOffset", "4");
1355         checkConfig.addProperty("braceAdjustment", "0");
1356         checkConfig.addProperty("caseIndent", "4");
1357         checkConfig.addProperty("forceStrictCondition", "false");
1358         checkConfig.addProperty("lineWrappingIndentation", "8");
1359         checkConfig.addProperty("tabWidth", "4");
1360         checkConfig.addProperty("throwsIndent", "8");
1361         final String[] expected = {
1362             "43:29: " + getCheckMessage(MSG_CHILD_ERROR, "new", 28, 36),
1363         };
1364         verifyWarns(checkConfig,
1365                 getPath("InputIndentationNewChildrenSevntuConfig.java"), expected);
1366     }
1367 
1368     @Test
1369     public void testNewKeyword2() throws Exception {
1370         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1371 
1372         checkConfig.addProperty("basicOffset", "4");
1373         checkConfig.addProperty("forceStrictCondition", "true");
1374         checkConfig.addProperty("lineWrappingIndentation", "8");
1375         checkConfig.addProperty("tabWidth", "4");
1376         checkConfig.addProperty("throwsIndent", "8");
1377         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1378         verifyWarns(checkConfig, getPath("InputIndentationNew.java"), expected);
1379     }
1380 
1381     // we can not use verifyWarns() due to usage of multi line string syntax in input
1382     @Test
1383     public void testTextBlockLiteral() throws Exception {
1384         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1385 
1386         checkConfig.addProperty("lineWrappingIndentation", "4");
1387         checkConfig.addProperty("forceStrictCondition", "true");
1388         checkConfig.addProperty("tabWidth", "4");
1389         final String[] expected = {
1390             "18:1: " + getCheckMessage(MSG_ERROR, "\"\"\"", 0, 8),
1391             "29:17: " + getCheckMessage(MSG_ERROR, "\"\"\"", 16, 12),
1392             "46:1: " + getCheckMessage(MSG_ERROR, "\"\"\"", 0, 12),
1393             "52:1: " + getCheckMessage(MSG_ERROR, "\"\"\"", 0, 12),
1394             "59:9: " + getCheckMessage(MSG_ERROR, "\"\"\"", 8, 12),
1395             "78:15: " + getCheckMessage(MSG_ERROR, "\"\"\"", 14, 12),
1396         };
1397         verifyWarns(checkConfig, getPath("InputIndentationTextBlock.java"),
1398             expected);
1399     }
1400 
1401     @Test
1402     public void testValidNewKeywordWithForceStrictCondition() throws Exception {
1403         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1404 
1405         checkConfig.addProperty("basicOffset", "4");
1406         checkConfig.addProperty("forceStrictCondition", "true");
1407         checkConfig.addProperty("lineWrappingIndentation", "8");
1408         checkConfig.addProperty("tabWidth", "4");
1409         checkConfig.addProperty("throwsIndent", "8");
1410         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1411         verifyWarns(checkConfig, getPath("InputIndentationNew.java"), expected);
1412     }
1413 
1414     @Test
1415     public void testInvalidNewKeywordWithForceStrictCondition() throws Exception {
1416         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1417 
1418         checkConfig.addProperty("basicOffset", "4");
1419         checkConfig.addProperty("forceStrictCondition", "true");
1420         checkConfig.addProperty("lineWrappingIndentation", "8");
1421         checkConfig.addProperty("tabWidth", "4");
1422         checkConfig.addProperty("throwsIndent", "8");
1423         final String[] expected = {
1424             "21:12: " + getCheckMessage(MSG_ERROR, "]", 11, 12),
1425             "25:5: " + getCheckMessage(MSG_ERROR, "[", 4, 12),
1426             "32:17: " + getCheckMessage(MSG_ERROR, "new", 16, 24),
1427             "33:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "object def", 20, "28, 32, 36"),
1428             "34:17: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 16, "24, 28, 32"),
1429             "37:36: " + getCheckMessage(MSG_ERROR, "+", 35, 16),
1430             "41:35: " + getCheckMessage(MSG_ERROR, "]", 34, 16),
1431             "45:36: " + getCheckMessage(MSG_ERROR, "42", 35, 16),
1432             "49:36: " + getCheckMessage(MSG_ERROR, "+", 35, 16),
1433             "50:36: " + getCheckMessage(MSG_ERROR, "+", 35, 16),
1434             "55:21: " + getCheckMessage(MSG_ERROR, "1", 20, 16),
1435             "59:13: " + getCheckMessage(MSG_ERROR, "fun2", 12, 16),
1436             "78:11: " + getCheckMessage(MSG_ERROR, "Object", 10, 12),
1437             "82:16: " + getCheckMessage(MSG_ERROR, "]", 15, 12),
1438         };
1439         verifyWarns(checkConfig,
1440             getPath("InputIndentationNewWithForceStrictCondition.java"), expected);
1441     }
1442 
1443     @Test
1444     public void testValidArrayInitDefaultIndentWithChecker()
1445             throws Exception {
1446         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1447 
1448         checkConfig.addProperty("arrayInitIndent", "4");
1449         checkConfig.addProperty("basicOffset", "4");
1450         checkConfig.addProperty("braceAdjustment", "0");
1451         checkConfig.addProperty("caseIndent", "4");
1452         checkConfig.addProperty("forceStrictCondition", "false");
1453         checkConfig.addProperty("lineWrappingIndentation", "4");
1454         checkConfig.addProperty("tabWidth", "4");
1455         checkConfig.addProperty("throwsIndent", "4");
1456         final String fileName = getPath("InputIndentationValidArrayInitDefaultIndent.java");
1457         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1458         verifyWarns(checkConfig, fileName, expected);
1459     }
1460 
1461     @Test
1462     public void testValidArrayInitWithChecker()
1463             throws Exception {
1464         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1465 
1466         checkConfig.addProperty("arrayInitIndent", "8");
1467         checkConfig.addProperty("basicOffset", "4");
1468         checkConfig.addProperty("braceAdjustment", "0");
1469         checkConfig.addProperty("caseIndent", "4");
1470         checkConfig.addProperty("forceStrictCondition", "false");
1471         checkConfig.addProperty("lineWrappingIndentation", "4");
1472         checkConfig.addProperty("tabWidth", "4");
1473         checkConfig.addProperty("throwsIndent", "4");
1474         final String fileName = getPath("InputIndentationValidArrayInitIndent.java");
1475         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1476         verifyWarns(checkConfig, fileName, expected);
1477     }
1478 
1479     @Test
1480     public void testValidArrayInitTwoDimensional() throws Exception {
1481         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1482 
1483         checkConfig.addProperty("arrayInitIndent", "2");
1484         checkConfig.addProperty("basicOffset", "4");
1485         checkConfig.addProperty("braceAdjustment", "4");
1486         checkConfig.addProperty("caseIndent", "4");
1487         checkConfig.addProperty("forceStrictCondition", "false");
1488         checkConfig.addProperty("lineWrappingIndentation", "4");
1489         checkConfig.addProperty("tabWidth", "4");
1490         checkConfig.addProperty("throwsIndent", "4");
1491         final String fileName = getPath("InputIndentationValidArrayInitIndentTwoDimensional.java");
1492         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1493         verifyWarns(checkConfig, fileName, expected);
1494     }
1495 
1496     @Test
1497     public void testInvalidArrayInitTwoDimensional() throws Exception {
1498         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1499 
1500         checkConfig.addProperty("arrayInitIndent", "2");
1501         checkConfig.addProperty("basicOffset", "4");
1502         checkConfig.addProperty("braceAdjustment", "4");
1503         checkConfig.addProperty("caseIndent", "4");
1504         checkConfig.addProperty("forceStrictCondition", "false");
1505         checkConfig.addProperty("lineWrappingIndentation", "4");
1506         checkConfig.addProperty("tabWidth", "4");
1507         checkConfig.addProperty("throwsIndent", "4");
1508         final String fileName =
1509             getPath("InputIndentationInvalidArrayInitIndent2D.java");
1510         final String[] expected = {
1511             "19:5: " + getCheckMessage(MSG_ERROR_MULTI,
1512                 "array initialization lcurly", 4, "6, 8, 20, 56, 60"),
1513             "24:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
1514                 "array initialization", 9, "8, 10, 12, 22, 24, 56, 58, 60"),
1515             "27:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
1516                 "array initialization", 6, "8, 10, 12, 22, 24, 56, 58, 60"),
1517             "29:5: " + getCheckMessage(MSG_ERROR_MULTI,
1518                 "array initialization lcurly", 4, "6, 8, 20, 56, 60"),
1519             "30:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
1520                 "array initialization", 6, "8, 10, 12, 22, 24, 56, 58, 60"),
1521             "31:5: " + getCheckMessage(MSG_ERROR_MULTI,
1522                 "array initialization rcurly", 4, "6, 8, 20, 56, 60"),
1523 
1524         };
1525         verifyWarns(checkConfig, fileName, expected);
1526     }
1527 
1528     @Test
1529     public void testValidArrayInit()
1530             throws Exception {
1531         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1532 
1533         checkConfig.addProperty("arrayInitIndent", "2");
1534         checkConfig.addProperty("basicOffset", "2");
1535         checkConfig.addProperty("braceAdjustment", "2");
1536         checkConfig.addProperty("caseIndent", "2");
1537         checkConfig.addProperty("forceStrictCondition", "false");
1538         checkConfig.addProperty("lineWrappingIndentation", "4");
1539         checkConfig.addProperty("tabWidth", "4");
1540         checkConfig.addProperty("throwsIndent", "4");
1541         final String fileName = getPath("InputIndentationValidArrayInitIndentTwo.java");
1542         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1543         verifyWarns(checkConfig, fileName, expected);
1544     }
1545 
1546     @Test
1547     public void testArrayInitWithEmoji() throws Exception {
1548         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1549 
1550         checkConfig.addProperty("arrayInitIndent", "2");
1551         checkConfig.addProperty("basicOffset", "2");
1552         checkConfig.addProperty("braceAdjustment", "2");
1553         checkConfig.addProperty("caseIndent", "2");
1554         checkConfig.addProperty("forceStrictCondition", "false");
1555         checkConfig.addProperty("lineWrappingIndentation", "4");
1556         checkConfig.addProperty("tabWidth", "4");
1557         checkConfig.addProperty("throwsIndent", "4");
1558         final String fileName = getPath("InputIndentationArrayInitIndentWithEmoji.java");
1559         final String[] expected = {
1560             "20:6: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1561                5, "4, 6, 54, 56"),
1562             "25:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1563                8, "4, 6, 37, 56"),
1564             "26:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1565                10, "4, 6, 37, 56"),
1566             "31:11: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly",
1567                10, "4, 6, 21, 56, 60"),
1568         };
1569         verifyWarns(checkConfig, fileName, expected);
1570     }
1571 
1572     @Test
1573     public void testYieldKeywordWithForceStrictCondition() throws Exception {
1574         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1575         checkConfig.addProperty("forceStrictCondition", "true");
1576         checkConfig.addProperty("tabWidth", "4");
1577         final String[] expected = {
1578             "15:13: " + getCheckMessage(MSG_CHILD_ERROR, "block", 12, 16),
1579             "16:13: " + getCheckMessage(MSG_ERROR, "yield", 12, 16),
1580             "44:13: " + getCheckMessage(MSG_CHILD_ERROR, "block", 12, 16),
1581             "45:13: " + getCheckMessage(MSG_ERROR, "yield", 12, 16),
1582             "50:5: " + getCheckMessage(MSG_ERROR, "yield", 4, 16),
1583             "71:15: " + getCheckMessage(MSG_ERROR, "yield", 14, 16),
1584             "74:20: " + getCheckMessage(MSG_ERROR, "yield", 19, 16),
1585             "77:9: " + getCheckMessage(MSG_ERROR, "yield", 8, 16),
1586         };
1587         verifyWarns(checkConfig,
1588                 getPath("InputIndentationYieldForceStrict.java"), expected);
1589     }
1590 
1591     @Test
1592     public void testChainedMethodCalling() throws Exception {
1593         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1594 
1595         checkConfig.addProperty("arrayInitIndent", "2");
1596         checkConfig.addProperty("basicOffset", "2");
1597         checkConfig.addProperty("braceAdjustment", "2");
1598         checkConfig.addProperty("caseIndent", "2");
1599         checkConfig.addProperty("forceStrictCondition", "false");
1600         checkConfig.addProperty("lineWrappingIndentation", "4");
1601         checkConfig.addProperty("tabWidth", "4");
1602         checkConfig.addProperty("throwsIndent", "4");
1603         final String fileName = getPath("InputIndentationChainedMethodCalls.java");
1604         final String[] expected = {
1605             "36:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
1606             "41:5: " + getCheckMessage(MSG_ERROR, ".", 4, 8),
1607             "42:5: " + getCheckMessage(MSG_ERROR, ".", 4, 8),
1608             "45:5: " + getCheckMessage(MSG_ERROR, "new", 4, 8),
1609         };
1610         verifyWarns(checkConfig, fileName, expected);
1611     }
1612 
1613     @Test
1614     public void testInvalidArrayInitWithTrueStrictCondition()
1615             throws Exception {
1616         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1617 
1618         checkConfig.addProperty("arrayInitIndent", "4");
1619         checkConfig.addProperty("basicOffset", "4");
1620         checkConfig.addProperty("braceAdjustment", "0");
1621         checkConfig.addProperty("caseIndent", "4");
1622         checkConfig.addProperty("forceStrictCondition", "true");
1623         checkConfig.addProperty("lineWrappingIndentation", "4");
1624         checkConfig.addProperty("tabWidth", "4");
1625         checkConfig.addProperty("throwsIndent", "4");
1626         final String fileName = getPath("InputIndentationInvalidArrayInitIndent.java");
1627         final String[] expected = {
1628             "22:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1629             "23:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1630             "25:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1631             "29:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1632             "30:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 8,
1633                 "10, 36, 71"),
1634             "31:5: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 4, "6, 10"),
1635             "34:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1636                 "8, 33, 71"),
1637             "35:8: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 7,
1638                 "8, 33, 71"),
1639             "36:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1640                 "8, 33, 71"),
1641             "41:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1642             "45:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "4, 8"),
1643             "49:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1644             "53:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 20,
1645                 "8, 31, 33"),
1646             "54:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1647                 4, "8, 31, 33"),
1648             "59:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1649                 6, "8, 33, 71"),
1650             "64:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1651             "66:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1652             "67:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 2, "6, 10"),
1653             "70:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1654                 6, "8, 38, 71"),
1655             "77:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1656                 10, "12, 26, 71"),
1657         };
1658 
1659         verifyWarns(checkConfig, fileName, expected);
1660     }
1661 
1662     @Test
1663     public void testInvalidArrayInitWithTrueStrictCondition1()
1664             throws Exception {
1665         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1666 
1667         checkConfig.addProperty("arrayInitIndent", "4");
1668         checkConfig.addProperty("basicOffset", "4");
1669         checkConfig.addProperty("braceAdjustment", "0");
1670         checkConfig.addProperty("caseIndent", "4");
1671         checkConfig.addProperty("forceStrictCondition", "true");
1672         checkConfig.addProperty("lineWrappingIndentation", "4");
1673         checkConfig.addProperty("tabWidth", "4");
1674         checkConfig.addProperty("throwsIndent", "4");
1675         final String fileName = getPath("InputIndentationInvalidArrayInitIndent1.java");
1676         final String[] expected = {
1677             "30:9: " + getCheckMessage(MSG_ERROR, "1", 8, 12),
1678             "41:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1679                 "12, 32, 71"),
1680             "42:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1681                 "12, 32, 71"),
1682             "45:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1683                 "12, 32, 71"),
1684             "46:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1685                 "12, 32, 71"),
1686             "47:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1687             "50:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 6, "8, 12"),
1688             "51:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1689                 "10, 12, 71"),
1690             "53:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1691             // following are tests for annotation array initialization
1692             "61:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1693                 12, "16, 46, 48"),
1694             "65:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1695                 14, "12, 16, 71"),
1696             "69:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1697                 14, "16, 28, 30"),
1698             "70:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1699                 8, "12, 16"),
1700             "72:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1701                 12, "16, 31, 71"),
1702         };
1703 
1704         verifyWarns(checkConfig, fileName, expected);
1705     }
1706 
1707     @Test
1708     public void testInvalidArrayInitWithFalseStrictCondition()
1709             throws Exception {
1710         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1711 
1712         checkConfig.addProperty("arrayInitIndent", "4");
1713         checkConfig.addProperty("basicOffset", "4");
1714         checkConfig.addProperty("braceAdjustment", "0");
1715         checkConfig.addProperty("caseIndent", "4");
1716         checkConfig.addProperty("forceStrictCondition", "false");
1717         checkConfig.addProperty("lineWrappingIndentation", "4");
1718         checkConfig.addProperty("tabWidth", "4");
1719         checkConfig.addProperty("throwsIndent", "4");
1720         final String fileName = getPath("InputIndentationInvalidArrayInitIndent.java");
1721         final String[] expected = {
1722             "22:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1723             "23:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1724             "25:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1725             "29:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1726             "30:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 8,
1727                 "10, 36, 71"),
1728             "31:5: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 4, "6, 10"),
1729             "34:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1730                 "8, 33, 71"),
1731             "35:8: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 7,
1732                 "8, 33, 71"),
1733             "36:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1734                 "8, 33, 71"),
1735             "41:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1736             "45:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "4, 8"),
1737             "49:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1738             "53:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 20,
1739                 "8, 31, 33"),
1740             "54:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1741                 4, "8, 31, 33"),
1742             "59:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1743                 6, "8, 33, 71"),
1744             "64:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1745             "66:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1746             "67:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 2, "6, 10"),
1747             "70:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1748                 6, "8, 38, 71"),
1749             "77:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1750                 10, "12, 26, 71"),
1751         };
1752 
1753         verifyWarns(checkConfig, fileName, expected);
1754     }
1755 
1756     @Test
1757     public void testInvalidArrayInitWithFalseStrictCondition1()
1758             throws Exception {
1759         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1760 
1761         checkConfig.addProperty("arrayInitIndent", "4");
1762         checkConfig.addProperty("basicOffset", "4");
1763         checkConfig.addProperty("braceAdjustment", "0");
1764         checkConfig.addProperty("caseIndent", "4");
1765         checkConfig.addProperty("forceStrictCondition", "false");
1766         checkConfig.addProperty("lineWrappingIndentation", "4");
1767         checkConfig.addProperty("tabWidth", "4");
1768         checkConfig.addProperty("throwsIndent", "4");
1769         final String fileName = getPath("InputIndentationInvalidArrayInitIndent1.java");
1770         final String[] expected = {
1771             "30:9: " + getCheckMessage(MSG_ERROR, "1", 8, 12),
1772             "41:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1773                 "12, 32, 71"),
1774             "42:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1775                 "12, 32, 71"),
1776             "45:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1777                 "12, 32, 71"),
1778             "46:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1779                 "12, 32, 71"),
1780             "47:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1781             "50:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 6, "8, 12"),
1782             "51:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1783                 "10, 12, 71"),
1784             "53:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1785             // following are tests for annotation array initialization
1786             "61:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1787                 12, "16, 46, 48"),
1788             "65:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1789                 14, "12, 16, 71"),
1790             "69:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1791                 14, "16, 28, 30"),
1792             "70:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1793                 8, "12, 16"),
1794             "72:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1795                 12, "16, 31, 71"),
1796         };
1797 
1798         verifyWarns(checkConfig, fileName, expected);
1799     }
1800 
1801     // Test Input without trailing comment and usage of 'verify' method is due to #16906
1802     @Test
1803     public void testInvalidArrayInitIndentNoCommentsTrueStrictCondition()
1804             throws Exception {
1805         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1806 
1807         checkConfig.addProperty("arrayInitIndent", "4");
1808         checkConfig.addProperty("basicOffset", "4");
1809         checkConfig.addProperty("braceAdjustment", "0");
1810         checkConfig.addProperty("caseIndent", "4");
1811         checkConfig.addProperty("forceStrictCondition", "true");
1812         checkConfig.addProperty("lineWrappingIndentation", "4");
1813         checkConfig.addProperty("tabWidth", "4");
1814         checkConfig.addProperty("throwsIndent", "4");
1815         final String fileName = getPath(
1816             "InputIndentationInvalidArrInitIndentNoTrailingComments.java");
1817         final String[] expected = {
1818             "31:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1819                 12, "16, 46, 48"),
1820             "37:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1821                 14, "12, 16"),
1822             "41:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1823                 14, "16, 28, 30"),
1824             "42:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1825                 8, "12, 16"),
1826             "45:13: " + getCheckMessage(MSG_CHILD_ERROR, "annotation array initialization",
1827                 12, 16),
1828         };
1829         verifyWarns(checkConfig, fileName, expected);
1830     }
1831 
1832     // Test Input without trailing comment and usage of 'verify' method is due to #16906
1833     @Test
1834     public void testInvalidArrayInitIndentNoCommentsFalseStrictCondition()
1835             throws Exception {
1836         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1837 
1838         checkConfig.addProperty("arrayInitIndent", "4");
1839         checkConfig.addProperty("basicOffset", "4");
1840         checkConfig.addProperty("braceAdjustment", "0");
1841         checkConfig.addProperty("caseIndent", "4");
1842         checkConfig.addProperty("forceStrictCondition", "false");
1843         checkConfig.addProperty("lineWrappingIndentation", "4");
1844         checkConfig.addProperty("tabWidth", "4");
1845         checkConfig.addProperty("throwsIndent", "4");
1846         final String fileName = getPath(
1847             "InputIndentationInvalidArrInitIndentNoTrailingComments.java");
1848         final String[] expected = {
1849             "31:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1850                 12, "16, 46, 48"),
1851             "37:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1852                 14, "12, 16"),
1853             "41:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1854                 14, "16, 28, 30"),
1855             "42:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1856                 8, "12, 16"),
1857             "45:13: " + getCheckMessage(MSG_CHILD_ERROR, "annotation array initialization",
1858                 12, 16),
1859         };
1860         verifyWarns(checkConfig, fileName, expected);
1861     }
1862 
1863     @Test
1864     public void testValidTryWithChecker()
1865             throws Exception {
1866         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1867 
1868         checkConfig.addProperty("arrayInitIndent", "4");
1869         checkConfig.addProperty("basicOffset", "4");
1870         checkConfig.addProperty("braceAdjustment", "0");
1871         checkConfig.addProperty("caseIndent", "4");
1872         checkConfig.addProperty("forceStrictCondition", "false");
1873         checkConfig.addProperty("lineWrappingIndentation", "4");
1874         checkConfig.addProperty("tabWidth", "4");
1875         checkConfig.addProperty("throwsIndent", "4");
1876         final String fileName = getPath("InputIndentationValidTryIndent.java");
1877         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1878         verifyWarns(checkConfig, fileName, expected);
1879     }
1880 
1881     @Test
1882     public void testInvalidTryWithChecker()
1883             throws Exception {
1884         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1885 
1886         checkConfig.addProperty("arrayInitIndent", "4");
1887         checkConfig.addProperty("basicOffset", "4");
1888         checkConfig.addProperty("braceAdjustment", "0");
1889         checkConfig.addProperty("caseIndent", "4");
1890         checkConfig.addProperty("forceStrictCondition", "false");
1891         checkConfig.addProperty("lineWrappingIndentation", "4");
1892         checkConfig.addProperty("tabWidth", "4");
1893         checkConfig.addProperty("throwsIndent", "4");
1894         final String fileName = getPath("InputIndentationInvalidTryIndent.java");
1895         final String[] expected = {
1896             "25:10: " + getCheckMessage(MSG_ERROR, "try", 9, 8),
1897             "26:8: " + getCheckMessage(MSG_ERROR, "try rcurly", 7, 8),
1898             "28:8: " + getCheckMessage(MSG_ERROR, "catch rcurly", 7, 8),
1899             "30:5: " + getCheckMessage(MSG_ERROR, "try", 4, 8),
1900             "31:9: " + getCheckMessage(MSG_CHILD_ERROR, "try", 8, 12),
1901             "32:5: " + getCheckMessage(MSG_ERROR, "try rcurly", 4, 8),
1902             "33:9: " + getCheckMessage(MSG_CHILD_ERROR, "finally", 8, 12),
1903             "38:9: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 8, 12),
1904             "43:11: " + getCheckMessage(MSG_ERROR, "try rcurly", 10, 8),
1905             "45:7: " + getCheckMessage(MSG_ERROR, "catch rcurly", 6, 8),
1906             "52:6: " + getCheckMessage(MSG_ERROR, "catch rcurly", 5, 8),
1907             "59:11: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
1908             "60:15: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 14, 12),
1909             "61:11: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
1910             "63:7: " + getCheckMessage(MSG_ERROR, "catch", 6, 8),
1911             "70:11: " + getCheckMessage(MSG_ERROR, "try lcurly", 10, 8),
1912             "72:11: " + getCheckMessage(MSG_ERROR, "try rcurly", 10, 8),
1913             "74:7: " + getCheckMessage(MSG_ERROR, "catch lcurly", 6, 8),
1914             "77:11: " + getCheckMessage(MSG_ERROR, "catch rcurly", 10, 8),
1915             "80:11: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
1916             "86:1: " + getCheckMessage(MSG_ERROR, "try", 0, 8),
1917             "87:1: " + getCheckMessage(MSG_ERROR, "try rcurly", 0, 8),
1918             "88:1: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 0, 12),
1919             "89:1: " + getCheckMessage(MSG_ERROR, "catch rcurly", 0, 8),
1920             "91:1: " + getCheckMessage(MSG_ERROR, "try", 0, 8),
1921             "92:1: " + getCheckMessage(MSG_ERROR, "try rcurly", 0, 8),
1922             "93:1: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 0, 12),
1923             "94:1: " + getCheckMessage(MSG_ERROR, "catch rcurly", 0, 8),
1924         };
1925         verifyWarns(checkConfig, fileName, expected);
1926     }
1927 
1928     @Test
1929     public void testCatchParametersOnNewLine()
1930             throws Exception {
1931         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1932 
1933         checkConfig.addProperty("arrayInitIndent", "2");
1934         checkConfig.addProperty("basicOffset", "2");
1935         checkConfig.addProperty("braceAdjustment", "2");
1936         checkConfig.addProperty("caseIndent", "2");
1937         checkConfig.addProperty("forceStrictCondition", "false");
1938         checkConfig.addProperty("lineWrappingIndentation", "4");
1939         checkConfig.addProperty("tabWidth", "4");
1940         checkConfig.addProperty("throwsIndent", "4");
1941         final String fileName =
1942             getPath("InputIndentationCatchParametersOnNewLine.java");
1943 
1944         final String[] expected = {
1945             "22:1: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 0, 8),
1946             "31:5: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 4, 8),
1947             "38:5: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 4, 8),
1948             "48:13: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 12, 8),
1949             "64:9: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 8, 12),
1950         };
1951         verifyWarns(checkConfig, fileName, expected);
1952     }
1953 
1954     @Test
1955     public void testMultiLineStatements()
1956             throws Exception {
1957         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1958 
1959         checkConfig.addProperty("arrayInitIndent", "2");
1960         checkConfig.addProperty("basicOffset", "2");
1961         checkConfig.addProperty("braceAdjustment", "2");
1962         checkConfig.addProperty("caseIndent", "2");
1963         checkConfig.addProperty("forceStrictCondition", "false");
1964         checkConfig.addProperty("lineWrappingIndentation", "4");
1965         checkConfig.addProperty("tabWidth", "4");
1966         checkConfig.addProperty("throwsIndent", "4");
1967         final String fileName =
1968             getPath("InputIndentationMultilineStatements.java");
1969 
1970         final String[] expected = {
1971             "23:7: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 6, 8),
1972             "39:7: " + getCheckMessage(MSG_ERROR, 0, 6, 8),
1973             "40:7: " + getCheckMessage(MSG_ERROR, 1, 6, 8),
1974             "65:7: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 6, 8),
1975         };
1976         verifyWarns(checkConfig, fileName, expected);
1977     }
1978 
1979     @Test
1980     public void testInvalidClassDefWithChecker()
1981             throws Exception {
1982         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1983 
1984         checkConfig.addProperty("arrayInitIndent", "4");
1985         checkConfig.addProperty("basicOffset", "4");
1986         checkConfig.addProperty("braceAdjustment", "0");
1987         checkConfig.addProperty("caseIndent", "4");
1988         checkConfig.addProperty("forceStrictCondition", "false");
1989         checkConfig.addProperty("lineWrappingIndentation", "4");
1990         checkConfig.addProperty("tabWidth", "4");
1991         checkConfig.addProperty("throwsIndent", "4");
1992         final String fileName = getPath("InputIndentationInvalidClassDefIndent.java");
1993         final String[] expected = {
1994             "18:3: " + getCheckMessage(MSG_ERROR, "class def modifier", 2, 0),
1995             "24:3: " + getCheckMessage(MSG_ERROR, "class def lcurly", 2, 0),
1996             "27:3: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
1997             "30:9: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 0),
1998             "34:3: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
1999             "39:3: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
2000             "40:3: " + getCheckMessage(MSG_ERROR, "implements", 2, 4),
2001             "46:3: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
2002             "54:3: " + getCheckMessage(MSG_ERROR, "implements", 2, 4),
2003             "55:3: " + getCheckMessage(MSG_ERROR, "java", 2, 4),
2004             "60:3: " + getCheckMessage(MSG_ERROR, "class def modifier", 2, 0),
2005             "61:3: " + getCheckMessage(MSG_ERROR, "class def lcurly", 2, 0),
2006             "69:3: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
2007             "73:3: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
2008             "81:1: " + getCheckMessage(MSG_ERROR, "class", 0, 4),
2009         };
2010         verifyWarns(checkConfig, fileName, expected);
2011     }
2012 
2013     @Test
2014     public void testInvalidClassDefWithChecker1()
2015             throws Exception {
2016         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2017 
2018         checkConfig.addProperty("arrayInitIndent", "4");
2019         checkConfig.addProperty("basicOffset", "4");
2020         checkConfig.addProperty("braceAdjustment", "0");
2021         checkConfig.addProperty("caseIndent", "4");
2022         checkConfig.addProperty("forceStrictCondition", "false");
2023         checkConfig.addProperty("lineWrappingIndentation", "4");
2024         checkConfig.addProperty("tabWidth", "4");
2025         checkConfig.addProperty("throwsIndent", "4");
2026         final String fileName = getPath("InputIndentationInvalidClassDefIndent1.java");
2027         final String[] expected = {
2028             "23:3: " + getCheckMessage(MSG_ERROR, "class def modifier", 2, 0),
2029             "28:9: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 4),
2030             "30:13: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 4),
2031             "32:9: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 4),
2032             "35:7: " + getCheckMessage(MSG_ERROR, "member def modifier", 6, 8),
2033             "41:11: " + getCheckMessage(MSG_ERROR, "int", 10, 12),
2034             "45:7: " + getCheckMessage(MSG_ERROR, "member def modifier", 6, 8),
2035             "50:7: " + getCheckMessage(MSG_ERROR, "class def rcurly", 6, 4),
2036             "52:13: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 4),
2037             "57:13: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 8),
2038             "60:17: " + getCheckMessage(MSG_ERROR, "class def ident", 10, 8),
2039             "62:11: " + getCheckMessage(MSG_ERROR, "class def rcurly", 10, 8),
2040             "65:11: " + getCheckMessage(MSG_ERROR, "member def type", 10, 12),
2041             "70:11: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 10, 8),
2042             "71:9: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 8, "10, 14"),
2043             "75:9: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 8, "10, 14"),
2044             "78:7: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 6, "8, 12"),
2045             "82:7: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 6, "8, 12"),
2046             "86:11: " + getCheckMessage(MSG_ERROR, "method def modifier", 10, 12),
2047             "88:11: " + getCheckMessage(MSG_ERROR, "method def rcurly", 10, 12),
2048         };
2049         verifyWarns(checkConfig, fileName, expected);
2050     }
2051 
2052     @Test
2053     public void testInvalidBlockWithChecker()
2054             throws Exception {
2055         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2056 
2057         checkConfig.addProperty("arrayInitIndent", "4");
2058         checkConfig.addProperty("basicOffset", "4");
2059         checkConfig.addProperty("braceAdjustment", "0");
2060         checkConfig.addProperty("caseIndent", "4");
2061         checkConfig.addProperty("forceStrictCondition", "false");
2062         checkConfig.addProperty("lineWrappingIndentation", "4");
2063         checkConfig.addProperty("tabWidth", "4");
2064         checkConfig.addProperty("throwsIndent", "4");
2065         final String fileName = getPath("InputIndentationInvalidBlockIndent.java");
2066         final String[] expected = {
2067             "26:8: " + getCheckMessage(MSG_ERROR, "block lcurly", 7, 8),
2068             "27:10: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
2069             "29:10: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
2070             "30:8: " + getCheckMessage(MSG_ERROR, "block rcurly", 7, 8),
2071             "32:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
2072             "34:7: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 8),
2073             "35:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
2074             "38:10: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
2075             "39:14: " + getCheckMessage(MSG_CHILD_ERROR, "block", 13, 12),
2076             "41:14: " + getCheckMessage(MSG_CHILD_ERROR, "block", 13, 12),
2077             "42:10: " + getCheckMessage(MSG_ERROR, "block rcurly", 9, 8),
2078             "45:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
2079             "46:11: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
2080             "48:11: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
2081             "49:7: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 8),
2082             "52:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
2083             "55:11: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
2084             "59:11: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
2085             "63:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
2086             "68:11: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
2087             "70:11: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
2088             "71:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
2089             "86:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
2090         };
2091         verifyWarns(checkConfig, fileName, expected);
2092     }
2093 
2094     @Test
2095     public void testInvalidBlockWithChecker1()
2096             throws Exception {
2097         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2098 
2099         checkConfig.addProperty("arrayInitIndent", "4");
2100         checkConfig.addProperty("basicOffset", "4");
2101         checkConfig.addProperty("braceAdjustment", "0");
2102         checkConfig.addProperty("caseIndent", "4");
2103         checkConfig.addProperty("forceStrictCondition", "false");
2104         checkConfig.addProperty("lineWrappingIndentation", "4");
2105         checkConfig.addProperty("tabWidth", "4");
2106         checkConfig.addProperty("throwsIndent", "4");
2107         final String fileName = getPath("InputIndentationInvalidBlockIndent1.java");
2108         final String[] expected = {
2109             "27:3: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
2110             "28:7: " + getCheckMessage(MSG_ERROR, "static initialization", 6, 4),
2111             "32:8: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 7, 8),
2112             "35:7: " + getCheckMessage(MSG_ERROR, "static initialization", 6, 4),
2113             "37:3: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 2, 4),
2114             "39:3: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
2115             "41:7: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
2116             "43:3: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
2117             "45:7: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
2118             "48:3: " + getCheckMessage(MSG_ERROR, "static initialization lcurly", 2, 4),
2119             "49:7: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
2120             "50:7: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
2121             "55:7: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
2122             "60:5: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 4, 8),
2123             "61:3: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 2, 4),
2124             "66:7: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
2125             "69:3: " + getCheckMessage(MSG_ERROR, "block lcurly", 2, 4),
2126             "70:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 4),
2127             "73:3: " + getCheckMessage(MSG_ERROR, "block lcurly", 2, 4),
2128             "75:7: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 4),
2129             "77:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 4),
2130             "79:3: " + getCheckMessage(MSG_ERROR, "block rcurly", 2, 4),
2131             "82:7: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 8),
2132         };
2133         verifyWarns(checkConfig, fileName, expected);
2134     }
2135 
2136     @Test
2137     public void testInvalidIfWithChecker()
2138             throws Exception {
2139         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2140 
2141         checkConfig.addProperty("arrayInitIndent", "4");
2142         checkConfig.addProperty("basicOffset", "4");
2143         checkConfig.addProperty("braceAdjustment", "0");
2144         checkConfig.addProperty("caseIndent", "4");
2145         checkConfig.addProperty("forceStrictCondition", "false");
2146         checkConfig.addProperty("lineWrappingIndentation", "4");
2147         checkConfig.addProperty("tabWidth", "4");
2148         checkConfig.addProperty("throwsIndent", "4");
2149         final String fileName = getPath("InputIndentationInvalidIfIndent.java");
2150         final String[] expected = {
2151             "54:2: " + getCheckMessage(MSG_ERROR, "if", 1, 8),
2152             "60:10: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
2153             "61:10: " + getCheckMessage(MSG_ERROR, "if lcurly", 9, 8),
2154             "62:8: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
2155             "64:7: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
2156             "65:6: " + getCheckMessage(MSG_ERROR, "if lcurly", 5, 8),
2157             "66:6: " + getCheckMessage(MSG_ERROR, "if rcurly", 5, 8),
2158             "71:11: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
2159             "72:8: " + getCheckMessage(MSG_ERROR, "else rcurly", 7, 8),
2160             "75:10: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
2161 
2162             "76:8: " + getCheckMessage(MSG_ERROR, "if lcurly", 7, 8),
2163             "78:10: " + getCheckMessage(MSG_ERROR, "else", 9, 8),
2164             "80:10: " + getCheckMessage(MSG_ERROR, "else rcurly", 9, 8),
2165             "83:11: " + getCheckMessage(MSG_ERROR, "if", 10, 8),
2166             "84:8: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
2167             "85:10: " + getCheckMessage(MSG_ERROR, "else", 9, 8),
2168             "86:8: " + getCheckMessage(MSG_ERROR, "else lcurly", 7, 8),
2169             "87:10: " + getCheckMessage(MSG_ERROR, "else rcurly", 9, 8),
2170 
2171             "91:10: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
2172             "92:10: " + getCheckMessage(MSG_ERROR, "if lcurly", 9, 8),
2173             "93:10: " + getCheckMessage(MSG_ERROR, "if rcurly", 9, 8),
2174             "94:8: " + getCheckMessage(MSG_ERROR, "else lcurly", 7, 8),
2175             "95:11: " + getCheckMessage(MSG_ERROR, "else rcurly", 10, 8),
2176             "98:7: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
2177             "99:11: " + getCheckMessage(MSG_ERROR, "if lcurly", 10, 8),
2178             "100:11: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
2179             "101:8: " + getCheckMessage(MSG_ERROR, "else rcurly", 7, 8),
2180             "104:6: " + getCheckMessage(MSG_ERROR, "if", 5, 8),
2181             "105:12: " + getCheckMessage(MSG_ERROR, "if rcurly", 11, 8),
2182             "106:6: " + getCheckMessage(MSG_ERROR, "else", 5, 8),
2183             "107:12: " + getCheckMessage(MSG_ERROR, "else rcurly", 11, 8),
2184         };
2185         verifyWarns(checkConfig, fileName, expected);
2186     }
2187 
2188     @Test
2189     public void testInvalidIfWithChecker1()
2190             throws Exception {
2191         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2192 
2193         checkConfig.addProperty("arrayInitIndent", "4");
2194         checkConfig.addProperty("basicOffset", "4");
2195         checkConfig.addProperty("braceAdjustment", "0");
2196         checkConfig.addProperty("caseIndent", "4");
2197         checkConfig.addProperty("forceStrictCondition", "false");
2198         checkConfig.addProperty("lineWrappingIndentation", "4");
2199         checkConfig.addProperty("tabWidth", "4");
2200         checkConfig.addProperty("throwsIndent", "4");
2201         final String fileName = getPath("InputIndentationInvalidIfIndent1.java");
2202         final String[] expected = {
2203             "37:15: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
2204             "42:11: " + getCheckMessage(MSG_ERROR, "if lcurly", 10, 8),
2205             "43:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2206             "48:15: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
2207             "49:11: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
2208             "51:11: " + getCheckMessage(MSG_CHILD_ERROR, "else", 10, 12),
2209             "52:9: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 12),
2210 
2211             "59:17: " + getCheckMessage(MSG_CHILD_ERROR, "if", 16, 12),
2212             "60:10: " + getCheckMessage(MSG_ERROR, "if rcurly", 9, 8),
2213             "63:17: " + getCheckMessage(MSG_CHILD_ERROR, "else", 16, 12),
2214             "69:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
2215             "73:41: " + getCheckMessage(MSG_CHILD_ERROR, "else", 40, 12),
2216             "80:15: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
2217 
2218             "83:15: " + getCheckMessage(MSG_CHILD_ERROR, "else", 14, 12),
2219             "89:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2220             "91:11: " + getCheckMessage(MSG_CHILD_ERROR, "else", 10, 12),
2221             "95:11: " + getCheckMessage(MSG_ERROR, "if", 10, 8),
2222             "96:15: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
2223             "97:11: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
2224             "98:11: " + getCheckMessage(MSG_ERROR, "else", 10, 8),
2225             "99:15: " + getCheckMessage(MSG_CHILD_ERROR, "else", 14, 12),
2226             "100:11: " + getCheckMessage(MSG_ERROR, "else rcurly", 10, 8),
2227         };
2228         verifyWarns(checkConfig, fileName, expected);
2229     }
2230 
2231     @Test
2232     public void testInvalidIfWithChecker2()
2233             throws Exception {
2234         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2235 
2236         checkConfig.addProperty("arrayInitIndent", "4");
2237         checkConfig.addProperty("basicOffset", "4");
2238         checkConfig.addProperty("braceAdjustment", "0");
2239         checkConfig.addProperty("caseIndent", "4");
2240         checkConfig.addProperty("forceStrictCondition", "false");
2241         checkConfig.addProperty("lineWrappingIndentation", "4");
2242         checkConfig.addProperty("tabWidth", "4");
2243         checkConfig.addProperty("throwsIndent", "4");
2244         final String fileName = getPath("InputIndentationInvalidIfIndent2.java");
2245         final String[] expected = {
2246             "26:10: " + getCheckMessage(MSG_CHILD_ERROR, "if", 9, 12),
2247             "27:12: " + getCheckMessage(MSG_CHILD_ERROR, "if", 11, 12),
2248             "31:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2249             "34:8: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
2250             "41:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2251             "43:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2252 
2253             "50:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2254             "59:11: " + getCheckMessage(MSG_ERROR, "if", 10, 12),
2255             "63:19: " + getCheckMessage(MSG_CHILD_ERROR, "if", 18, 20),
2256             "74:11: " + getCheckMessage(MSG_ERROR, "if rparen", 10, 8),
2257             "79:7: " + getCheckMessage(MSG_ERROR, "if rparen", 6, 8),
2258             "85:7: " + getCheckMessage(MSG_ERROR, "if lparen", 6, 8),
2259             "87:7: " + getCheckMessage(MSG_ERROR, "if rparen", 6, 8),
2260             "90:1: " + getCheckMessage(MSG_ERROR, "if", 0, 8),
2261             "91:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
2262             "92:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
2263             "93:1: " + getCheckMessage(MSG_ERROR, "if rcurly", 0, 8),
2264             "94:1: " + getCheckMessage(MSG_ERROR, "if", 0, 8),
2265             "95:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
2266             "96:1: " + getCheckMessage(MSG_ERROR, "else", 0, 8),
2267             "97:1: " + getCheckMessage(MSG_CHILD_ERROR, "else", 0, 12),
2268         };
2269         verifyWarns(checkConfig, fileName, expected);
2270     }
2271 
2272     @Test
2273     public void testInvalidWhileWithChecker()
2274             throws Exception {
2275         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2276 
2277         checkConfig.addProperty("arrayInitIndent", "4");
2278         checkConfig.addProperty("basicOffset", "4");
2279         checkConfig.addProperty("braceAdjustment", "0");
2280         checkConfig.addProperty("caseIndent", "4");
2281         checkConfig.addProperty("forceStrictCondition", "false");
2282         checkConfig.addProperty("lineWrappingIndentation", "4");
2283         checkConfig.addProperty("tabWidth", "4");
2284         checkConfig.addProperty("throwsIndent", "4");
2285         final String fileName = getPath("InputIndentationInvalidWhileIndent.java");
2286         final String[] expected = {
2287             "25:10: " + getCheckMessage(MSG_ERROR, "while", 9, 8),
2288             "26:8: " + getCheckMessage(MSG_ERROR, "while rcurly", 7, 8),
2289             "28:8: " + getCheckMessage(MSG_ERROR, "while", 7, 8),
2290             "29:10: " + getCheckMessage(MSG_ERROR, "while lcurly", 9, 8),
2291             "30:10: " + getCheckMessage(MSG_ERROR, "while rcurly", 9, 8),
2292 
2293             "32:10: " + getCheckMessage(MSG_ERROR, "while", 9, 8),
2294             "33:7: " + getCheckMessage(MSG_ERROR, "while lcurly", 6, 8),
2295             "34:15: " + getCheckMessage(MSG_CHILD_ERROR, "while", 14, 12),
2296             "35:7: " + getCheckMessage(MSG_ERROR, "while rcurly", 6, 8),
2297 
2298             "37:11: " + getCheckMessage(MSG_ERROR, "while", 10, 8),
2299             "39:11: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
2300             "41:11: " + getCheckMessage(MSG_ERROR, "while", 10, 8),
2301             "44:11: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
2302 
2303             "46:7: " + getCheckMessage(MSG_ERROR, "while", 6, 8),
2304             "47:11: " + getCheckMessage(MSG_ERROR, "while lcurly", 10, 8),
2305             "50:7: " + getCheckMessage(MSG_ERROR, "while rcurly", 6, 8),
2306             "53:15: " + getCheckMessage(MSG_ERROR, "if", 14, 12),
2307             "54:19: " + getCheckMessage(MSG_CHILD_ERROR, "if", 18, 16),
2308             "55:15: " + getCheckMessage(MSG_ERROR, "if rcurly", 14, 12),
2309             "56:15: " + getCheckMessage(MSG_CHILD_ERROR, "while", 14, 12),
2310             "57:11: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
2311 
2312             "60:11: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
2313             "66:11: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
2314             "71:11: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
2315             "78:6: " + getCheckMessage(MSG_ERROR, "while rparen", 5, 8),
2316             "85:11: " + getCheckMessage(MSG_ERROR, "while rparen", 10, 8),
2317             "92:11: " + getCheckMessage(MSG_ERROR, "while rparen", 10, 8),
2318             "99:9: " + getCheckMessage(MSG_CHILD_ERROR, "while", 8, 12),
2319         };
2320         verifyWarns(checkConfig, fileName, expected);
2321     }
2322 
2323     @Test
2324     public void testInvalidInvalidAnonymousClass() throws Exception {
2325         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2326 
2327         checkConfig.addProperty("arrayInitIndent", "4");
2328         checkConfig.addProperty("basicOffset", "4");
2329         checkConfig.addProperty("braceAdjustment", "0");
2330         checkConfig.addProperty("caseIndent", "4");
2331         checkConfig.addProperty("forceStrictCondition", "false");
2332         checkConfig.addProperty("lineWrappingIndentation", "4");
2333         checkConfig.addProperty("tabWidth", "4");
2334         checkConfig.addProperty("throwsIndent", "4");
2335         final String fileName = getPath("InputIndentationInvalidAnonymousClassIndent.java");
2336         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2337         verifyWarns(checkConfig, fileName, expected);
2338     }
2339 
2340     @Test
2341     public void testInvalidForWithChecker()
2342             throws Exception {
2343         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2344 
2345         checkConfig.addProperty("arrayInitIndent", "4");
2346         checkConfig.addProperty("basicOffset", "4");
2347         checkConfig.addProperty("braceAdjustment", "0");
2348         checkConfig.addProperty("caseIndent", "4");
2349         checkConfig.addProperty("forceStrictCondition", "false");
2350         checkConfig.addProperty("lineWrappingIndentation", "4");
2351         checkConfig.addProperty("tabWidth", "4");
2352         checkConfig.addProperty("throwsIndent", "4");
2353         final String fileName = getPath("InputIndentationInvalidForIndent.java");
2354         final String[] expected = {
2355             "27:7: " + getCheckMessage(MSG_ERROR, "for", 6, 8),
2356             "28:11: " + getCheckMessage(MSG_ERROR, "for rcurly", 10, 8),
2357             "30:10: " + getCheckMessage(MSG_ERROR, "for", 9, 8),
2358             "31:7: " + getCheckMessage(MSG_ERROR, "for lcurly", 6, 8),
2359             "32:7: " + getCheckMessage(MSG_ERROR, "for rcurly", 6, 8),
2360             "36:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2361 
2362             "37:11: " + getCheckMessage(MSG_ERROR, "for rcurly", 10, 8),
2363             "40:11: " + getCheckMessage(MSG_ERROR, "for lcurly", 10, 8),
2364             "41:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2365             "49:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2366             "55:8: " + getCheckMessage(MSG_ERROR, "for", 7, 8),
2367 
2368             "56:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2369             "65:8: " + getCheckMessage(MSG_CHILD_ERROR, "for", 7, 12),
2370 
2371             "70:7: " + getCheckMessage(MSG_ERROR, "for", 6, 8),
2372             "71:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2373             "72:15: " + getCheckMessage(MSG_CHILD_ERROR, "for", 14, 16),
2374             "73:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2375             "82:13: " + getCheckMessage(MSG_ERROR, "for rparen", 12, 8),
2376             "87:3: " + getCheckMessage(MSG_ERROR, "method def modifier", 2, 4),
2377             "88:5: " + getCheckMessage(MSG_ERROR, "for", 4, 8),
2378             "89:9: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 12),
2379             "90:7: " + getCheckMessage(MSG_CHILD_ERROR, "for", 6, 12),
2380             "91:9: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 16),
2381             "93:1: " + getCheckMessage(MSG_ERROR, "for", 0, 8),
2382             "94:1: " + getCheckMessage(MSG_ERROR, "for lparen", 0, 8),
2383             "95:1: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
2384             "96:1: " + getCheckMessage(MSG_ERROR, ";", 0, 4),
2385             "97:1: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
2386             "98:1: " + getCheckMessage(MSG_ERROR, ";", 0, 4),
2387             "99:1: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
2388         };
2389         verifyWarns(checkConfig, fileName, expected);
2390     }
2391 
2392     @Test
2393     public void testValidForWithChecker()
2394             throws Exception {
2395         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2396 
2397         checkConfig.addProperty("arrayInitIndent", "4");
2398         checkConfig.addProperty("basicOffset", "4");
2399         checkConfig.addProperty("braceAdjustment", "0");
2400         checkConfig.addProperty("caseIndent", "4");
2401         checkConfig.addProperty("forceStrictCondition", "false");
2402         checkConfig.addProperty("lineWrappingIndentation", "4");
2403         checkConfig.addProperty("tabWidth", "4");
2404         checkConfig.addProperty("throwsIndent", "4");
2405         final String fileName = getPath("InputIndentationValidForIndent.java");
2406         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2407         verifyWarns(checkConfig, fileName, expected);
2408     }
2409 
2410     @Test
2411     public void testValidDoWhileWithChecker()
2412             throws Exception {
2413         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2414 
2415         checkConfig.addProperty("arrayInitIndent", "4");
2416         checkConfig.addProperty("basicOffset", "4");
2417         checkConfig.addProperty("braceAdjustment", "0");
2418         checkConfig.addProperty("caseIndent", "4");
2419         checkConfig.addProperty("forceStrictCondition", "false");
2420         checkConfig.addProperty("lineWrappingIndentation", "4");
2421         checkConfig.addProperty("tabWidth", "4");
2422         checkConfig.addProperty("throwsIndent", "4");
2423         final String fileName = getPath("InputIndentationValidDoWhileIndent.java");
2424         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2425         verifyWarns(checkConfig, fileName, expected);
2426     }
2427 
2428     @Test
2429     public void testInvalidDoWhileWithChecker()
2430             throws Exception {
2431         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2432 
2433         checkConfig.addProperty("arrayInitIndent", "4");
2434         checkConfig.addProperty("basicOffset", "4");
2435         checkConfig.addProperty("braceAdjustment", "0");
2436         checkConfig.addProperty("caseIndent", "4");
2437         checkConfig.addProperty("forceStrictCondition", "false");
2438         checkConfig.addProperty("lineWrappingIndentation", "4");
2439         checkConfig.addProperty("tabWidth", "4");
2440         checkConfig.addProperty("throwsIndent", "4");
2441         final String fileName = getPath("InputIndentationInvalidDoWhileIndent.java");
2442         final String[] expected = {
2443             "7:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2444             "8:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2445             "9:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2446             "10:1: " + getCheckMessage(MSG_ERROR, "do..while rcurly", 0, 8),
2447             "11:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2448             "12:1: " + getCheckMessage(MSG_ERROR, "do..while while", 0, 8),
2449             "13:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2450             "14:1: " + getCheckMessage(MSG_ERROR, "do..while lcurly", 0, 8),
2451             "15:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2452             "16:1: " + getCheckMessage(MSG_ERROR, "do..while while", 0, 8),
2453             "17:1: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
2454             "18:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2455             "19:1: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
2456             "20:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2457             "21:1: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
2458             "22:1: " + getCheckMessage(MSG_CHILD_ERROR, "do..while", 0, 8),
2459             "23:1: " + getCheckMessage(MSG_ERROR, "do..while rparen", 0, 8),
2460         };
2461         verifyWarns(checkConfig, fileName, expected);
2462     }
2463 
2464     @Test
2465     public void testValidBlockWithChecker()
2466             throws Exception {
2467         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2468 
2469         checkConfig.addProperty("arrayInitIndent", "4");
2470         checkConfig.addProperty("basicOffset", "4");
2471         checkConfig.addProperty("braceAdjustment", "0");
2472         checkConfig.addProperty("caseIndent", "4");
2473         checkConfig.addProperty("forceStrictCondition", "false");
2474         checkConfig.addProperty("lineWrappingIndentation", "4");
2475         checkConfig.addProperty("tabWidth", "4");
2476         checkConfig.addProperty("throwsIndent", "4");
2477         final String fileName = getPath("InputIndentationValidBlockIndent.java");
2478         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2479         verifyWarns(checkConfig, fileName, expected);
2480     }
2481 
2482     @Test
2483     public void testValidBlockWithChecker1()
2484             throws Exception {
2485         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2486 
2487         checkConfig.addProperty("arrayInitIndent", "4");
2488         checkConfig.addProperty("basicOffset", "4");
2489         checkConfig.addProperty("braceAdjustment", "0");
2490         checkConfig.addProperty("caseIndent", "4");
2491         checkConfig.addProperty("forceStrictCondition", "false");
2492         checkConfig.addProperty("lineWrappingIndentation", "4");
2493         checkConfig.addProperty("tabWidth", "4");
2494         checkConfig.addProperty("throwsIndent", "4");
2495         final String fileName = getPath("InputIndentationValidBlockIndent1.java");
2496         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2497         verifyWarns(checkConfig, fileName, expected);
2498     }
2499 
2500     @Test
2501     public void testValidWhileWithChecker()
2502             throws Exception {
2503         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2504 
2505         checkConfig.addProperty("arrayInitIndent", "4");
2506         checkConfig.addProperty("basicOffset", "4");
2507         checkConfig.addProperty("braceAdjustment", "0");
2508         checkConfig.addProperty("caseIndent", "4");
2509         checkConfig.addProperty("forceStrictCondition", "false");
2510         checkConfig.addProperty("lineWrappingIndentation", "4");
2511         checkConfig.addProperty("tabWidth", "4");
2512         checkConfig.addProperty("throwsIndent", "4");
2513         final String fileName = getPath("InputIndentationValidWhileIndent.java");
2514         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2515         verifyWarns(checkConfig, fileName, expected);
2516     }
2517 
2518     @Test
2519     public void testValidClassDefWithChecker()
2520             throws Exception {
2521         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2522 
2523         checkConfig.addProperty("arrayInitIndent", "4");
2524         checkConfig.addProperty("basicOffset", "4");
2525         checkConfig.addProperty("braceAdjustment", "0");
2526         checkConfig.addProperty("caseIndent", "4");
2527         checkConfig.addProperty("forceStrictCondition", "false");
2528         checkConfig.addProperty("lineWrappingIndentation", "4");
2529         checkConfig.addProperty("tabWidth", "4");
2530         checkConfig.addProperty("throwsIndent", "4");
2531         final String fileName = getPath("InputIndentationValidClassDefIndent.java");
2532         final String[] expected = {
2533             "38:9: " + getCheckMessage(MSG_ERROR, "int", 8, 12),
2534         };
2535         verifyWarns(checkConfig, fileName, expected);
2536     }
2537 
2538     @Test
2539     public void testValidClassDefWithChecker1()
2540             throws Exception {
2541         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2542 
2543         checkConfig.addProperty("arrayInitIndent", "4");
2544         checkConfig.addProperty("basicOffset", "4");
2545         checkConfig.addProperty("braceAdjustment", "0");
2546         checkConfig.addProperty("caseIndent", "4");
2547         checkConfig.addProperty("forceStrictCondition", "false");
2548         checkConfig.addProperty("lineWrappingIndentation", "4");
2549         checkConfig.addProperty("tabWidth", "4");
2550         checkConfig.addProperty("throwsIndent", "4");
2551         final String fileName = getPath("InputIndentationValidClassDefIndent1.java");
2552         final String[] expected = {
2553             "43:1: " + getCheckMessage(MSG_ERROR, "class", 0, 4),
2554         };
2555         verifyWarns(checkConfig, fileName, expected);
2556     }
2557 
2558     @Test
2559     public void testValidInterfaceDefWithChecker()
2560             throws Exception {
2561         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2562 
2563         checkConfig.addProperty("arrayInitIndent", "4");
2564         checkConfig.addProperty("basicOffset", "4");
2565         checkConfig.addProperty("braceAdjustment", "0");
2566         checkConfig.addProperty("caseIndent", "4");
2567         checkConfig.addProperty("forceStrictCondition", "false");
2568         checkConfig.addProperty("lineWrappingIndentation", "4");
2569         checkConfig.addProperty("tabWidth", "4");
2570         checkConfig.addProperty("throwsIndent", "4");
2571         final String fileName = getPath("InputIndentationValidInterfaceDefIndent.java");
2572         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2573         verifyWarns(checkConfig, fileName, expected);
2574     }
2575 
2576     @Test
2577     public void testValidCommaWithChecker()
2578             throws Exception {
2579         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2580 
2581         checkConfig.addProperty("arrayInitIndent", "4");
2582         checkConfig.addProperty("basicOffset", "4");
2583         checkConfig.addProperty("braceAdjustment", "0");
2584         checkConfig.addProperty("caseIndent", "4");
2585         checkConfig.addProperty("forceStrictCondition", "false");
2586         checkConfig.addProperty("lineWrappingIndentation", "4");
2587         checkConfig.addProperty("tabWidth", "4");
2588         checkConfig.addProperty("throwsIndent", "4");
2589         final String fileName = getPath("InputIndentationValidCommaIndent.java");
2590         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2591         verifyWarns(checkConfig, fileName, expected);
2592     }
2593 
2594     @Test
2595     public void testTabs() throws Exception {
2596         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2597 
2598         checkConfig.addProperty("arrayInitIndent", "4");
2599         checkConfig.addProperty("basicOffset", "4");
2600         checkConfig.addProperty("braceAdjustment", "0");
2601         checkConfig.addProperty("caseIndent", "4");
2602         checkConfig.addProperty("forceStrictCondition", "false");
2603         checkConfig.addProperty("lineWrappingIndentation", "4");
2604         checkConfig.addProperty("tabWidth", "4");
2605         checkConfig.addProperty("throwsIndent", "4");
2606         final String[] expected = {
2607             "29:10: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 9, 8),
2608         };
2609         verifyWarns(checkConfig, getPath("InputIndentationUseTabs.java"), expected);
2610     }
2611 
2612     @Test
2613     public void testIndentationLevel() throws Exception {
2614         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2615 
2616         checkConfig.addProperty("arrayInitIndent", "4");
2617         checkConfig.addProperty("basicOffset", "2");
2618         checkConfig.addProperty("braceAdjustment", "0");
2619         checkConfig.addProperty("caseIndent", "4");
2620         checkConfig.addProperty("forceStrictCondition", "false");
2621         checkConfig.addProperty("lineWrappingIndentation", "2");
2622         checkConfig.addProperty("tabWidth", "4");
2623         checkConfig.addProperty("throwsIndent", "4");
2624         final String[] expected = {
2625             "29:6: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 5, 4),
2626         };
2627         verifyWarns(checkConfig, getPath("InputIndentationUseTwoSpaces.java"), expected);
2628     }
2629 
2630     @Test
2631     public void testThrowsIndentationLevel() throws Exception {
2632         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2633 
2634         checkConfig.addProperty("arrayInitIndent", "4");
2635         checkConfig.addProperty("basicOffset", "4");
2636         checkConfig.addProperty("braceAdjustment", "0");
2637         checkConfig.addProperty("caseIndent", "4");
2638         checkConfig.addProperty("forceStrictCondition", "false");
2639         checkConfig.addProperty("lineWrappingIndentation", "4");
2640         checkConfig.addProperty("tabWidth", "4");
2641         checkConfig.addProperty("throwsIndent", "8");
2642         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2643         verifyWarns(checkConfig, getPath("InputIndentationInvalidThrowsIndent.java"), expected);
2644     }
2645 
2646     @Test
2647     public void testThrowsIndentationLevel2() throws Exception {
2648         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2649 
2650         checkConfig.addProperty("basicOffset", "1");
2651         checkConfig.addProperty("forceStrictCondition", "true");
2652         checkConfig.addProperty("lineWrappingIndentation", "3");
2653         checkConfig.addProperty("tabWidth", "4");
2654         checkConfig.addProperty("throwsIndent", "5");
2655         final String[] expected = {
2656             "7:1: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
2657             "10:1: " + getCheckMessage(MSG_ERROR, "NullPointerException", 0, 6),
2658             "13:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2659             "16:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2660             "18:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2661             "19:1: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
2662             "22:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2663             "23:1: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
2664             "24:1: " + getCheckMessage(MSG_ERROR, "NullPointerException", 0, 6),
2665             "27:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2666             "28:1: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
2667             "31:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2668             "37:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2669         };
2670         verifyWarns(checkConfig, getPath("InputIndentationInvalidThrowsIndent2.java"), expected);
2671     }
2672 
2673     @Test
2674     public void testCaseLevel() throws Exception {
2675         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2676 
2677         checkConfig.addProperty("arrayInitIndent", "4");
2678         checkConfig.addProperty("basicOffset", "4");
2679         checkConfig.addProperty("braceAdjustment", "0");
2680         checkConfig.addProperty("caseIndent", "0");
2681         checkConfig.addProperty("forceStrictCondition", "false");
2682         checkConfig.addProperty("lineWrappingIndentation", "4");
2683         checkConfig.addProperty("tabWidth", "4");
2684         checkConfig.addProperty("throwsIndent", "4");
2685         final String[] expected = {
2686             "27:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 8),
2687         };
2688         verifyWarns(checkConfig, getPath("InputIndentationCaseLevel.java"), expected);
2689     }
2690 
2691     @Test
2692     public void testBraceAdjustment() throws Exception {
2693         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2694 
2695         checkConfig.addProperty("arrayInitIndent", "4");
2696         checkConfig.addProperty("basicOffset", "4");
2697         checkConfig.addProperty("braceAdjustment", "2");
2698         checkConfig.addProperty("caseIndent", "4");
2699         checkConfig.addProperty("forceStrictCondition", "false");
2700         checkConfig.addProperty("lineWrappingIndentation", "4");
2701         checkConfig.addProperty("tabWidth", "4");
2702         checkConfig.addProperty("throwsIndent", "4");
2703         final String[] expected = {
2704             "25:9: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 8, 10),
2705             "26:9: " + getCheckMessage(MSG_ERROR, "if", 8, 10),
2706             "27:11: " + getCheckMessage(MSG_ERROR, "if lcurly", 10, 12),
2707             "28:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "if", 12, "14, 16"),
2708             "29:9: " + getCheckMessage(MSG_ERROR, "if rcurly", 8, 12),
2709         };
2710         verifyWarns(checkConfig, getPath("InputIndentationBraceAdjustment.java"), expected);
2711     }
2712 
2713     @Test
2714     public void testInvalidAssignWithChecker() throws Exception {
2715         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2716 
2717         checkConfig.addProperty("arrayInitIndent", "4");
2718         checkConfig.addProperty("basicOffset", "4");
2719         checkConfig.addProperty("braceAdjustment", "0");
2720         checkConfig.addProperty("caseIndent", "4");
2721         checkConfig.addProperty("forceStrictCondition", "false");
2722         checkConfig.addProperty("lineWrappingIndentation", "4");
2723         checkConfig.addProperty("tabWidth", "4");
2724         checkConfig.addProperty("throwsIndent", "4");
2725         final String[] expected = {
2726             "22:11: " + getCheckMessage(MSG_ERROR, "getLineNo", 10, 12),
2727             "24:11: " + getCheckMessage(MSG_ERROR, "getLine", 10, 12),
2728             "28:10: " + getCheckMessage(MSG_ERROR, "=", 9, 12),
2729             "29:11: " + getCheckMessage(MSG_ERROR, "1", 10, 12),
2730         };
2731         verifyWarns(checkConfig, getPath("InputIndentationInvalidAssignIndent.java"), expected);
2732     }
2733 
2734     @Test
2735     public void testInvalidImportIndent() throws Exception {
2736         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2737         checkConfig.addProperty("basicOffset", "8");
2738         checkConfig.addProperty("tabWidth", "4");
2739         final String[] expected = {
2740             "4:3: " + getCheckMessage(MSG_ERROR, ".", 2, 4),
2741             "5:2: " + getCheckMessage(MSG_ERROR, "import", 1, 0),
2742         };
2743         verifyWarns(checkConfig, getPath("InputIndentationInvalidImportIndent.java"), expected);
2744     }
2745 
2746     @Test
2747     public void testValidAssignWithChecker() throws Exception {
2748         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2749 
2750         checkConfig.addProperty("arrayInitIndent", "4");
2751         checkConfig.addProperty("basicOffset", "4");
2752         checkConfig.addProperty("braceAdjustment", "0");
2753         checkConfig.addProperty("caseIndent", "4");
2754         checkConfig.addProperty("forceStrictCondition", "false");
2755         checkConfig.addProperty("lineWrappingIndentation", "4");
2756         checkConfig.addProperty("tabWidth", "4");
2757         checkConfig.addProperty("throwsIndent", "4");
2758         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2759         verifyWarns(checkConfig, getPath("InputIndentationValidAssignIndent.java"), expected);
2760     }
2761 
2762     @Test
2763     public void test15Extensions() throws Exception {
2764         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2765 
2766         checkConfig.addProperty("arrayInitIndent", "4");
2767         checkConfig.addProperty("basicOffset", "4");
2768         checkConfig.addProperty("braceAdjustment", "0");
2769         checkConfig.addProperty("caseIndent", "4");
2770         checkConfig.addProperty("forceStrictCondition", "false");
2771         checkConfig.addProperty("lineWrappingIndentation", "4");
2772         checkConfig.addProperty("tabWidth", "4");
2773         checkConfig.addProperty("throwsIndent", "4");
2774         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2775         verifyWarns(checkConfig, getPath("InputIndentation15Extensions.java"), expected);
2776     }
2777 
2778     @Test
2779     public void testTryResources() throws Exception {
2780         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2781 
2782         checkConfig.addProperty("arrayInitIndent", "4");
2783         checkConfig.addProperty("basicOffset", "4");
2784         checkConfig.addProperty("braceAdjustment", "0");
2785         checkConfig.addProperty("caseIndent", "4");
2786         checkConfig.addProperty("forceStrictCondition", "false");
2787         checkConfig.addProperty("lineWrappingIndentation", "4");
2788         checkConfig.addProperty("tabWidth", "4");
2789         checkConfig.addProperty("throwsIndent", "4");
2790         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2791         verifyWarns(checkConfig, getPath("InputIndentationValidTryResourcesIndent.java"),
2792                expected);
2793     }
2794 
2795     @Test
2796     public void testSwitchCustom() throws Exception {
2797         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2798 
2799         checkConfig.addProperty("arrayInitIndent", "4");
2800         checkConfig.addProperty("basicOffset", "4");
2801         checkConfig.addProperty("braceAdjustment", "0");
2802         checkConfig.addProperty("caseIndent", "4");
2803         checkConfig.addProperty("forceStrictCondition", "false");
2804         checkConfig.addProperty("lineWrappingIndentation", "8");
2805         checkConfig.addProperty("tabWidth", "4");
2806         checkConfig.addProperty("throwsIndent", "8");
2807         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2808         verifyWarns(checkConfig, getPath("InputIndentationSwitchCustom.java"),
2809                expected);
2810     }
2811 
2812     @Test
2813     public void testSynchronizedStatement() throws Exception {
2814         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2815         checkConfig.addProperty("arrayInitIndent", "4");
2816         checkConfig.addProperty("basicOffset", "4");
2817         checkConfig.addProperty("braceAdjustment", "0");
2818         checkConfig.addProperty("caseIndent", "4");
2819         checkConfig.addProperty("forceStrictCondition", "false");
2820         checkConfig.addProperty("lineWrappingIndentation", "8");
2821         checkConfig.addProperty("tabWidth", "4");
2822         checkConfig.addProperty("throwsIndent", "8");
2823         final String[] expected = {
2824             "27:1: " + getCheckMessage(MSG_CHILD_ERROR, "synchronized", 0, 12),
2825             "30:13: " + getCheckMessage(MSG_ERROR, "synchronized lparen", 12, 8),
2826         };
2827         verifyWarns(checkConfig, getPath("InputIndentationSynchronizedStatement.java"), expected);
2828     }
2829 
2830     @Test
2831     public void testSynchronizedMethod() throws Exception {
2832         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2833         checkConfig.addProperty("arrayInitIndent", "4");
2834         checkConfig.addProperty("basicOffset", "4");
2835         checkConfig.addProperty("braceAdjustment", "0");
2836         checkConfig.addProperty("caseIndent", "4");
2837         checkConfig.addProperty("forceStrictCondition", "false");
2838         checkConfig.addProperty("lineWrappingIndentation", "8");
2839         checkConfig.addProperty("tabWidth", "4");
2840         checkConfig.addProperty("throwsIndent", "8");
2841         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2842         verifyWarns(checkConfig, getPath("InputIndentationSynchronizedMethod.java"), expected);
2843     }
2844 
2845     @Test
2846     public void testAnonymousClassInMethod() throws Exception {
2847         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2848         checkConfig.addProperty("tabWidth", "8");
2849         checkConfig.addProperty("basicOffset", "2");
2850         checkConfig.addProperty("braceAdjustment", "0");
2851         checkConfig.addProperty("caseIndent", "2");
2852         checkConfig.addProperty("lineWrappingIndentation", "4");
2853         checkConfig.addProperty("throwsIndent", "4");
2854         checkConfig.addProperty("arrayInitIndent", "2");
2855         final String[] expected = {
2856             "19:9: " + getCheckMessage(MSG_ERROR, "method def modifier", 8, 2),
2857             "20:17: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 16, 4),
2858             "21:25: " + getCheckMessage(MSG_ERROR_MULTI, "method def modifier", 24, "18, 20, 22"),
2859             "23:33: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "method def", 32, "20, 22, 24"),
2860             "24:25: " + getCheckMessage(MSG_ERROR_MULTI, "method def rcurly", 24, "18, 20, 22"),
2861             "26:9: " + getCheckMessage(MSG_ERROR, "method def rcurly", 8, 2),
2862         };
2863         verifyWarns(checkConfig, getPath("InputIndentationAnonymousClassInMethod.java"), expected);
2864     }
2865 
2866     @Test
2867     public void testAnonymousClassInMethodWithCurlyOnNewLine() throws Exception {
2868         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2869         checkConfig.addProperty("tabWidth", "4");
2870         checkConfig.addProperty("basicOffset", "4");
2871         checkConfig.addProperty("braceAdjustment", "0");
2872         checkConfig.addProperty("caseIndent", "4");
2873         checkConfig.addProperty("lineWrappingIndentation", "8");
2874         checkConfig.addProperty("throwsIndent", "4");
2875         checkConfig.addProperty("arrayInitIndent", "4");
2876         final String[] expected = {
2877             "40:19: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 18, "16, 20, 24"),
2878             "42:15: " + getCheckMessage(MSG_ERROR, "new", 14, 16),
2879             "48:15: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 14, "16, 20, 24"),
2880             "60:19: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 18, "16, 20, 24"),
2881             "66:19: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 18, "16, 20, 24"),
2882             "69:15: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 14, "16, 20, 24"),
2883             "75:15: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 14, "16, 20, 24"),
2884         };
2885         verifyWarns(checkConfig,
2886             getPath("InputIndentationAnonymousClassInMethodCurlyOnNewLine.java"), expected);
2887     }
2888 
2889     @Test
2890     public void testAnnotationDefinition() throws Exception {
2891         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2892         checkConfig.addProperty("tabWidth", "4");
2893         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2894         verifyWarns(checkConfig, getPath("InputIndentationAnnotationDefinition.java"), expected);
2895     }
2896 
2897     @Test
2898     public void testPackageDeclaration() throws Exception {
2899         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2900         checkConfig.addProperty("tabWidth", "4");
2901         final String[] expected = {
2902             "1:2: " + getCheckMessage(MSG_ERROR, "package def", 1, 0),
2903         };
2904         verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration.java"), expected);
2905     }
2906 
2907     @Test
2908     public void testPackageDeclaration2() throws Exception {
2909         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2910         checkConfig.addProperty("tabWidth", "4");
2911         final String[] expected = {
2912             "2:2: " + getCheckMessage(MSG_ERROR, "package def", 1, 0),
2913         };
2914         verifyWarns(checkConfig,
2915             getPath("package-info.java"), expected);
2916     }
2917 
2918     @Test
2919     public void testPackageDeclaration3() throws Exception {
2920         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2921         checkConfig.addProperty("tabWidth", "4");
2922         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2923         verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration3.java"), expected);
2924     }
2925 
2926     @Test
2927     public void testPackageDeclaration4() throws Exception {
2928         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2929         checkConfig.addProperty("tabWidth", "4");
2930         final String[] expected = {
2931             "2:1: " + getCheckMessage(MSG_ERROR, "com", 0, 4),
2932             "3:1: " + getCheckMessage(MSG_ERROR, "checks", 0, 4),
2933         };
2934         verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration4.java"), expected);
2935     }
2936 
2937     @Test
2938     public void testLambda() throws Exception {
2939         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2940         checkConfig.addProperty("tabWidth", "2");
2941         checkConfig.addProperty("basicOffset", "2");
2942         checkConfig.addProperty("lineWrappingIndentation", "4");
2943         final String[] expected = {
2944             "37:6: " + getCheckMessage(MSG_ERROR_MULTI, "block lcurly", 5, "4, 8"),
2945             "38:6: " + getCheckMessage(MSG_ERROR_MULTI, "block rcurly", 5, "4, 8"),
2946             "42:12: " + getCheckMessage(MSG_ERROR, "lambda", 11, 12),
2947             "43:10: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
2948             "55:8: " + getCheckMessage(MSG_CHILD_ERROR, "block", 7, 6),
2949             "56:6: " + getCheckMessage(MSG_ERROR, "block rcurly", 5, 4),
2950         };
2951         verifyWarns(checkConfig, getPath("InputIndentationLambda.java"), expected);
2952     }
2953 
2954     @Test
2955     public void testLambda1() throws Exception {
2956         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2957         checkConfig.addProperty("tabWidth", "2");
2958         checkConfig.addProperty("basicOffset", "2");
2959         checkConfig.addProperty("lineWrappingIndentation", "4");
2960         final String[] expected = {
2961             "69:10: " + getCheckMessage(MSG_CHILD_ERROR, "block", 9, 10),
2962             "70:12: " + getCheckMessage(MSG_CHILD_ERROR, "block", 11, 10),
2963             "75:8: " + getCheckMessage(MSG_ERROR, "block rcurly", 7, 8),
2964         };
2965         verifyWarns(checkConfig, getPath("InputIndentationLambda1.java"), expected);
2966     }
2967 
2968     @Test
2969     public void testLambda2() throws Exception {
2970         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2971         checkConfig.addProperty("tabWidth", "4");
2972         checkConfig.addProperty("basicOffset", "4");
2973         checkConfig.addProperty("lineWrappingIndentation", "8");
2974         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2975         verifyWarns(checkConfig, getPath("InputIndentationLambda2.java"), expected);
2976     }
2977 
2978     @Test
2979     public void testLambda3() throws Exception {
2980         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2981         checkConfig.addProperty("tabWidth", "4");
2982         checkConfig.addProperty("basicOffset", "4");
2983         checkConfig.addProperty("lineWrappingIndentation", "8");
2984         final String[] expected = {
2985             "15:13: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
2986             "29:13: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
2987             "30:13: " + getCheckMessage(MSG_CHILD_ERROR, "block", 12, 16),
2988             "31:9: " + getCheckMessage(MSG_ERROR, "block rcurly", 8, 12),
2989             "65:13: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
2990             "87:13: " + getCheckMessage(MSG_ERROR, "method def rcurly", 12, 8),
2991         };
2992         verifyWarns(checkConfig, getPath("InputIndentationLambda3.java"), expected);
2993     }
2994 
2995     @Test
2996     public void testLambda4() throws Exception {
2997         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2998         checkConfig.addProperty("tabWidth", "4");
2999         checkConfig.addProperty("basicOffset", "4");
3000         checkConfig.addProperty("lineWrappingIndentation", "8");
3001         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3002         verifyWarns(checkConfig, getPath("InputIndentationLambda4.java"), expected);
3003     }
3004 
3005     @Test
3006     public void testLambda5() throws Exception {
3007         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3008         checkConfig.addProperty("tabWidth", "3");
3009         checkConfig.addProperty("basicOffset", "3");
3010         checkConfig.addProperty("caseIndent", "0");
3011         checkConfig.addProperty("lineWrappingIndentation", "6");
3012         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3013         verifyWarns(checkConfig, getPath("InputIndentationLambda5.java"), expected);
3014     }
3015 
3016     @Test
3017     public void testLambdaFalseForceStrictCondition() throws Exception {
3018         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3019         checkConfig.addProperty("tabWidth", "4");
3020         checkConfig.addProperty("basicOffset", "4");
3021         checkConfig.addProperty("braceAdjustment", "0");
3022         checkConfig.addProperty("forceStrictCondition", "false");
3023         checkConfig.addProperty("lineWrappingIndentation", "0");
3024         final String[] expected = {
3025             "34:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
3026             "35:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 12),
3027             "36:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
3028             "47:5: " + getCheckMessage(MSG_ERROR_MULTI, "block rcurly", 4, "8, 16"),
3029             "73:5: " + getCheckMessage(MSG_ERROR, "->", 4, 8),
3030         };
3031 
3032         verifyWarns(checkConfig, getPath("InputIndentationLambda6.java"), expected);
3033     }
3034 
3035     @Test
3036     public void testLambdaTrueForceStrictCondition() throws Exception {
3037         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3038         checkConfig.addProperty("tabWidth", "4");
3039         checkConfig.addProperty("basicOffset", "4");
3040         checkConfig.addProperty("braceAdjustment", "0");
3041         checkConfig.addProperty("forceStrictCondition", "true");
3042         checkConfig.addProperty("lineWrappingIndentation", "4");
3043         final String[] expected = {
3044             "23:17: " + getCheckMessage(MSG_ERROR, "(", 16, 12),
3045             "24:17: " + getCheckMessage(MSG_ERROR, "->", 16, 12),
3046             "26:27: " + getCheckMessage(MSG_ERROR, "\"SECOND_ARG\"", 26, 12),
3047             "27:26: " + getCheckMessage(MSG_ERROR, "(", 25, 12),
3048             "30:17: " + getCheckMessage(MSG_ERROR, "(", 16, 12),
3049             "31:21: " + getCheckMessage(MSG_ERROR, "if", 20, 16),
3050             "32:25: " + getCheckMessage(MSG_CHILD_ERROR, "if", 24, 20),
3051             "33:21: " + getCheckMessage(MSG_ERROR, "if rcurly", 20, 16),
3052             "34:25: " + getCheckMessage(MSG_CHILD_ERROR, "else", 24, 20),
3053             "35:21: " + getCheckMessage(MSG_ERROR, "else rcurly", 20, 16),
3054             "36:17: " + getCheckMessage(MSG_ERROR, "block rcurly", 16, 12),
3055             "39:17: " + getCheckMessage(MSG_ERROR, "(", 16, 12),
3056             "40:17: " + getCheckMessage(MSG_ERROR, "->", 16, 12),
3057             "41:21: " + getCheckMessage(MSG_ERROR, "if", 20, 16),
3058             "44:1: " + getCheckMessage(MSG_ERROR, "block rcurly", 0, 12),
3059         };
3060 
3061         verifyWarns(checkConfig, getPath("InputIndentationLambda7.java"), expected);
3062     }
3063 
3064     @Test
3065     public void testLambdaOddConditions() throws Exception {
3066         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3067         checkConfig.addProperty("tabWidth", "4");
3068         checkConfig.addProperty("basicOffset", "3");
3069         checkConfig.addProperty("braceAdjustment", "0");
3070         checkConfig.addProperty("forceStrictCondition", "false");
3071         checkConfig.addProperty("lineWrappingIndentation", "7");
3072         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3073 
3074         verifyWarns(checkConfig, getPath("InputIndentationLambda8.java"), expected);
3075     }
3076 
3077     @Test
3078     public void testSeparatedStatements() throws Exception {
3079         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3080         checkConfig.addProperty("tabWidth", "4");
3081         final String fileName = getPath("InputIndentationSeparatedStatements.java");
3082         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3083         verifyWarns(checkConfig, fileName, expected);
3084     }
3085 
3086     @Test
3087     public void testSeparatedLineWithJustSpaces() throws Exception {
3088         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3089         checkConfig.addProperty("tabWidth", "4");
3090         final String fileName = getPath("InputIndentationSeparatedStatementWithSpaces.java");
3091         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3092         verifyWarns(checkConfig, fileName, expected);
3093     }
3094 
3095     @Test
3096     public void testTwoStatementsPerLine() throws Exception {
3097         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3098         checkConfig.addProperty("tabWidth", "4");
3099         checkConfig.addProperty("basicOffset", "4");
3100         final String fileName = getPath("InputIndentationTwoStatementsPerLine.java");
3101         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3102         verifyWarns(checkConfig, fileName, expected);
3103     }
3104 
3105     @Test
3106     public void testMethodChaining() throws Exception {
3107         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3108         checkConfig.addProperty("tabWidth", "4");
3109         checkConfig.addProperty("basicOffset", "4");
3110         final String fileName = getPath("InputIndentationChainedMethods.java");
3111         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3112         verifyWarns(checkConfig, fileName, expected);
3113     }
3114 
3115     @Test
3116     public void testMultipleAnnotationsWithWrappedLines() throws Exception {
3117         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3118         checkConfig.addProperty("tabWidth", "4");
3119         checkConfig.addProperty("basicOffset", "4");
3120         checkConfig.addProperty("forceStrictCondition", "true");
3121         final String fileName =
3122             getPath("InputIndentationCorrectMultipleAnnotationsWithWrappedLines.java");
3123         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3124         verifyWarns(checkConfig, fileName, expected);
3125     }
3126 
3127     @Test
3128     public void testMultipleAnnotationsWithWrappedLines1() throws Exception {
3129         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3130         checkConfig.addProperty("tabWidth", "4");
3131         checkConfig.addProperty("basicOffset", "4");
3132         checkConfig.addProperty("forceStrictCondition", "true");
3133         final String fileName =
3134             getPath("InputIndentationCorrectMultipleAnnotationsWithWrappedLines1.java");
3135         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3136         verifyWarns(checkConfig, fileName, expected);
3137     }
3138 
3139     @Test
3140     public void testMethodPrecedeByAnnotationsWithParameterOnSeparateLine() throws Exception {
3141         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3142         checkConfig.addProperty("tabWidth", "4");
3143         checkConfig.addProperty("basicOffset", "2");
3144         checkConfig.addProperty("braceAdjustment", "0");
3145         checkConfig.addProperty("caseIndent", "2");
3146         checkConfig.addProperty("throwsIndent", "4");
3147         checkConfig.addProperty("lineWrappingIndentation", "4");
3148         checkConfig.addProperty("arrayInitIndent", "2");
3149         final String fileName =
3150             getPath("InputIndentationMethodPrecededByAnnotationWithParameterOnSeparateLine.java");
3151         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3152         verifyWarns(checkConfig, fileName, expected);
3153     }
3154 
3155     @Test
3156     public void testAnnotationIncorrect() throws Exception {
3157         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3158         checkConfig.addProperty("tabWidth", "4");
3159         checkConfig.addProperty("basicOffset", "4");
3160         checkConfig.addProperty("braceAdjustment", "0");
3161         checkConfig.addProperty("lineWrappingIndentation", "4");
3162         final String fileName =
3163             getPath("InputIndentationAnnotationIncorrect.java");
3164         final String[] expected = {
3165             "11:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
3166             "14:9: " + getCheckMessage(MSG_ERROR, "(", 8, 12),
3167             "19:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
3168         };
3169         verifyWarns(checkConfig, fileName, expected);
3170     }
3171 
3172     @Test
3173     public void testInputAnnotationScopeIndentationCheck() throws Exception {
3174         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3175         checkConfig.addProperty("tabWidth", "4");
3176         checkConfig.addProperty("basicOffset", "4");
3177         checkConfig.addProperty("forceStrictCondition", "true");
3178         final String fileName = getPath("InputIndentationAnnotationScopeIndentationCheck.java");
3179         final String[] expected = {
3180             "9:9: " + getCheckMessage(MSG_ERROR_MULTI,
3181                     "annotation array initialization rcurly", 8, "0, 4"),
3182         };
3183         verifyWarns(checkConfig, fileName, expected);
3184     }
3185 
3186     @Test
3187     public void testInputAnnotationDefIndentationCheck() throws Exception {
3188         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3189         checkConfig.addProperty("tabWidth", "4");
3190         checkConfig.addProperty("arrayInitIndent", "4");
3191         checkConfig.addProperty("basicOffset", "4");
3192         checkConfig.addProperty("braceAdjustment", "0");
3193         checkConfig.addProperty("lineWrappingIndentation", "4");
3194         checkConfig.addProperty("forceStrictCondition", "true");
3195         final String fileName = getPath("InputIndentationCustomAnnotation.java");
3196         final String[] expected = {
3197             "14:6: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 0),
3198             "16:6: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
3199             "17:6: " + getCheckMessage(MSG_ERROR, "@", 5, 0),
3200             "18:1: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 0, 4),
3201             "19:6: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
3202             "21:4: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 0),
3203             "23:1: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 0, 4),
3204             "24:6: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
3205             "26:6: " + getCheckMessage(MSG_ERROR, "@", 5, 0),
3206             "27:6: " + getCheckMessage(MSG_ERROR, "AnnotationWithLineWrap", 5, 0),
3207             "31:6: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 0),
3208             "32:4: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 0),
3209             "35:6: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 5, 4),
3210             "36:4: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 4),
3211             "37:1: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 0, 4),
3212             "38:1: " + getCheckMessage(MSG_ERROR, "@", 0, 4),
3213             "39:9: " + getCheckMessage(MSG_ERROR, "AnnotationInnerLineWrap", 8, 4),
3214             "42:8: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 7, 8),
3215             "60:5: " + getCheckMessage(MSG_ERROR, "AnnotationInnerLineWrap2", 4, 0),
3216             "61:4: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 3, 4),
3217             "62:8: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 7, 4),
3218             "64:5: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 4, 0),
3219             "75:4: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 4),
3220             "91:29: " + getCheckMessage(MSG_ERROR_MULTI, "new", 28, "20, 24"),
3221         };
3222         verifyWarns(checkConfig, fileName, expected);
3223     }
3224 
3225     @Test
3226     public void testInputAnnotationDefIndentationCheck1() throws Exception {
3227         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3228         checkConfig.addProperty("tabWidth", "4");
3229         checkConfig.addProperty("arrayInitIndent", "4");
3230         checkConfig.addProperty("basicOffset", "4");
3231         checkConfig.addProperty("braceAdjustment", "0");
3232         checkConfig.addProperty("lineWrappingIndentation", "4");
3233         checkConfig.addProperty("forceStrictCondition", "true");
3234         final String fileName = getPath("InputIndentationCustomAnnotation1.java");
3235         final String[] expected = {
3236             "36:6: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 4),
3237             "47:2: " + getCheckMessage(MSG_ERROR, "interface", 1, 0),
3238             "53:12: " + getCheckMessage(MSG_ERROR, "@", 11, 0),
3239             "56:17: " + getCheckMessage(MSG_ERROR, "@", 16, 0),
3240             "63:13: " + getCheckMessage(MSG_ERROR, "@", 12, 4),
3241             "67:23: " + getCheckMessage(MSG_ERROR, "class def ident", 16, 0),
3242         };
3243         verifyWarns(checkConfig, fileName, expected);
3244     }
3245 
3246     @Test
3247     public void testTryResourcesStrict() throws Exception {
3248         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3249         checkConfig.addProperty("tabWidth", "4");
3250         checkConfig.addProperty("forceStrictCondition", "true");
3251         checkConfig.addProperty("braceAdjustment", "0");
3252         checkConfig.addProperty("lineWrappingIndentation", "4");
3253         final String fileName = getPath("InputIndentationTryWithResourcesStrict.java");
3254         final String[] expected = {
3255             "26:1: " + getCheckMessage(MSG_ERROR, "try resource", 0, 12),
3256             "28:14: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 13, "8, 12"),
3257             "33:1: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 16),
3258             "39:1: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 12),
3259             "59:21: " + getCheckMessage(MSG_ERROR, "try resource", 20, 16),
3260             "79:14: " + getCheckMessage(MSG_ERROR, ".", 13, 12),
3261             "85:12: " + getCheckMessage(MSG_ERROR, ".", 11, 12),
3262         };
3263         verifyWarns(checkConfig, fileName, expected);
3264     }
3265 
3266     @Test
3267     public void testTryResourcesStrict1() throws Exception {
3268         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3269         checkConfig.addProperty("tabWidth", "4");
3270         checkConfig.addProperty("forceStrictCondition", "true");
3271         checkConfig.addProperty("braceAdjustment", "0");
3272         checkConfig.addProperty("lineWrappingIndentation", "4");
3273         final String fileName = getPath("InputIndentationTryWithResourcesStrict1.java");
3274         final String[] expected = {
3275             "31:20: " + getCheckMessage(MSG_ERROR, "writ", 19, 12),
3276             "38:20: " + getCheckMessage(MSG_ERROR, "writ", 19, 16),
3277             "45:22: " + getCheckMessage(MSG_ERROR, "writ", 21, 16),
3278             "60:18: " + getCheckMessage(MSG_ERROR, "zipFileName", 17, 16),
3279             "67:16: " + getCheckMessage(MSG_ERROR, "zipFileName", 15, 16),
3280             "77:8: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
3281             "82:16: " + getCheckMessage(MSG_CHILD_ERROR, "try", 15, 12),
3282             "88:12: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
3283             "89:10: " + getCheckMessage(MSG_CHILD_ERROR, "try", 9, 12),
3284             "93:12: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
3285             "94:12: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 11, 16),
3286             "95:14: " + getCheckMessage(MSG_CHILD_ERROR, "try", 13, 12),
3287             "97:8: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
3288             "98:8: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 7, "8, 12"),
3289             "102:10: " + getCheckMessage(MSG_ERROR, "try", 9, 8),
3290         };
3291         verifyWarns(checkConfig, fileName, expected);
3292     }
3293 
3294     @Test
3295     public void testTryResourcesNotStrict() throws Exception {
3296         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3297         checkConfig.addProperty("tabWidth", "4");
3298         checkConfig.addProperty("braceAdjustment", "0");
3299         checkConfig.addProperty("lineWrappingIndentation", "4");
3300         final String fileName = getPath("InputIndentationTryResourcesNotStrict.java");
3301         final String[] expected = {
3302             "26:1: " + getCheckMessage(MSG_ERROR, "try resource", 0, 12),
3303             "32:1: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 16),
3304             "38:1: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 12),
3305         };
3306         verifyWarns(checkConfig, fileName, expected);
3307     }
3308 
3309     @Test
3310     public void testTryResourcesNotStrict1() throws Exception {
3311         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3312         checkConfig.addProperty("tabWidth", "4");
3313         checkConfig.addProperty("braceAdjustment", "0");
3314         checkConfig.addProperty("lineWrappingIndentation", "4");
3315         final String fileName = getPath("InputIndentationTryResourcesNotStrict1.java");
3316         final String[] expected = {
3317             "44:16: " + getCheckMessage(MSG_ERROR, "zipFileName", 15, 16),
3318             "54:8: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
3319             "59:16: " + getCheckMessage(MSG_CHILD_ERROR, "try", 15, 12),
3320             "65:12: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
3321             "66:10: " + getCheckMessage(MSG_CHILD_ERROR, "try", 9, 12),
3322             "70:12: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
3323             "71:12: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 11, 16),
3324             "72:14: " + getCheckMessage(MSG_CHILD_ERROR, "try", 13, 12),
3325             "74:8: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
3326             "75:8: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 7, "8, 12"),
3327             "88:9: " + getCheckMessage(MSG_ERROR, ".", 8, 12),
3328             "96:12: " + getCheckMessage(MSG_ERROR, "new", 11, 12),
3329         };
3330         verifyWarns(checkConfig, fileName, expected);
3331     }
3332 
3333     /**
3334      * Verifies that the arguments of {@link IndentationCheck#MSG_ERROR},
3335      * {@link IndentationCheck#MSG_CHILD_ERROR}, {@link IndentationCheck#MSG_CHILD_ERROR_MULTI},
3336      * {@link IndentationCheck#MSG_CHILD_ERROR_MULTI} are in appropriate order.
3337      *
3338      * <p>In other tests, the argument 0 and text before it are chopped off and only the rest of
3339      * messages are verified. Therefore, the argument 0 is required to be the first argument in
3340      * the messages above. If we update the messages in the future, it is required to keep the
3341      * arguments in appropriate order to ensure other tests will work.</p>
3342      *
3343      * @see IndentComment#getExpectedMessagePostfix(String)
3344      */
3345     @Test
3346     public void testArgumentOrderOfErrorMessages() {
3347         final Object[] arguments = {"##0##", "##1##", "##2##"};
3348         final String[] messages = {
3349             getCheckMessage(MSG_ERROR, arguments),
3350             getCheckMessage(MSG_CHILD_ERROR, arguments),
3351             getCheckMessage(MSG_ERROR_MULTI, arguments),
3352             getCheckMessage(MSG_CHILD_ERROR_MULTI, arguments),
3353         };
3354         final boolean isInOrder = Arrays.stream(messages).allMatch(msg -> {
3355             final int indexOfArgumentZero = msg.indexOf((String) arguments[0]);
3356             return Arrays.stream(arguments)
3357                     .map(String.class::cast)
3358                     .mapToInt(msg::indexOf)
3359                     .allMatch(index -> index >= indexOfArgumentZero);
3360         });
3361         assertWithMessage(
3362                     "the argument 0 of error messages (indentation.error, indentation.child.error,"
3363                         + " indentation.error.multi, indentation.child.error.multi)"
3364                         + " is required to be the first argument of them")
3365                 .that(isInOrder)
3366                 .isTrue();
3367     }
3368 
3369     @Test
3370     public void testEmptyArray() throws Exception {
3371         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3372         checkConfig.addProperty("tabWidth", "4");
3373         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3374         verifyWarns(checkConfig, getPath("InputIndentationEmptyArray.java"), expected);
3375     }
3376 
3377     @Test
3378     public void testNewHandler() throws Exception {
3379         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3380         checkConfig.addProperty("tabWidth", "4");
3381         final String[] expected = {
3382             "10:1: " + getCheckMessage(MSG_ERROR, "Object", 0, 12),
3383             "12:1: " + getCheckMessage(MSG_ERROR, "(", 0, 12),
3384             "15:1: " + getCheckMessage(MSG_CHILD_ERROR, "new", 0, 8),
3385             "17:1: " + getCheckMessage(MSG_ERROR, "new lparen", 0, 8),
3386             "25:1: " + getCheckMessage(MSG_ERROR, "=", 0, 8),
3387         };
3388         verifyWarns(checkConfig, getPath("InputIndentationNewHandler.java"), expected);
3389     }
3390 
3391     @Test
3392     public void testTryHandler() throws Exception {
3393         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3394         checkConfig.addProperty("tabWidth", "4");
3395         checkConfig.addProperty("braceAdjustment", "0");
3396         checkConfig.addProperty("lineWrappingIndentation", "8");
3397         checkConfig.addProperty("forceStrictCondition", "true");
3398         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3399         verifyWarns(checkConfig, getPath("InputIndentationTryBlockWithResources.java"), expected);
3400     }
3401 
3402     @Test
3403     public void testTryHandler2() throws Exception {
3404         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3405         checkConfig.addProperty("tabWidth", "4");
3406         checkConfig.addProperty("braceAdjustment", "0");
3407         checkConfig.addProperty("lineWrappingIndentation", "8");
3408         checkConfig.addProperty("forceStrictCondition", "true");
3409         final String[] expected = {
3410             "25:17: " + getCheckMessage(MSG_ERROR, "new", 16, 20),
3411             "27:13: " + getCheckMessage(MSG_ERROR, "new", 12, 20),
3412         };
3413         verifyWarns(checkConfig, getPath("InputIndentationTryBlock.java"), expected);
3414     }
3415 
3416     @Test
3417     public void testChainedMethodWithBracketOnNewLine() throws Exception {
3418         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3419 
3420         checkConfig.addProperty("arrayInitIndent", "2");
3421         checkConfig.addProperty("basicOffset", "2");
3422         checkConfig.addProperty("braceAdjustment", "0");
3423         checkConfig.addProperty("caseIndent", "2");
3424         checkConfig.addProperty("forceStrictCondition", "false");
3425         checkConfig.addProperty("lineWrappingIndentation", "4");
3426         checkConfig.addProperty("tabWidth", "2");
3427         checkConfig.addProperty("throwsIndent", "2");
3428         final String[] expected = {
3429             "44:7: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 6, 8),
3430             "45:9: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 10),
3431             "47:7: " + getCheckMessage(MSG_ERROR, "method call rparen", 6, 8),
3432             "61:6: " + getCheckMessage(MSG_ERROR, "foo", 5, 8),
3433             "82:5: " + getCheckMessage(MSG_ERROR, "if rcurly", 4, 6),
3434             "84:3: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 2, 4),
3435         };
3436         final String fileName = "InputIndentationChainedMethodWithBracketOnNewLine.java";
3437         verifyWarns(checkConfig, getPath(fileName), expected);
3438     }
3439 
3440     @Test
3441     public void testIndentationSwitchExpression() throws Exception {
3442         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3443         checkConfig.addProperty("tabWidth", "4");
3444         final String[] expected = {
3445             "17:1: " + getCheckMessage(MSG_CHILD_ERROR, "case", 0, 12),
3446             "18:9: " + getCheckMessage(MSG_CHILD_ERROR, "block", 8, 16),
3447             "21:25: " + getCheckMessage(MSG_CHILD_ERROR, "case", 24, 12),
3448             "22:9: " + getCheckMessage(MSG_CHILD_ERROR, "block", 8, 16),
3449             "27:9: " + getCheckMessage(MSG_CHILD_ERROR, "block", 8, 20),
3450             "29:1: " + getCheckMessage(MSG_CHILD_ERROR, "block", 0, 16),
3451             "30:1: " + getCheckMessage(MSG_ERROR, "yield", 0, 16),
3452             "34:5: " + getCheckMessage(MSG_CHILD_ERROR, "block", 4, 20),
3453             "44:1: " + getCheckMessage(MSG_CHILD_ERROR, "block", 0, 16),
3454             "46:21: " + getCheckMessage(MSG_CHILD_ERROR, "case", 20, 12),
3455             "47:1: " + getCheckMessage(MSG_CHILD_ERROR, "block", 0, 16),
3456             "51:9: " + getCheckMessage(MSG_CHILD_ERROR, "block", 8, 20),
3457             "56:33: " + getCheckMessage(MSG_CHILD_ERROR, "block", 32, 20),
3458         };
3459 
3460         verifyWarns(checkConfig,
3461                 getPath("InputIndentationCheckSwitchExpression.java"),
3462                 expected);
3463     }
3464 
3465     @Test
3466     public void testIndentationYieldStatement() throws Exception {
3467         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3468         checkConfig.addProperty("tabWidth", "4");
3469         final String[] expected = {
3470             "23:13: " + getCheckMessage(MSG_ERROR, "yield", 12, 16),
3471             "28:9: " + getCheckMessage(MSG_CHILD_ERROR, "yield", 8, 16),
3472             "40:5: " + getCheckMessage(MSG_ERROR, "yield", 4, 16),
3473             "41:9: " + getCheckMessage(MSG_CHILD_ERROR, "yield", 8, 16),
3474             "71:1: " + getCheckMessage(MSG_ERROR, "yield", 0, 16),
3475             "74:37: " + getCheckMessage(MSG_ERROR, "yield", 36, 16),
3476         };
3477 
3478         verifyWarns(checkConfig,
3479             getPath("InputIndentationYieldStatement.java"),
3480             expected);
3481     }
3482 
3483     @Test
3484     public void testIndentationSwitchExpressionCorrect() throws Exception {
3485         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3486         checkConfig.addProperty("tabWidth", "4");
3487         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3488         verifyWarns(checkConfig,
3489             getPath("InputIndentationCheckSwitchExpressionCorrect.java"),
3490             expected);
3491     }
3492 
3493     @Test
3494     public void testIndentationSwitchExpressionDeclaration() throws Exception {
3495         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3496         checkConfig.addProperty("tabWidth", "4");
3497         checkConfig.addProperty("caseIndent", "4");
3498         checkConfig.addProperty("lineWrappingIndentation", "8");
3499         final String[] expected = {
3500             "33:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
3501             "34:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
3502             "41:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
3503             "42:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
3504             "49:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3505             "50:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3506             "57:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3507             "58:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3508         };
3509         verifyWarns(checkConfig,
3510             getPath("InputIndentationCheckSwitchExpressionDeclaration.java"),
3511             expected);
3512     }
3513 
3514     @Test
3515     public void testIndentationSwitchExpressionDeclarationLeftCurlyNewLine() throws Exception {
3516         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3517         checkConfig.addProperty("tabWidth", "4");
3518         final String[] expected = {
3519             "34:5: " + getCheckMessage(MSG_ERROR, "switch lcurly", 4, 8),
3520             "42:5: " + getCheckMessage(MSG_ERROR, "switch lcurly", 4, 8),
3521             "50:13: " + getCheckMessage(MSG_ERROR, "switch lcurly", 12, 8),
3522             "58:13: " + getCheckMessage(MSG_ERROR, "switch lcurly", 12, 8),
3523         };
3524         verifyWarns(checkConfig,
3525             getPath(
3526                     "InputIndentationCheckSwitchExpressionDeclarationLCurlyNewLine.java"),
3527             expected);
3528     }
3529 
3530     @Test
3531     public void testIndentationRecords() throws Exception {
3532         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3533         checkConfig.addProperty("tabWidth", "4");
3534         checkConfig.addProperty("basicOffset", "4");
3535         checkConfig.addProperty("braceAdjustment", "0");
3536         checkConfig.addProperty("caseIndent", "4");
3537         checkConfig.addProperty("throwsIndent", "4");
3538         checkConfig.addProperty("arrayInitIndent", "4");
3539         checkConfig.addProperty("lineWrappingIndentation", "4");
3540         checkConfig.addProperty("forceStrictCondition", "false");
3541 
3542         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3543 
3544         verifyWarns(checkConfig,
3545             getPath("InputIndentationRecords.java"),
3546             expected);
3547     }
3548 
3549     @Test
3550     public void testIndentationRecordsAndCompactCtors() throws Exception {
3551         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3552         checkConfig.addProperty("tabWidth", "4");
3553         final String[] expected = {
3554             "13:1: " + getCheckMessage(MSG_ERROR, "(", 0, 8),
3555             "25:1: " + getCheckMessage(MSG_ERROR, "String", 0, 12),
3556             "38:1: " + getCheckMessage(MSG_CHILD_ERROR, "compact ctor def", 0, 12),
3557             "48:8: " + getCheckMessage(MSG_ERROR, "record def ident", 0, 4),
3558             "53:1: " + getCheckMessage(MSG_ERROR, "compact ctor def rcurly", 0, 8),
3559             "61:1: " + getCheckMessage(MSG_ERROR, "ctor def rcurly", 0, 8),
3560         };
3561 
3562         verifyWarns(checkConfig,
3563             getPath("InputIndentationRecordsAndCompactCtors.java"),
3564             expected);
3565     }
3566 
3567     @Test
3568     public void testIndentationSwitchExpressionNewLine() throws Exception {
3569         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3570         checkConfig.addProperty("tabWidth", "4");
3571         final String[] expected = {
3572             "30:13: " + getCheckMessage(MSG_ERROR, "lambda", 12, 16),
3573             "32:13: " + getCheckMessage(MSG_ERROR, "lambda", 12, 16),
3574         };
3575 
3576         verifyWarns(checkConfig,
3577             getPath("InputIndentationCheckSwitchExpressionNewLine.java"),
3578             expected);
3579     }
3580 
3581     @Test
3582     public void testIndentationMethodParenthesisOnNewLine() throws Exception {
3583         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3584         checkConfig.addProperty("tabWidth", "4");
3585         final String[] expected = {
3586             "13:9: " + getCheckMessage(MSG_ERROR, "method def rparen", 8, 4),
3587             "18:9: " + getCheckMessage(MSG_ERROR, "method def rparen", 8, 4),
3588         };
3589 
3590         verifyWarns(checkConfig,
3591                 getPath("InputIndentationCheckMethodParenOnNewLine.java"),
3592                 expected);
3593     }
3594 
3595     @Test
3596     public void testIndentationMethodParenthesisOnNewLine1() throws Exception {
3597         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3598         checkConfig.addProperty("tabWidth", "4");
3599         final String[] expected = {
3600             "11:10: " + getCheckMessage(MSG_ERROR, "2", 9, 12),
3601             "17:8: " + getCheckMessage(MSG_ERROR, "int", 7, 8),
3602             "18:9: " + getCheckMessage(MSG_ERROR, "method def rparen", 8, 4),
3603         };
3604 
3605         verifyWarns(checkConfig,
3606                 getPath("InputIndentationCheckMethodParenOnNewLine1.java"),
3607                 expected);
3608     }
3609 
3610     @Test
3611     public void testIndentationLineWrappedRecordDeclaration() throws Exception {
3612         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3613         checkConfig.addProperty("tabWidth", "4");
3614         checkConfig.addProperty("basicOffset", "4");
3615         checkConfig.addProperty("braceAdjustment", "0");
3616         checkConfig.addProperty("caseIndent", "4");
3617         checkConfig.addProperty("throwsIndent", "4");
3618         checkConfig.addProperty("arrayInitIndent", "4");
3619         checkConfig.addProperty("lineWrappingIndentation", "4");
3620 
3621         final String[] expected = {
3622             "33:1: " + getCheckMessage(MSG_ERROR, ")", 0, 4),
3623             "55:11: " + getCheckMessage(MSG_ERROR, "interface def ident", 0, 4),
3624             "56:1: " + getCheckMessage(MSG_ERROR, "method def modifier", 0, 8),
3625             "57:1: " + getCheckMessage(MSG_ERROR, "void", 0, 4),
3626             "58:1: " + getCheckMessage(MSG_ERROR, "method", 0, 4),
3627             "59:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 4),
3628             "60:1: " + getCheckMessage(MSG_ERROR, "IOException", 0, 4),
3629             "61:1: " + getCheckMessage(MSG_ERROR, "method def rcurly", 0, 8),
3630             "62:1: " + getCheckMessage(MSG_ERROR, "interface def rcurly", 0, 4),
3631             "75:8: " + getCheckMessage(MSG_ERROR, "record def ident", 0, 4),
3632             "76:1: " + getCheckMessage(MSG_ERROR, "record def rparen", 0, 4),
3633             "77:1: " + getCheckMessage(MSG_ERROR, "implements", 0, 4),
3634             "78:1: " + getCheckMessage(MSG_ERROR, "SimpleInterface2", 0, 4),
3635             "79:8: " + getCheckMessage(MSG_ERROR, "record def ident", 0, 8),
3636             "80:1: " + getCheckMessage(MSG_ERROR, "(", 0, 4),
3637             "81:1: " + getCheckMessage(MSG_ERROR, "record def rparen", 0, 8),
3638             "82:1: " + getCheckMessage(MSG_ERROR, "record def lcurly", 0, 8),
3639             "83:1: " + getCheckMessage(MSG_ERROR, "record def rcurly", 0, 8),
3640             "84:1: " + getCheckMessage(MSG_ERROR, "record def rcurly", 0, 4),
3641         };
3642 
3643         verifyWarns(checkConfig,
3644             getPath("InputIndentationLineWrappedRecordDeclaration.java"),
3645             expected);
3646     }
3647 
3648     @Test
3649     public void testIndentationAnnotationFieldDefinition() throws Exception {
3650         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3651         checkConfig.addProperty("tabWidth", "4");
3652         checkConfig.addProperty("basicOffset", "4");
3653         checkConfig.addProperty("braceAdjustment", "0");
3654         checkConfig.addProperty("caseIndent", "4");
3655         checkConfig.addProperty("throwsIndent", "8");
3656         checkConfig.addProperty("forceStrictCondition", "true");
3657 
3658         final String[] expected = {
3659             "17:5: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 4, 8),
3660             "18:13: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 12, 8),
3661             "25:5: " + getCheckMessage(MSG_ERROR, "member def type", 4, 8),
3662             "26:5: " + getCheckMessage(MSG_ERROR, "member def type", 4, 8),
3663         };
3664 
3665         verifyWarns(checkConfig, getPath("InputIndentationAnnotationFieldDef.java"),
3666                 expected);
3667     }
3668 
3669     @Test
3670     public void testIndentationLongConcatenatedString() throws Exception {
3671         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3672         checkConfig.addProperty("tabWidth", "4");
3673 
3674         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3675 
3676         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString.java"),
3677                 expected);
3678     }
3679 
3680     @Test
3681     public void testIndentationLongConcatenatedString1() throws Exception {
3682         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3683         checkConfig.addProperty("tabWidth", "4");
3684 
3685         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3686 
3687         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString1.java"),
3688                 expected);
3689     }
3690 
3691     @Test
3692     public void testIndentationLongConcatenatedString2() throws Exception {
3693         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3694         checkConfig.addProperty("tabWidth", "4");
3695 
3696         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3697 
3698         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString2.java"),
3699                 expected);
3700     }
3701 
3702     @Test
3703     public void testIndentationLongConcatenatedString3() throws Exception {
3704         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3705         checkConfig.addProperty("tabWidth", "4");
3706 
3707         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3708 
3709         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString3.java"),
3710                 expected);
3711     }
3712 
3713     @Test
3714     public void testIndentationLongConcatenatedString4() throws Exception {
3715         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3716         checkConfig.addProperty("tabWidth", "4");
3717 
3718         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3719 
3720         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString4.java"),
3721                 expected);
3722     }
3723 
3724     @Test
3725     public void testIndentationLongConcatenatedString5() throws Exception {
3726         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3727         checkConfig.addProperty("tabWidth", "4");
3728 
3729         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3730 
3731         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString5.java"),
3732                 expected);
3733     }
3734 
3735     @Test
3736     public void testIndentationLongConcatenatedString6() throws Exception {
3737         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3738         checkConfig.addProperty("tabWidth", "4");
3739 
3740         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3741 
3742         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString6.java"),
3743                 expected);
3744     }
3745 
3746     @Test
3747     public void testIndentationLongConcatenatedString7() throws Exception {
3748         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3749         checkConfig.addProperty("tabWidth", "4");
3750 
3751         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3752 
3753         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString7.java"),
3754                 expected);
3755     }
3756 
3757     @Test
3758     public void testIndentationLongConcatenatedString8() throws Exception {
3759         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3760         checkConfig.addProperty("tabWidth", "4");
3761 
3762         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3763 
3764         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString8.java"),
3765                 expected);
3766     }
3767 
3768     @Test
3769     public void testIndentationLongConcatenatedString9() throws Exception {
3770         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3771         checkConfig.addProperty("tabWidth", "4");
3772 
3773         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3774 
3775         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString9.java"),
3776                 expected);
3777     }
3778 
3779     @Test
3780     public void testIndentationLongConcatenatedString10() throws Exception {
3781         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3782         checkConfig.addProperty("tabWidth", "4");
3783 
3784         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3785 
3786         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString10.java"),
3787                 expected);
3788     }
3789 
3790     @Test
3791     public void testIndentationLongConcatenatedString11() throws Exception {
3792         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3793         checkConfig.addProperty("tabWidth", "4");
3794 
3795         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3796 
3797         verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString11.java"),
3798                 expected);
3799     }
3800 
3801     @Test
3802     public void testIndentationLineBreakVariableDeclaration()
3803             throws Exception {
3804         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3805         checkConfig.addProperty("tabWidth", "4");
3806 
3807         final String fileName = getPath("InputIndentationLineBreakVariableDeclaration.java");
3808         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3809         verifyWarns(checkConfig, fileName, expected);
3810     }
3811 
3812     @Test
3813     public void testIndentationSwitchExpressionOnStartOfTheLine() throws Exception {
3814         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3815         checkConfig.addProperty("tabWidth", "4");
3816         checkConfig.addProperty("basicOffset", "2");
3817         checkConfig.addProperty("braceAdjustment", "2");
3818         checkConfig.addProperty("caseIndent", "2");
3819         checkConfig.addProperty("throwsIndent", "4");
3820         checkConfig.addProperty("lineWrappingIndentation", "4");
3821 
3822         final String[] expected = {
3823             "40:7: " + getCheckMessage(MSG_ERROR, "switch", 6, 8),
3824             "41:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3825             "42:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3826             "43:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3827             "44:7: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
3828             "49:11: " + getCheckMessage(MSG_ERROR, "switch", 10, 8),
3829             "50:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
3830             "51:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
3831             "52:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
3832         };
3833 
3834         verifyWarns(checkConfig,
3835                 getPath("InputIndentationSwitchOnStartOfLine.java"), expected);
3836     }
3837 
3838     @Test
3839     public void testIndentationSwitchExpressionWrappingIndentation() throws Exception {
3840         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3841         checkConfig.addProperty("tabWidth", "4");
3842         checkConfig.addProperty("basicOffset", "2");
3843         checkConfig.addProperty("braceAdjustment", "2");
3844         checkConfig.addProperty("caseIndent", "2");
3845         checkConfig.addProperty("lineWrappingIndentation", "4");
3846 
3847         final String fileName = getPath(
3848                 "InputIndentationSwitchExpressionWrappingIndentation.java");
3849         final String[] expected = {
3850             "41:7: " + getCheckMessage(MSG_ERROR, "switch", 6, 8),
3851             "42:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3852             "43:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3853             "44:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3854             "45:7: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
3855             "51:9: " + getCheckMessage(MSG_CHILD_ERROR, "lambda", 8, 10),
3856             "52:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
3857         };
3858         verifyWarns(checkConfig, fileName, expected);
3859     }
3860 
3861     @Test
3862     public void testInputIndentationLambdaChild() throws Exception {
3863         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3864         checkConfig.addProperty("tabWidth", "4");
3865         checkConfig.addProperty("basicOffset", "2");
3866         checkConfig.addProperty("braceAdjustment", "2");
3867         checkConfig.addProperty("caseIndent", "2");
3868         checkConfig.addProperty("lineWrappingIndentation", "4");
3869 
3870         final String fileName = getPath(
3871                 "InputIndentationLambdaChild.java");
3872         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3873         verifyWarns(checkConfig, fileName, expected);
3874     }
3875 
3876     @Test
3877     public void testInputLambdaAndChildOnTheSameLine() throws Exception {
3878         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3879         checkConfig.addProperty("tabWidth", "4");
3880         checkConfig.addProperty("basicOffset", "2");
3881         checkConfig.addProperty("braceAdjustment", "2");
3882         checkConfig.addProperty("caseIndent", "2");
3883         checkConfig.addProperty("lineWrappingIndentation", "4");
3884 
3885         final String fileName = getPath(
3886                 "InputIndentationLambdaAndChildOnTheSameLine.java");
3887         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3888         verifyWarns(checkConfig, fileName, expected);
3889     }
3890 
3891     @Test
3892     public void testIndentationPatternMatchingForSwitch()
3893             throws Exception {
3894         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3895         checkConfig.addProperty("forceStrictCondition", "true");
3896         checkConfig.addProperty("tabWidth", "4");
3897         checkConfig.addProperty("basicOffset", "4");
3898         checkConfig.addProperty("braceAdjustment", "0");
3899         checkConfig.addProperty("caseIndent", "4");
3900         checkConfig.addProperty("throwsIndent", "8");
3901 
3902         final String fileName = getPath(
3903                 "InputIndentationPatternMatchingForSwitch.java");
3904         final String[] expected = {
3905             "21:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 16),
3906             "54:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 16),
3907             "69:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 16),
3908             "70:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 16),
3909             "75:5: " + getCheckMessage(MSG_CHILD_ERROR, "case", 4, 16),
3910             "76:5: " + getCheckMessage(MSG_CHILD_ERROR, "case", 4, 16),
3911             "87:1: " + getCheckMessage(MSG_CHILD_ERROR, "case", 0, 16),
3912             "88:1: " + getCheckMessage(MSG_CHILD_ERROR, "case", 0, 16),
3913             "89:1: " + getCheckMessage(MSG_CHILD_ERROR, "case", 0, 16),
3914             "90:1: " + getCheckMessage(MSG_ERROR, "lambda", 0, 16),
3915             "91:1: " + getCheckMessage(MSG_CHILD_ERROR, "lambda", 0, 20),
3916         };
3917         verifyWarns(checkConfig, fileName, expected);
3918     }
3919 
3920     @Test
3921     public void testIndentationSingleSwitchStatementsWithoutCurly()
3922             throws Exception {
3923         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3924         checkConfig.addProperty("forceStrictCondition", "true");
3925         checkConfig.addProperty("tabWidth", "4");
3926         checkConfig.addProperty("basicOffset", "4");
3927         checkConfig.addProperty("braceAdjustment", "0");
3928         checkConfig.addProperty("caseIndent", "4");
3929         checkConfig.addProperty("throwsIndent", "4");
3930 
3931         final String fileName = getPath(
3932                 "InputIndentationCheckSingleSwitchStatementsWithoutCurly.java");
3933         final String[] expected = {
3934             "31:13: " + getCheckMessage(MSG_ERROR, "lambda", 12, 16),
3935             "32:13: " + getCheckMessage(MSG_CHILD_ERROR, "lambda", 12, 20),
3936             "33:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3937             "34:1: " + getCheckMessage(MSG_CHILD_ERROR, "lambda", 0, 16),
3938             "44:25: " + getCheckMessage(MSG_CHILD_ERROR, "lambda", 24, 16),
3939             "47:13: " + getCheckMessage(MSG_CHILD_ERROR, "block", 12, 16),
3940         };
3941         verifyWarns(checkConfig, fileName, expected);
3942     }
3943 
3944     @Test
3945     public void testIndentationRecordPattern()
3946             throws Exception {
3947         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3948         checkConfig.addProperty("forceStrictCondition", "true");
3949         checkConfig.addProperty("tabWidth", "4");
3950         checkConfig.addProperty("basicOffset", "4");
3951         checkConfig.addProperty("braceAdjustment", "0");
3952         checkConfig.addProperty("caseIndent", "4");
3953         checkConfig.addProperty("throwsIndent", "8");
3954 
3955         final String fileName = getPath(
3956                 "InputIndentationRecordPattern.java");
3957         final String[] expected = {
3958             "19:17: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 16, 12),
3959             "24:9: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 8, 12),
3960             "29:17: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 16, 12),
3961             "34:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3962             "37:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3963             "39:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3964             "40:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3965             "41:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3966             "42:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3967             "56:17: " + getCheckMessage(MSG_ERROR, "Rectangle", 16, 12),
3968             "57:17: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 16, 12),
3969             "58:25: " + getCheckMessage(MSG_ERROR, "boolean", 24, 12),
3970             "59:17: " + getCheckMessage(MSG_ERROR, "int", 16, 12),
3971             "60:25: " + getCheckMessage(MSG_ERROR, "_", 24, 12),
3972             "61:17: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 16, 12),
3973             "62:17: " + getCheckMessage(MSG_ERROR, ")", 16, 8),
3974             "67:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3975             "66:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3976             "68:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3977             "69:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3978             "70:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3979             "71:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3980             "72:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3981             "81:13: " + getCheckMessage(MSG_ERROR, ")", 12, 8),
3982             "89:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 16),
3983             "90:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 16),
3984         };
3985         verifyWarns(checkConfig, fileName, expected);
3986     }
3987 
3988     @Test
3989     public void testIndentationCodeBlocks1() throws Exception {
3990         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3991         checkConfig.addProperty("tabWidth", "4");
3992         checkConfig.addProperty("basicOffset", "2");
3993         checkConfig.addProperty("braceAdjustment", "2");
3994         checkConfig.addProperty("caseIndent", "2");
3995         checkConfig.addProperty("throwsIndent", "4");
3996         checkConfig.addProperty("lineWrappingIndentation", "4");
3997         final String[] expected = {
3998             "17:5: " + getCheckMessage(MSG_ERROR, "block lcurly", 4, 2),
3999             "18:7: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 4),
4000             "19:5: " + getCheckMessage(MSG_ERROR, "block rcurly", 4, 2),
4001             "30:5: " + getCheckMessage(MSG_ERROR, "block lcurly", 4, 2),
4002             "31:7: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 4),
4003             "32:5: " + getCheckMessage(MSG_ERROR, "block rcurly", 4, 2),
4004         };
4005         verifyWarns(checkConfig, getPath("InputIndentationCodeBlocks1.java"), expected);
4006     }
4007 
4008     @Test
4009     public void testIndentationCodeBlocks2() throws Exception {
4010         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4011         checkConfig.addProperty("tabWidth", "4");
4012         checkConfig.addProperty("basicOffset", "2");
4013         checkConfig.addProperty("braceAdjustment", "2");
4014         checkConfig.addProperty("throwsIndent", "4");
4015         checkConfig.addProperty("caseIndent", "2");
4016         checkConfig.addProperty("lineWrappingIndentation", "4");
4017         final String[] expected = {
4018             "45:13: " + getCheckMessage(MSG_ERROR, "for lcurly", 12, 14),
4019             "47:13: " + getCheckMessage(MSG_ERROR, "for rcurly", 12, 14),
4020         };
4021         verifyWarns(checkConfig,
4022                 getPath("InputIndentationCodeBlocks2.java"), expected);
4023     }
4024 
4025     @Test
4026     public void testSynchronizedExprViolation() throws Exception {
4027         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4028         checkConfig.addProperty("basicOffset", "4");
4029         checkConfig.addProperty("braceAdjustment", "0");
4030         checkConfig.addProperty("caseIndent", "4");
4031         checkConfig.addProperty("lineWrappingIndentation", "4");
4032         checkConfig.addProperty("throwsIndent", "4");
4033         checkConfig.addProperty("forceStrictCondition", "false");
4034         checkConfig.addProperty("tabWidth", "4");
4035         final String fileName = getPath("InputIndentationSynchronizedExprViolation.java");
4036         final String[] expected = {
4037             "18:1: " + getCheckMessage(MSG_CHILD_ERROR, "synchronized", 0, 12),
4038         };
4039         verifyWarns(checkConfig, fileName, expected);
4040     }
4041 
4042     @Test
4043     public void testIndentationAnnotationArray() throws Exception {
4044         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4045         checkConfig.addProperty("tabWidth", "4");
4046         checkConfig.addProperty("basicOffset", "2");
4047         checkConfig.addProperty("braceAdjustment", "2");
4048         checkConfig.addProperty("caseIndent", "2");
4049         checkConfig.addProperty("throwsIndent", "4");
4050         checkConfig.addProperty("lineWrappingIndentation", "4");
4051         checkConfig.addProperty("arrayInitIndent", "2");
4052 
4053         final String fileName = getPath(
4054                 "InputIndentationAnnotationArray.java");
4055         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
4056         verifyWarns(checkConfig, fileName, expected);
4057     }
4058 
4059     @Test
4060     public void testSwitchExprViolation() throws Exception {
4061         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4062         checkConfig.addProperty("basicOffset", "4");
4063         checkConfig.addProperty("braceAdjustment", "0");
4064         checkConfig.addProperty("caseIndent", "4");
4065         checkConfig.addProperty("lineWrappingIndentation", "4");
4066         checkConfig.addProperty("throwsIndent", "4");
4067         checkConfig.addProperty("forceStrictCondition", "false");
4068         checkConfig.addProperty("tabWidth", "4");
4069         final String fileName = getPath("InputIndentationSwitchExprViolation.java");
4070         final String[] expected = {
4071             "18:1: " + getCheckMessage(MSG_CHILD_ERROR, "switch", 0, 8),
4072         };
4073         verifyWarns(checkConfig, fileName, expected);
4074     }
4075 
4076     @Test
4077     public void testIndentationSealedClasses()
4078             throws Exception {
4079         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4080         checkConfig.addProperty("forceStrictCondition", "true");
4081         checkConfig.addProperty("tabWidth", "4");
4082         checkConfig.addProperty("basicOffset", "4");
4083         checkConfig.addProperty("braceAdjustment", "0");
4084         checkConfig.addProperty("caseIndent", "4");
4085         checkConfig.addProperty("throwsIndent", "8");
4086 
4087         final String fileName = getPath(
4088                 "InputIndentationSealedClasses.java");
4089         final String[] expected = {
4090             "14:1: " + getCheckMessage(MSG_ERROR, "class def modifier", 0, 4),
4091             "15:2: " + getCheckMessage(MSG_ERROR, "class", 1, 4),
4092             "16:6: " + getCheckMessage(MSG_ERROR, "permits", 5, 4),
4093             "19:5: " + getCheckMessage(MSG_ERROR, "class", 4, 8),
4094             "20:5: " + getCheckMessage(MSG_ERROR, "permits", 4, 8),
4095             "28:1: " + getCheckMessage(MSG_ERROR, "class def modifier", 0, 4),
4096             "29:9: " + getCheckMessage(MSG_ERROR, "extends", 8, 4),
4097             "32:5: " + getCheckMessage(MSG_ERROR, "extends", 4, 8),
4098             "38:5: " + getCheckMessage(MSG_ERROR, "class", 4, 8),
4099             "39:1: " + getCheckMessage(MSG_ERROR, "permits", 0, 8),
4100             "40:13: " + getCheckMessage(MSG_ERROR, "C", 12, 8),
4101             "48:5: " + getCheckMessage(MSG_ERROR, "class", 4, 8),
4102             "49:5: " + getCheckMessage(MSG_ERROR, "C", 4, 8),
4103             "55:1: " + getCheckMessage(MSG_ERROR, "class def modifier", 0, 4),
4104             "56:9: " + getCheckMessage(MSG_ERROR, "class", 8, 4),
4105         };
4106         verifyWarns(checkConfig, fileName, expected);
4107     }
4108 
4109     @Test
4110     public void testTryResourcesLparenViolation() throws Exception {
4111         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4112         checkConfig.addProperty("basicOffset", "4");
4113         checkConfig.addProperty("braceAdjustment", "0");
4114         checkConfig.addProperty("caseIndent", "4");
4115         checkConfig.addProperty("lineWrappingIndentation", "4");
4116         checkConfig.addProperty("throwsIndent", "4");
4117         checkConfig.addProperty("forceStrictCondition", "false");
4118         checkConfig.addProperty("tabWidth", "4");
4119         final String fileName = getPath("InputIndentationTryResourcesLparenViolation.java");
4120         final String[] expected = {
4121             "22:1: " + getCheckMessage(MSG_ERROR_MULTI, "try lparen", 0, "8, 12"),
4122         };
4123         verifyWarns(checkConfig, fileName, expected);
4124     }
4125 
4126     @Test
4127     public void testSynchronizedWrapping() throws Exception {
4128         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4129         checkConfig.addProperty("arrayInitIndent", "4");
4130         checkConfig.addProperty("basicOffset", "4");
4131         checkConfig.addProperty("braceAdjustment", "0");
4132         checkConfig.addProperty("caseIndent", "4");
4133         checkConfig.addProperty("forceStrictCondition", "false");
4134         checkConfig.addProperty("lineWrappingIndentation", "8");
4135         checkConfig.addProperty("tabWidth", "4");
4136         checkConfig.addProperty("throwsIndent", "4");
4137         final String fileName = getPath("InputIndentationSynchronizedWrapping.java");
4138         final String[] expected = {
4139             "22:13: " + getCheckMessage(MSG_ERROR, ".", 12, 16),
4140         };
4141         verifyWarns(checkConfig, fileName, expected);
4142     }
4143 
4144     /**
4145      * Pure unit test to satisfy line coverage for {@link PrimordialHandler#checkIndentation()}.
4146      * The method has an empty implementation required by the abstract contract of
4147      * {@link AbstractExpressionHandler}. A unit test is required as this method is not
4148      * reachable through any integration test.
4149      */
4150     @Test
4151     public void testPrimordialHandlerCheckIndentation() {
4152         final IndentationCheck check = new IndentationCheck();
4153         final PrimordialHandler handler = new PrimordialHandler(check);
4154         handler.checkIndentation();
4155         assertWithMessage("Method should complete without exception")
4156             .that(handler)
4157             .isNotNull();
4158     }
4159 
4160     @Test
4161     public void testIndexOpWithInvalidChildIndentation() throws Exception {
4162         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4163         checkConfig.addProperty("arrayInitIndent", "4");
4164         checkConfig.addProperty("basicOffset", "4");
4165         checkConfig.addProperty("braceAdjustment", "0");
4166         checkConfig.addProperty("caseIndent", "4");
4167         checkConfig.addProperty("forceStrictCondition", "false");
4168         checkConfig.addProperty("lineWrappingIndentation", "4");
4169         checkConfig.addProperty("tabWidth", "4");
4170         checkConfig.addProperty("throwsIndent", "4");
4171         final String fileName = getPath("InputIndentationInvalidArrayIndexIndent.java");
4172         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
4173         verifyWarns(checkConfig, fileName, expected);
4174     }
4175 
4176     @Test
4177     public void testFirstTokenSelection() throws Exception {
4178         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4179         checkConfig.addProperty("basicOffset", "4");
4180         checkConfig.addProperty("tabWidth", "4");
4181 
4182         final String[] expected = {
4183             "15:1: " + getCheckMessage(MSG_ERROR, "member def type", 0, 8),
4184             "16:1: " + getCheckMessage(MSG_ERROR, "Integer", 0, 12),
4185             "17:1: " + getCheckMessage(MSG_ERROR, ">", 0, 12),
4186         };
4187         verifyWarns(checkConfig,
4188             getPath("InputIndentationFirstTokenSelection.java"), expected);
4189     }
4190 
4191     @Test
4192     public void testNewKeywordWithTernaryOperator() throws Exception {
4193         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4194 
4195         checkConfig.addProperty("basicOffset", "4");
4196         checkConfig.addProperty("braceAdjustment", "0");
4197         checkConfig.addProperty("caseIndent", "4");
4198         checkConfig.addProperty("forceStrictCondition", "true");
4199         checkConfig.addProperty("lineWrappingIndentation", "4");
4200         checkConfig.addProperty("tabWidth", "4");
4201         checkConfig.addProperty("throwsIndent", "4");
4202         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
4203         verifyWarns(checkConfig,
4204             getPath("InputIndentationNewWithTernaryOp.java"), expected);
4205     }
4206 
4207     /**
4208      * Test to kill Pitest mutation by verifying internal state is cleared.
4209      *
4210      * <p>This reflection-based test was chosen because:
4211      * 1. clearState() exists purely for memory management, prevents OutOfMemoryError when
4212      *    processing thousands of files
4213      * 2. Removing clear() has no observable effect in normal tests since each file creates
4214      *    new DetailAST objects (no collision possible)
4215      * 3. Pitest's excludedMethods only protects method bodies, not call-sites
4216      * 4. Creating a utility class with avoidCallsTo was overkill for one mutation
4217      *
4218      * @see <a href="https://github.com/hcoles/pitest/issues/404">Pitest Issue #404</a>
4219      */
4220     @Test
4221     public void testClearStateForMemoryManagement() {
4222         final IndentationCheck check = new IndentationCheck();
4223         @SuppressWarnings("unchecked")
4224         final Deque<PrimordialHandler> handlers = TestUtil.getInternalState(check,
4225                 "handlers", Deque.class);
4226 
4227         handlers.push(new PrimordialHandler(check));
4228         handlers.push(new PrimordialHandler(check));
4229 
4230         assertWithMessage("handlers should have 2 elements before beginTree")
4231                 .that(handlers)
4232                 .hasSize(2);
4233 
4234         check.beginTree(null);
4235 
4236         assertWithMessage("handlers should be reset to 1 element after beginTree")
4237                 .that(handlers)
4238                 .hasSize(1);
4239     }
4240 
4241     @Test
4242     public void testLambdaInEnumConstant() throws Exception {
4243         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4244         checkConfig.addProperty("basicOffset", "4");
4245         checkConfig.addProperty("braceAdjustment", "0");
4246         checkConfig.addProperty("caseIndent", "4");
4247         checkConfig.addProperty("throwsIndent", "4");
4248         checkConfig.addProperty("arrayInitIndent", "4");
4249         checkConfig.addProperty("lineWrappingIndentation", "4");
4250         checkConfig.addProperty("forceStrictCondition", "false");
4251         checkConfig.addProperty("tabWidth", "8");
4252 
4253         final String fileName = getPath("InputIndentationLambdaInEnum.java");
4254         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
4255         verifyWarns(checkConfig, fileName, expected);
4256     }
4257 
4258     @Test
4259     public void testLambdaInEnumConstantWithMultipleArgs() throws Exception {
4260         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4261         checkConfig.addProperty("basicOffset", "4");
4262         checkConfig.addProperty("braceAdjustment", "0");
4263         checkConfig.addProperty("caseIndent", "4");
4264         checkConfig.addProperty("throwsIndent", "4");
4265         checkConfig.addProperty("arrayInitIndent", "4");
4266         checkConfig.addProperty("lineWrappingIndentation", "4");
4267         checkConfig.addProperty("forceStrictCondition", "false");
4268         checkConfig.addProperty("tabWidth", "8");
4269 
4270         final String fileName = getPath("InputIndentationLambdaInEnumMultipleArgs.java");
4271         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
4272         verifyWarns(checkConfig, fileName, expected);
4273     }
4274 
4275     @Test
4276     public void testTryBlockConstructorParameters() throws Exception {
4277         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
4278         checkConfig.addProperty("basicOffset", "4");
4279         checkConfig.addProperty("braceAdjustment", "0");
4280         checkConfig.addProperty("caseIndent", "4");
4281         checkConfig.addProperty("lineWrappingIndentation", "8");
4282         checkConfig.addProperty("tabWidth", "4");
4283 
4284         final String fileName = getPath("InputIndentationTryCtorParams.java");
4285         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
4286         verifyWarns(checkConfig, fileName, expected);
4287     }
4288 
4289     private static final class IndentAudit implements AuditListener {
4290 
4291         private final IndentComment[] comments;
4292         private int position;
4293 
4294         private IndentAudit(IndentComment... comments) {
4295             this.comments = Arrays.copyOf(comments, comments.length);
4296         }
4297 
4298         @Override
4299         public void auditStarted(AuditEvent event) {
4300             // No code needed
4301         }
4302 
4303         @Override
4304         public void auditFinished(AuditEvent event) {
4305             // No code needed
4306         }
4307 
4308         @Override
4309         public void fileStarted(AuditEvent event) {
4310             // No code needed
4311         }
4312 
4313         @Override
4314         public void fileFinished(AuditEvent event) {
4315             // No code needed
4316         }
4317 
4318         @Override
4319         public void addError(AuditEvent event) {
4320             final int line = event.getLine();
4321             final String message = event.getMessage();
4322 
4323             assertWithMessage(
4324                     "found a warning when none was expected for #%s at line %s with message %s",
4325                     position, line, message)
4326                 .that(position)
4327                 .isLessThan(comments.length);
4328 
4329             final IndentComment comment = comments[position];
4330             position++;
4331 
4332             final String possibleExceptedMessages = Arrays.stream(comment.getExpectedMessages())
4333                     .reduce("", (cur, next) -> cur + "\"" + next + "\", ");
4334             final String assertMessage = String.format(
4335                     Locale.ROOT,
4336                     "input expected warning #%d at line %d to report one of the following: %s"
4337                             + "but got instead: %d: %s",
4338                     position, comment.getLineNumber(), possibleExceptedMessages, line, message);
4339             assertWithMessage(assertMessage)
4340                     .that(line == comment.getLineNumber() && Arrays
4341                             .stream(comment.getExpectedMessages()).anyMatch(message::endsWith))
4342                     .isTrue();
4343         }
4344 
4345         @Override
4346         public void addException(AuditEvent event, Throwable throwable) {
4347             // No code needed
4348         }
4349 
4350     }
4351 
4352     private static final class IndentComment {
4353 
4354         /** Used to locate the index of argument zero of error messages. */
4355         private static final String FAKE_ARGUMENT_ZERO = "##0##";
4356         private final int lineNumber;
4357         private final int indent;
4358         /** Used for when violations report nodes not first on the line. */
4359         private final int indentOffset;
4360         private final boolean expectedNonStrict;
4361         private final String expectedWarning;
4362         private final boolean warning;
4363 
4364         private IndentComment(IndentComment original, int newLineNumber) {
4365             lineNumber = newLineNumber;
4366             indent = original.indent;
4367             indentOffset = original.indentOffset;
4368             expectedNonStrict = original.expectedNonStrict;
4369             expectedWarning = original.expectedWarning;
4370             warning = original.warning;
4371         }
4372 
4373         private IndentComment(Matcher match, int lineNumber) {
4374             this.lineNumber = lineNumber;
4375             indent = Integer.parseInt(match.group(1));
4376             if (match.group(2) == null) {
4377                 indentOffset = 0;
4378             }
4379             else {
4380                 indentOffset = Integer.parseInt(match.group(2));
4381             }
4382             expectedNonStrict = match.group(3) != null;
4383             expectedWarning = match.group(4).replace(",", ", ");
4384             warning = match.group(5) != null;
4385         }
4386 
4387         private String[] getExpectedMessages() {
4388             final String[] expectedMessages;
4389             if (expectedWarning.contains(",")) {
4390                 expectedMessages = new String[] {
4391                     getExpectedMessagePostfix(MSG_ERROR_MULTI),
4392                     getExpectedMessagePostfix(MSG_CHILD_ERROR_MULTI),
4393                 };
4394             }
4395             else {
4396                 expectedMessages = new String[] {
4397                     getExpectedMessagePostfix(MSG_ERROR),
4398                     getExpectedMessagePostfix(MSG_CHILD_ERROR),
4399                 };
4400             }
4401             return expectedMessages;
4402         }
4403 
4404         private String getExpectedMessagePostfix(final String messageKey) {
4405             final String msg = getCheckMessage(IndentationCheck.class, messageKey,
4406                     FAKE_ARGUMENT_ZERO, indent + indentOffset, expectedWarning);
4407             final int indexOfMsgPostfix = msg.indexOf(FAKE_ARGUMENT_ZERO)
4408                     + FAKE_ARGUMENT_ZERO.length();
4409             return msg.substring(indexOfMsgPostfix);
4410         }
4411 
4412         private int getLineNumber() {
4413             return lineNumber;
4414         }
4415 
4416         private int getIndent() {
4417             return indent;
4418         }
4419 
4420         private int getIndentOffset() {
4421             return indentOffset;
4422         }
4423 
4424         private boolean isExpectedNonStrict() {
4425             return expectedNonStrict;
4426         }
4427 
4428         private String getExpectedWarning() {
4429             return expectedWarning;
4430         }
4431 
4432         private boolean isWarning() {
4433             return warning;
4434         }
4435 
4436     }
4437 
4438 }