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