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