1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2019 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.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_CHILD_ERROR;
23  import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_CHILD_ERROR_MULTI;
24  import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_ERROR;
25  import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_ERROR_MULTI;
26  import static org.junit.Assert.assertArrayEquals;
27  import static org.junit.Assert.assertEquals;
28  import static org.junit.Assert.assertTrue;
29  import static org.junit.Assert.fail;
30  
31  import java.io.BufferedReader;
32  import java.io.IOException;
33  import java.nio.charset.StandardCharsets;
34  import java.nio.file.Files;
35  import java.nio.file.Paths;
36  import java.util.ArrayList;
37  import java.util.Arrays;
38  import java.util.List;
39  import java.util.Locale;
40  import java.util.regex.Matcher;
41  import java.util.regex.Pattern;
42  
43  import org.junit.Test;
44  
45  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
46  import com.puppycrawl.tools.checkstyle.Checker;
47  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
48  import com.puppycrawl.tools.checkstyle.api.AuditEvent;
49  import com.puppycrawl.tools.checkstyle.api.AuditListener;
50  import com.puppycrawl.tools.checkstyle.api.Configuration;
51  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
52  
53  /**
54   * Unit test for IndentationCheck.
55   */
56  public class IndentationCheckTest extends AbstractModuleTestSupport {
57  
58      private static final Pattern LINE_WITH_COMMENT_REGEX =
59                      Pattern.compile(".*?//indent:(\\d+)(?: ioffset:(\\d+))?"
60                          + " exp:(>=)?(\\d+(?:,\\d+)*?)( warn)?$");
61  
62      private static final IndentComment[] EMPTY_INDENT_COMMENT_ARRAY = new IndentComment[0];
63  
64      private static IndentComment[] getLinesWithWarnAndCheckComments(String aFileName,
65              final int tabWidth)
66                      throws IOException {
67          final List<IndentComment> result = new ArrayList<>();
68          try (BufferedReader br = Files.newBufferedReader(Paths.get(aFileName),
69                  StandardCharsets.UTF_8)) {
70              int lineNumber = 1;
71              for (String line = br.readLine(); line != null; line = br.readLine()) {
72                  final Matcher match = LINE_WITH_COMMENT_REGEX.matcher(line);
73                  if (match.matches()) {
74                      final IndentComment warn = new IndentComment(match, lineNumber);
75                      final int actualIndent = getLineStart(line, tabWidth);
76  
77                      if (actualIndent != warn.getIndent()) {
78                          throw new IllegalStateException(String.format(Locale.ROOT,
79                                          "File \"%1$s\" has incorrect indentation in comment. "
80                                                          + "Line %2$d: comment:%3$d, actual:%4$d.",
81                                          aFileName,
82                                          lineNumber,
83                                          warn.getIndent(),
84                                          actualIndent));
85                      }
86  
87                      if (!isCommentConsistent(warn)) {
88                          throw new IllegalStateException(String.format(Locale.ROOT,
89                                          "File \"%1$s\" has inconsistent comment on line %2$d",
90                                          aFileName,
91                                          lineNumber));
92                      }
93  
94                      if (warn.isWarning()) {
95                          result.add(warn);
96                      }
97                  }
98                  else if (!line.isEmpty()) {
99                      throw new IllegalStateException(String.format(Locale.ROOT,
100                                     "File \"%1$s\" has no indentation comment or its format "
101                                                     + "malformed. Error on line: %2$d",
102                                     aFileName,
103                                     lineNumber));
104                 }
105                 lineNumber++;
106             }
107         }
108         return result.toArray(EMPTY_INDENT_COMMENT_ARRAY);
109     }
110 
111     private static boolean isCommentConsistent(IndentComment comment) {
112         final String[] levels = comment.getExpectedWarning().split(", ");
113         final int indent = comment.getIndent() + comment.getIndentOffset();
114         final boolean result;
115         if (levels.length > 1) {
116             // multi
117             final boolean containsActualLevel =
118                             Arrays.asList(levels).contains(String.valueOf(indent));
119 
120             result = containsActualLevel != comment.isWarning();
121         }
122         else {
123             final int expectedWarning = Integer.parseInt(comment.getExpectedWarning());
124 
125             if (comment.isExpectedNonStrict()) {
126                 // non-strict
127                 final boolean test = indent >= expectedWarning;
128                 result = test != comment.isWarning();
129             }
130             else {
131                 // single
132                 final boolean test = expectedWarning == indent;
133                 result = test != comment.isWarning();
134             }
135         }
136         return result;
137     }
138 
139     private static int getLineStart(String line, final int tabWidth) {
140         int lineStart = 0;
141         for (int index = 0; index < line.length(); ++index) {
142             if (!Character.isWhitespace(line.charAt(index))) {
143                 lineStart = CommonUtil.lengthExpandedTabs(line, index, tabWidth);
144                 break;
145             }
146         }
147         return lineStart;
148     }
149 
150     private void verifyWarns(Configuration config, String filePath,
151                     String... expected)
152                     throws Exception {
153         final int tabWidth = Integer.parseInt(config.getAttribute("tabWidth"));
154         final IndentComment[] linesWithWarn =
155                         getLinesWithWarnAndCheckComments(filePath, tabWidth);
156         verify(config, filePath, expected, linesWithWarn);
157         assertEquals("Expected warning count in UT does not match warn"
158                         + " comment count in input file", linesWithWarn.length,
159                         expected.length);
160     }
161 
162     private void verify(Configuration config, String filePath, String[] expected,
163             final IndentComment... linesWithWarn) throws Exception {
164         final Checker checker = createChecker(config);
165         checker.addListener(new IndentAudit(linesWithWarn));
166         verify(checker, filePath, expected);
167     }
168 
169     @Override
170     protected String getPackageLocation() {
171         return "com/puppycrawl/tools/checkstyle/checks/indentation/indentation";
172     }
173 
174     @Test
175     public void testGetRequiredTokens() {
176         final IndentationCheck checkObj = new IndentationCheck();
177         final int[] requiredTokens = checkObj.getRequiredTokens();
178         final HandlerFactory handlerFactory = new HandlerFactory();
179         final int[] expected = handlerFactory.getHandledTypes();
180         Arrays.sort(expected);
181         Arrays.sort(requiredTokens);
182         assertArrayEquals("Default required tokens are invalid", expected, requiredTokens);
183     }
184 
185     @Test
186     public void testGetAcceptableTokens() {
187         final IndentationCheck checkObj = new IndentationCheck();
188         final int[] acceptableTokens = checkObj.getAcceptableTokens();
189         final HandlerFactory handlerFactory = new HandlerFactory();
190         final int[] expected = handlerFactory.getHandledTypes();
191         Arrays.sort(expected);
192         Arrays.sort(acceptableTokens);
193         assertArrayEquals("Default acceptable tokens are invalid", expected, acceptableTokens);
194     }
195 
196     @Test
197     public void testThrowsIndentProperty() {
198         final IndentationCheck indentationCheck = new IndentationCheck();
199 
200         indentationCheck.setThrowsIndent(1);
201 
202         assertEquals("Invalid throws indent", 1, indentationCheck.getThrowsIndent());
203     }
204 
205     @Test
206     public void testStrictCondition() throws Exception {
207         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
208         checkConfig.addAttribute("arrayInitIndent", "4");
209         checkConfig.addAttribute("basicOffset", "4");
210         checkConfig.addAttribute("braceAdjustment", "4");
211         checkConfig.addAttribute("caseIndent", "4");
212         checkConfig.addAttribute("forceStrictCondition", "true");
213         checkConfig.addAttribute("lineWrappingIndentation", "8");
214         checkConfig.addAttribute("tabWidth", "4");
215         checkConfig.addAttribute("throwsIndent", "8");
216         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
217         verifyWarns(checkConfig, getPath("InputIndentationStrictCondition.java"), expected);
218     }
219 
220     @Test
221     public void forbidOldStyle() throws Exception {
222         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
223         checkConfig.addAttribute("arrayInitIndent", "4");
224         checkConfig.addAttribute("basicOffset", "4");
225         checkConfig.addAttribute("braceAdjustment", "0");
226         checkConfig.addAttribute("caseIndent", "4");
227         checkConfig.addAttribute("forceStrictCondition", "true");
228         checkConfig.addAttribute("lineWrappingIndentation", "8");
229         checkConfig.addAttribute("tabWidth", "4");
230         checkConfig.addAttribute("throwsIndent", "8");
231         final String[] expected = {
232             "20: " + getCheckMessage(MSG_ERROR, "int", 29, 12),
233             "21: " + getCheckMessage(MSG_ERROR, "int", 29, 12),
234         };
235         verifyWarns(checkConfig, getPath("InputIndentationMethodCStyle.java"), expected);
236     }
237 
238     @Test
239     public void testZeroCaseLevel() throws Exception {
240         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
241         checkConfig.addAttribute("arrayInitIndent", "4");
242         checkConfig.addAttribute("basicOffset", "4");
243         checkConfig.addAttribute("braceAdjustment", "0");
244         checkConfig.addAttribute("caseIndent", "0");
245         checkConfig.addAttribute("forceStrictCondition", "false");
246         checkConfig.addAttribute("lineWrappingIndentation", "4");
247         checkConfig.addAttribute("tabWidth", "4");
248         checkConfig.addAttribute("throwsIndent", "4");
249         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
250         verifyWarns(checkConfig, getPath("InputIndentationZeroCaseLevel.java"), expected);
251     }
252 
253     @Test
254     public void testAndroidStyle() throws Exception {
255         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
256         checkConfig.addAttribute("arrayInitIndent", "4");
257         checkConfig.addAttribute("basicOffset", "4");
258         checkConfig.addAttribute("braceAdjustment", "0");
259         checkConfig.addAttribute("caseIndent", "4");
260         checkConfig.addAttribute("forceStrictCondition", "false");
261         checkConfig.addAttribute("lineWrappingIndentation", "8");
262         checkConfig.addAttribute("tabWidth", "4");
263         checkConfig.addAttribute("throwsIndent", "8");
264         final String[] expected = {
265             "42: " + getCheckMessage(MSG_ERROR, "extends", 3, 8),
266             "44: " + getCheckMessage(MSG_ERROR, "member def type", 3, 4),
267             "47: " + getCheckMessage(MSG_ERROR, "foo", 8, 12),
268             "50: " + getCheckMessage(MSG_ERROR, "int", 8, 12),
269             "53: " + getCheckMessage(MSG_ERROR, "true", 13, 16),
270             "56: " + getCheckMessage(MSG_ERROR, "+", 16, 20),
271             "57: " + getCheckMessage(MSG_ERROR, "if", 8, 12),
272             "60: " + getCheckMessage(MSG_ERROR, "if rcurly", 11, 12),
273             "62: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 7, 8),
274         };
275         verifyWarns(checkConfig, getPath("InputIndentationAndroidStyle.java"), expected);
276     }
277 
278     @Test
279     public void testMethodCallLineWrap() throws Exception {
280         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
281 
282         checkConfig.addAttribute("arrayInitIndent", "4");
283         checkConfig.addAttribute("basicOffset", "4");
284         checkConfig.addAttribute("braceAdjustment", "0");
285         checkConfig.addAttribute("caseIndent", "4");
286         checkConfig.addAttribute("forceStrictCondition", "false");
287         checkConfig.addAttribute("lineWrappingIndentation", "4");
288         checkConfig.addAttribute("tabWidth", "4");
289         checkConfig.addAttribute("throwsIndent", "4");
290         final String[] expected = {
291             "53: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 18, 20),
292             "54: " + getCheckMessage(MSG_ERROR, "method call rparen", 14, 16),
293             "75: " + getCheckMessage(MSG_ERROR, "lambda arguments", 12, 16),
294         };
295         verifyWarns(checkConfig, getPath("InputIndentationMethodCallLineWrap.java"), expected);
296     }
297 
298     @Test
299     public void testDifficultAnnotations() throws Exception {
300         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
301 
302         checkConfig.addAttribute("arrayInitIndent", "4");
303         checkConfig.addAttribute("basicOffset", "4");
304         checkConfig.addAttribute("braceAdjustment", "0");
305         checkConfig.addAttribute("caseIndent", "4");
306         checkConfig.addAttribute("forceStrictCondition", "false");
307         checkConfig.addAttribute("lineWrappingIndentation", "4");
308         checkConfig.addAttribute("tabWidth", "4");
309         checkConfig.addAttribute("throwsIndent", "4");
310         final String[] expected = {
311             "40: " + getCheckMessage(MSG_ERROR, "@", 0, 4),
312             "41: " + getCheckMessage(MSG_ERROR, "@", 0, 4),
313             "50: " + getCheckMessage(MSG_ERROR, "@", 6, 8),
314         };
315         verifyWarns(checkConfig, getPath("InputIndentationDifficultAnnotations.java"), expected);
316     }
317 
318     @Test
319     public void testAnnotationClosingParenthesisEndsInSameIndentationAsOpening() throws Exception {
320         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
321 
322         checkConfig.addAttribute("basicOffset", "4");
323         checkConfig.addAttribute("forceStrictCondition", "true");
324         checkConfig.addAttribute("tabWidth", "4");
325 
326         final String[] expected = {
327             "34: " + getCheckMessage(MSG_ERROR, ")", 16, 0),
328             "36: " + getCheckMessage(MSG_ERROR, ")", 16, 0),
329             "40: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
330             "42: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
331             "46: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
332         };
333 
334         verifyWarns(checkConfig,
335             getPath("InputIndentation"
336                 + "AnnotationClosingParenthesisEndsInSameIndentationAsOpening.java"),
337                 expected);
338     }
339 
340     @Test
341     public void testAnonClassesFromGuava() throws Exception {
342         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
343 
344         checkConfig.addAttribute("arrayInitIndent", "4");
345         checkConfig.addAttribute("basicOffset", "2");
346         checkConfig.addAttribute("braceAdjustment", "0");
347         checkConfig.addAttribute("caseIndent", "4");
348         checkConfig.addAttribute("forceStrictCondition", "false");
349         checkConfig.addAttribute("lineWrappingIndentation", "4");
350         checkConfig.addAttribute("tabWidth", "4");
351         checkConfig.addAttribute("throwsIndent", "4");
352         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
353         verifyWarns(checkConfig, getPath("InputIndentationFromGuava2.java"), expected);
354     }
355 
356     @Test
357     public void testAnnotations() throws Exception {
358         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
359 
360         checkConfig.addAttribute("arrayInitIndent", "4");
361         checkConfig.addAttribute("basicOffset", "2");
362         checkConfig.addAttribute("braceAdjustment", "0");
363         checkConfig.addAttribute("caseIndent", "4");
364         checkConfig.addAttribute("forceStrictCondition", "false");
365         checkConfig.addAttribute("lineWrappingIndentation", "4");
366         checkConfig.addAttribute("tabWidth", "4");
367         checkConfig.addAttribute("throwsIndent", "4");
368         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
369         verifyWarns(checkConfig, getPath("InputIndentationFromGuava.java"), expected);
370     }
371 
372     @Test
373     public void testCorrectIfAndParameters() throws Exception {
374         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
375 
376         checkConfig.addAttribute("arrayInitIndent", "4");
377         checkConfig.addAttribute("basicOffset", "2");
378         checkConfig.addAttribute("braceAdjustment", "0");
379         checkConfig.addAttribute("caseIndent", "4");
380         checkConfig.addAttribute("forceStrictCondition", "false");
381         checkConfig.addAttribute("lineWrappingIndentation", "4");
382         checkConfig.addAttribute("tabWidth", "4");
383         checkConfig.addAttribute("throwsIndent", "4");
384         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
385         verifyWarns(checkConfig, getPath("InputIndentationCorrectIfAndParameter.java"), expected);
386     }
387 
388     @Test
389     public void testAnonymousClasses() throws Exception {
390         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
391 
392         checkConfig.addAttribute("arrayInitIndent", "4");
393         checkConfig.addAttribute("basicOffset", "2");
394         checkConfig.addAttribute("braceAdjustment", "0");
395         checkConfig.addAttribute("caseIndent", "4");
396         checkConfig.addAttribute("forceStrictCondition", "false");
397         checkConfig.addAttribute("lineWrappingIndentation", "4");
398         checkConfig.addAttribute("tabWidth", "4");
399         checkConfig.addAttribute("throwsIndent", "4");
400         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
401         verifyWarns(checkConfig, getPath("InputIndentationAnonymousClasses.java"), expected);
402     }
403 
404     @Test
405     public void testArrays() throws Exception {
406         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
407 
408         checkConfig.addAttribute("arrayInitIndent", "2");
409         checkConfig.addAttribute("basicOffset", "2");
410         checkConfig.addAttribute("braceAdjustment", "0");
411         checkConfig.addAttribute("caseIndent", "4");
412         checkConfig.addAttribute("forceStrictCondition", "false");
413         checkConfig.addAttribute("lineWrappingIndentation", "4");
414         checkConfig.addAttribute("tabWidth", "4");
415         checkConfig.addAttribute("throwsIndent", "4");
416         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
417         verifyWarns(checkConfig, getPath("InputIndentationArrays.java"), expected);
418     }
419 
420     @Test
421     public void testLabels() throws Exception {
422         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
423 
424         checkConfig.addAttribute("arrayInitIndent", "4");
425         checkConfig.addAttribute("basicOffset", "2");
426         checkConfig.addAttribute("braceAdjustment", "0");
427         checkConfig.addAttribute("caseIndent", "4");
428         checkConfig.addAttribute("forceStrictCondition", "false");
429         checkConfig.addAttribute("lineWrappingIndentation", "4");
430         checkConfig.addAttribute("tabWidth", "4");
431         checkConfig.addAttribute("throwsIndent", "4");
432         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
433         verifyWarns(checkConfig, getPath("InputIndentationLabels.java"), expected);
434     }
435 
436     @Test
437     public void testClassesAndMethods() throws Exception {
438         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
439 
440         checkConfig.addAttribute("arrayInitIndent", "4");
441         checkConfig.addAttribute("basicOffset", "2");
442         checkConfig.addAttribute("braceAdjustment", "0");
443         checkConfig.addAttribute("caseIndent", "4");
444         checkConfig.addAttribute("forceStrictCondition", "false");
445         checkConfig.addAttribute("lineWrappingIndentation", "4");
446         checkConfig.addAttribute("tabWidth", "4");
447         checkConfig.addAttribute("throwsIndent", "4");
448         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
449         verifyWarns(checkConfig, getPath("InputIndentationClassesMethods.java"), expected);
450     }
451 
452     @Test
453     public void testCtorCall() throws Exception {
454         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
455 
456         checkConfig.addAttribute("basicOffset", "2");
457         checkConfig.addAttribute("braceAdjustment", "0");
458         checkConfig.addAttribute("lineWrappingIndentation", "4");
459         checkConfig.addAttribute("tabWidth", "4");
460         final String[] expected = {
461             "28: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
462             "29: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
463             "30: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
464             "34: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
465             "35: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
466             "39: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
467             "40: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
468             "41: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
469             "45: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
470             "46: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
471             "50: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
472             "51: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
473             "52: " + getCheckMessage(MSG_ERROR, "x", 4, 8),
474             "56: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
475             "57: " + getCheckMessage(MSG_ERROR, "method call lparen", 4, 6),
476             "62: " + getCheckMessage(MSG_ERROR, ".", 4, 10),
477             "63: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
478             "68: " + getCheckMessage(MSG_ERROR, "super", 4, 10),
479             "69: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
480         };
481         verifyWarns(checkConfig, getPath("InputIndentationCtorCall.java"), expected);
482     }
483 
484     @Test
485     public void testMembers() throws Exception {
486         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
487 
488         checkConfig.addAttribute("arrayInitIndent", "4");
489         checkConfig.addAttribute("basicOffset", "2");
490         checkConfig.addAttribute("braceAdjustment", "0");
491         checkConfig.addAttribute("caseIndent", "4");
492         checkConfig.addAttribute("forceStrictCondition", "false");
493         checkConfig.addAttribute("lineWrappingIndentation", "4");
494         checkConfig.addAttribute("tabWidth", "4");
495         checkConfig.addAttribute("throwsIndent", "4");
496         final String[] expected = {
497             "22: " + getCheckMessage(MSG_ERROR, "=", 5, 6),
498             "57: " + getCheckMessage(MSG_ERROR, "class def rcurly", 3, 2),
499         };
500 
501         verifyWarns(checkConfig, getPath("InputIndentationMembers.java"), expected);
502     }
503 
504     @Test
505     public void testInvalidLabel() throws Exception {
506         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
507 
508         checkConfig.addAttribute("arrayInitIndent", "4");
509         checkConfig.addAttribute("basicOffset", "4");
510         checkConfig.addAttribute("braceAdjustment", "0");
511         checkConfig.addAttribute("caseIndent", "4");
512         checkConfig.addAttribute("forceStrictCondition", "false");
513         checkConfig.addAttribute("lineWrappingIndentation", "4");
514         checkConfig.addAttribute("tabWidth", "4");
515         checkConfig.addAttribute("throwsIndent", "4");
516         final String[] expected = {
517             "24: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 10, "8, 12"),
518             "33: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 2, "4, 8"),
519             "36: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 18, "8, 12"),
520             "37: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 18, 8),
521             "39: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 6, "8, 12"),
522             "41: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 6, "8, 12"),
523         };
524         verifyWarns(checkConfig, getPath("InputIndentationInvalidLabelIndent.java"), expected);
525     }
526 
527     @Test
528     public void testInvalidLabelWithWhileLoop() throws Exception {
529         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
530 
531         checkConfig.addAttribute("arrayInitIndent", "4");
532         checkConfig.addAttribute("basicOffset", "4");
533         checkConfig.addAttribute("braceAdjustment", "0");
534         checkConfig.addAttribute("caseIndent", "4");
535         checkConfig.addAttribute("forceStrictCondition", "false");
536         checkConfig.addAttribute("lineWrappingIndentation", "4");
537         checkConfig.addAttribute("tabWidth", "4");
538         checkConfig.addAttribute("throwsIndent", "4");
539         final String[] expected = {
540             "18: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 9, "4, 8"),
541             "19: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 9, "8, 12"),
542         };
543         verifyWarns(checkConfig, getPath("InputIndentationInvalidLabelWithWhileLoopIndent.java"),
544             expected);
545     }
546 
547     @Test
548     public void testValidLabel() throws Exception {
549         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
550 
551         checkConfig.addAttribute("arrayInitIndent", "4");
552         checkConfig.addAttribute("basicOffset", "4");
553         checkConfig.addAttribute("braceAdjustment", "0");
554         checkConfig.addAttribute("caseIndent", "4");
555         checkConfig.addAttribute("forceStrictCondition", "false");
556         checkConfig.addAttribute("lineWrappingIndentation", "4");
557         checkConfig.addAttribute("tabWidth", "4");
558         checkConfig.addAttribute("throwsIndent", "4");
559         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
560         verifyWarns(checkConfig, getPath("InputIndentationValidLabelIndent.java"), expected);
561     }
562 
563     @Test
564     public void testValidIfWithChecker() throws Exception {
565         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
566 
567         checkConfig.addAttribute("arrayInitIndent", "4");
568         checkConfig.addAttribute("basicOffset", "4");
569         checkConfig.addAttribute("braceAdjustment", "0");
570         checkConfig.addAttribute("caseIndent", "4");
571         checkConfig.addAttribute("forceStrictCondition", "false");
572         checkConfig.addAttribute("lineWrappingIndentation", "4");
573         checkConfig.addAttribute("tabWidth", "4");
574         checkConfig.addAttribute("throwsIndent", "4");
575         final String fileName = getPath("InputIndentationValidIfIndent.java");
576         final String[] expected = {
577             "231: " + getCheckMessage(MSG_ERROR, "(", 8, 12),
578         };
579         verifyWarns(checkConfig, fileName, expected);
580     }
581 
582     @Test
583     public void testValidDotWithChecker()
584             throws Exception {
585         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
586 
587         checkConfig.addAttribute("arrayInitIndent", "4");
588         checkConfig.addAttribute("basicOffset", "4");
589         checkConfig.addAttribute("braceAdjustment", "0");
590         checkConfig.addAttribute("caseIndent", "4");
591         checkConfig.addAttribute("forceStrictCondition", "false");
592         checkConfig.addAttribute("lineWrappingIndentation", "4");
593         checkConfig.addAttribute("tabWidth", "4");
594         checkConfig.addAttribute("throwsIndent", "4");
595         final String fileName = getPath("InputIndentationValidDotIndent.java");
596         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
597         verifyWarns(checkConfig, fileName, expected);
598     }
599 
600     @Test
601     public void testValidMethodWithChecker()
602             throws Exception {
603         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
604 
605         checkConfig.addAttribute("arrayInitIndent", "4");
606         checkConfig.addAttribute("basicOffset", "4");
607         checkConfig.addAttribute("braceAdjustment", "0");
608         checkConfig.addAttribute("caseIndent", "4");
609         checkConfig.addAttribute("forceStrictCondition", "false");
610         checkConfig.addAttribute("lineWrappingIndentation", "4");
611         checkConfig.addAttribute("tabWidth", "4");
612         checkConfig.addAttribute("throwsIndent", "4");
613         final String fileName = getPath("InputIndentationValidMethodIndent.java");
614         final String[] expected = {
615             "129: " + getCheckMessage(MSG_ERROR, "void", 4, 8),
616             "130: " + getCheckMessage(MSG_ERROR, "method5", 4, 8),
617         };
618         verifyWarns(checkConfig, fileName, expected);
619     }
620 
621     @Test
622     public void testInvalidMethodWithChecker()
623             throws Exception {
624         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
625 
626         checkConfig.addAttribute("arrayInitIndent", "4");
627         checkConfig.addAttribute("basicOffset", "4");
628         checkConfig.addAttribute("braceAdjustment", "0");
629         checkConfig.addAttribute("caseIndent", "4");
630         checkConfig.addAttribute("forceStrictCondition", "false");
631         checkConfig.addAttribute("lineWrappingIndentation", "4");
632         checkConfig.addAttribute("tabWidth", "4");
633         checkConfig.addAttribute("throwsIndent", "4");
634         final String fileName = getPath("InputIndentationInvalidMethodIndent.java");
635         final String[] expected = {
636             "23: " + getCheckMessage(MSG_ERROR, "ctor def rcurly", 6, 4),
637             "26: " + getCheckMessage(MSG_ERROR, "ctor def modifier", 6, 4),
638             "27: " + getCheckMessage(MSG_ERROR, "ctor def lcurly", 2, 4),
639             "28: " + getCheckMessage(MSG_ERROR, "ctor def rcurly", 6, 4),
640             "31: " + getCheckMessage(MSG_ERROR, "method def modifier", 2, 4),
641             "32: " + getCheckMessage(MSG_ERROR, "method def rcurly", 6, 4),
642             "69: " + getCheckMessage(MSG_ERROR, "method def modifier", 5, 4),
643             "70: " + getCheckMessage(MSG_ERROR, "final", 5, 9),
644             "71: " + getCheckMessage(MSG_ERROR, "void", 5, 9),
645             "72: " + getCheckMessage(MSG_ERROR, "method5", 4, 9),
646             "80: " + getCheckMessage(MSG_ERROR, "method def modifier", 3, 4),
647             "81: " + getCheckMessage(MSG_ERROR, "final", 3, 7),
648             "82: " + getCheckMessage(MSG_ERROR, "void", 3, 7),
649             "83: " + getCheckMessage(MSG_ERROR, "method6", 5, 7),
650             "93: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 8),
651             "98: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 6, 8),
652             "99: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
653             "100: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
654             "101: " + getCheckMessage(MSG_ERROR, "if rcurly", 6, 8),
655             "104: " + getCheckMessage(MSG_ERROR, "Arrays", 10, 12),
656             "113: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
657             "122: " + getCheckMessage(MSG_ERROR, "new", 10, 12),
658             "126: " + getCheckMessage(MSG_ERROR, "new", 10, 12),
659             "127: " + getCheckMessage(MSG_ERROR, ")", 6, 8),
660             "131: " + getCheckMessage(MSG_ERROR, "method call rparen", 6, 8),
661             "145: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
662             "148: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
663             "158: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 6, 12),
664             "170: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 4, 8),
665             "175: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 4, 8),
666             "179: " + getCheckMessage(MSG_ERROR, "int", 0, 8),
667             "180: " + getCheckMessage(MSG_ERROR, "method9", 4, 8),
668             "190: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
669         };
670         verifyWarns(checkConfig, fileName, expected);
671     }
672 
673     @Test
674     public void testInvalidSwitchWithChecker()
675             throws Exception {
676         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
677 
678         checkConfig.addAttribute("arrayInitIndent", "4");
679         checkConfig.addAttribute("basicOffset", "4");
680         checkConfig.addAttribute("braceAdjustment", "0");
681         checkConfig.addAttribute("caseIndent", "4");
682         checkConfig.addAttribute("forceStrictCondition", "false");
683         checkConfig.addAttribute("lineWrappingIndentation", "4");
684         checkConfig.addAttribute("tabWidth", "4");
685         checkConfig.addAttribute("throwsIndent", "4");
686         final String fileName = getPath("InputIndentationInvalidSwitchIndent.java");
687         final String[] expected = {
688             "30: " + getCheckMessage(MSG_ERROR, "switch", 6, 8),
689             "32: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
690             "33: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
691             "37: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
692             "39: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 12),
693             "40: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
694             "43: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
695             "44: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
696             "45: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
697             "53: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
698             "54: " + getCheckMessage(MSG_CHILD_ERROR, "block", 18, 16),
699             "55: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
700             "59: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
701             "62: " + getCheckMessage(MSG_ERROR, "block rcurly", 14, 12),
702             "66: " + getCheckMessage(MSG_ERROR, "block lcurly", 14, 12),
703             "69: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
704             "76: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 16),
705             "81: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 16),
706             "89: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
707             "92: " + getCheckMessage(MSG_ERROR, "switch lcurly", 6, 8),
708             "93: " + getCheckMessage(MSG_ERROR, "switch rcurly", 10, 8),
709             "95: " + getCheckMessage(MSG_ERROR, "switch lcurly", 10, 8),
710             "96: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
711             "99: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
712             "100: " + getCheckMessage(MSG_ERROR, "if", 12, 16),
713             "101: " + getCheckMessage(MSG_CHILD_ERROR, "if", 16, 20),
714             "102: " + getCheckMessage(MSG_ERROR, "else", 12, 16),
715             "103: " + getCheckMessage(MSG_CHILD_ERROR, "else", 16, 20),
716         };
717         verifyWarns(checkConfig, fileName, expected);
718     }
719 
720     @Test
721     public void testValidSwitchWithChecker()
722             throws Exception {
723         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
724 
725         checkConfig.addAttribute("arrayInitIndent", "4");
726         checkConfig.addAttribute("basicOffset", "4");
727         checkConfig.addAttribute("braceAdjustment", "0");
728         checkConfig.addAttribute("caseIndent", "4");
729         checkConfig.addAttribute("forceStrictCondition", "false");
730         checkConfig.addAttribute("lineWrappingIndentation", "4");
731         checkConfig.addAttribute("tabWidth", "4");
732         checkConfig.addAttribute("throwsIndent", "4");
733         final String fileName = getPath("InputIndentationValidSwitchIndent.java");
734         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
735         verifyWarns(checkConfig, fileName, expected);
736     }
737 
738     @Test
739     public void testValidArrayInitDefaultIndentWithChecker()
740             throws Exception {
741         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
742 
743         checkConfig.addAttribute("arrayInitIndent", "4");
744         checkConfig.addAttribute("basicOffset", "4");
745         checkConfig.addAttribute("braceAdjustment", "0");
746         checkConfig.addAttribute("caseIndent", "4");
747         checkConfig.addAttribute("forceStrictCondition", "false");
748         checkConfig.addAttribute("lineWrappingIndentation", "4");
749         checkConfig.addAttribute("tabWidth", "4");
750         checkConfig.addAttribute("throwsIndent", "4");
751         final String fileName = getPath("InputIndentationValidArrayInitDefaultIndent.java");
752         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
753         verifyWarns(checkConfig, fileName, expected);
754     }
755 
756     @Test
757     public void testValidArrayInitWithChecker()
758             throws Exception {
759         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
760 
761         checkConfig.addAttribute("arrayInitIndent", "8");
762         checkConfig.addAttribute("basicOffset", "4");
763         checkConfig.addAttribute("braceAdjustment", "0");
764         checkConfig.addAttribute("caseIndent", "4");
765         checkConfig.addAttribute("forceStrictCondition", "false");
766         checkConfig.addAttribute("lineWrappingIndentation", "4");
767         checkConfig.addAttribute("tabWidth", "4");
768         checkConfig.addAttribute("throwsIndent", "4");
769         final String fileName = getPath("InputIndentationValidArrayInitIndent.java");
770         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
771         verifyWarns(checkConfig, fileName, expected);
772     }
773 
774     @Test
775     public void testInvalidArrayInitWithChecker()
776             throws Exception {
777         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
778 
779         checkConfig.addAttribute("arrayInitIndent", "4");
780         checkConfig.addAttribute("basicOffset", "4");
781         checkConfig.addAttribute("braceAdjustment", "0");
782         checkConfig.addAttribute("caseIndent", "4");
783         checkConfig.addAttribute("forceStrictCondition", "false");
784         checkConfig.addAttribute("lineWrappingIndentation", "4");
785         checkConfig.addAttribute("tabWidth", "4");
786         checkConfig.addAttribute("throwsIndent", "4");
787         final String fileName = getPath("InputIndentationInvalidArrayInitIndent.java");
788         final String[] expected = {
789             "21: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
790             "22: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
791             "24: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
792             "28: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
793             "29: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 8, 10),
794             "30: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 4, "6, 10"),
795             "33: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 9, 8),
796             "34: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 7, 8),
797             "35: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 9, 8),
798             "40: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
799             "44: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "4, 8"),
800             "48: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
801             "52: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 20,
802                 "8, 31, 33"),
803             "53: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 4, "8, 31, 33"),
804             "58: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 6, 8),
805             "63: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
806             "65: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
807             "66: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 2, "6, 10"),
808             "69: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 6, 8),
809             "76: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12),
810             "89: " + getCheckMessage(MSG_ERROR, "1", 8, 12),
811             "100: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12),
812             "101: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12),
813             "104: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12),
814             "105: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12),
815             "106: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
816             "109: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 6, "8, 12"),
817             "110: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12),
818             "111: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12),
819             "112: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
820         };
821 
822         //Test input for this test case is not checked due to issue #693.
823         verify(checkConfig, fileName, expected);
824     }
825 
826     @Test
827     public void testValidTryWithChecker()
828             throws Exception {
829         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
830 
831         checkConfig.addAttribute("arrayInitIndent", "4");
832         checkConfig.addAttribute("basicOffset", "4");
833         checkConfig.addAttribute("braceAdjustment", "0");
834         checkConfig.addAttribute("caseIndent", "4");
835         checkConfig.addAttribute("forceStrictCondition", "false");
836         checkConfig.addAttribute("lineWrappingIndentation", "4");
837         checkConfig.addAttribute("tabWidth", "4");
838         checkConfig.addAttribute("throwsIndent", "4");
839         final String fileName = getPath("InputIndentationValidTryIndent.java");
840         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
841         verifyWarns(checkConfig, fileName, expected);
842     }
843 
844     @Test
845     public void testInvalidTryWithChecker()
846             throws Exception {
847         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
848 
849         checkConfig.addAttribute("arrayInitIndent", "4");
850         checkConfig.addAttribute("basicOffset", "4");
851         checkConfig.addAttribute("braceAdjustment", "0");
852         checkConfig.addAttribute("caseIndent", "4");
853         checkConfig.addAttribute("forceStrictCondition", "false");
854         checkConfig.addAttribute("lineWrappingIndentation", "4");
855         checkConfig.addAttribute("tabWidth", "4");
856         checkConfig.addAttribute("throwsIndent", "4");
857         final String fileName = getPath("InputIndentationInvalidTryIndent.java");
858         final String[] expected = {
859             "25: " + getCheckMessage(MSG_ERROR, "try", 9, 8),
860             "26: " + getCheckMessage(MSG_ERROR, "try rcurly", 7, 8),
861             "28: " + getCheckMessage(MSG_ERROR, "catch rcurly", 7, 8),
862             "30: " + getCheckMessage(MSG_ERROR, "try", 4, 8),
863             "31: " + getCheckMessage(MSG_CHILD_ERROR, "try", 8, 12),
864             "32: " + getCheckMessage(MSG_ERROR, "try rcurly", 4, 8),
865             "33: " + getCheckMessage(MSG_CHILD_ERROR, "finally", 8, 12),
866             "38: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 8, 12),
867             "43: " + getCheckMessage(MSG_ERROR, "try rcurly", 10, 8),
868             "45: " + getCheckMessage(MSG_ERROR, "catch rcurly", 6, 8),
869             "52: " + getCheckMessage(MSG_ERROR, "catch rcurly", 5, 8),
870             "59: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
871             "60: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 14, 12),
872             "61: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
873             "63: " + getCheckMessage(MSG_ERROR, "catch", 6, 8),
874             "70: " + getCheckMessage(MSG_ERROR, "try lcurly", 10, 8),
875             "72: " + getCheckMessage(MSG_ERROR, "try rcurly", 10, 8),
876             "74: " + getCheckMessage(MSG_ERROR, "catch lcurly", 6, 8),
877             "77: " + getCheckMessage(MSG_ERROR, "catch rcurly", 10, 8),
878             "80: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
879             "86: " + getCheckMessage(MSG_ERROR, "try", 0, 8),
880             "87: " + getCheckMessage(MSG_ERROR, "try rcurly", 0, 8),
881             "88: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 0, 12),
882             "89: " + getCheckMessage(MSG_ERROR, "catch rcurly", 0, 8),
883             "91: " + getCheckMessage(MSG_ERROR, "try", 0, 8),
884             "92: " + getCheckMessage(MSG_ERROR, "try rcurly", 0, 8),
885             "93: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 0, 12),
886             "94: " + getCheckMessage(MSG_ERROR, "catch rcurly", 0, 8),
887         };
888         verifyWarns(checkConfig, fileName, expected);
889     }
890 
891     @Test
892     public void testInvalidClassDefWithChecker()
893             throws Exception {
894         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
895 
896         checkConfig.addAttribute("arrayInitIndent", "4");
897         checkConfig.addAttribute("basicOffset", "4");
898         checkConfig.addAttribute("braceAdjustment", "0");
899         checkConfig.addAttribute("caseIndent", "4");
900         checkConfig.addAttribute("forceStrictCondition", "false");
901         checkConfig.addAttribute("lineWrappingIndentation", "4");
902         checkConfig.addAttribute("tabWidth", "4");
903         checkConfig.addAttribute("throwsIndent", "4");
904         final String fileName = getPath("InputIndentationInvalidClassDefIndent.java");
905         final String[] expected = {
906             "22: " + getCheckMessage(MSG_ERROR, "class def modifier", 2, 0),
907             "28: " + getCheckMessage(MSG_ERROR, "class def lcurly", 2, 0),
908             "31: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
909             "34: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 0),
910             "38: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
911             "43: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
912             "44: " + getCheckMessage(MSG_ERROR, "implements", 2, 4),
913             "50: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
914             "58: " + getCheckMessage(MSG_ERROR, "implements", 2, 4),
915             "59: " + getCheckMessage(MSG_ERROR, "java", 2, 4),
916             "64: " + getCheckMessage(MSG_ERROR, "class def modifier", 2, 0),
917             "65: " + getCheckMessage(MSG_ERROR, "class def lcurly", 2, 0),
918             "73: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
919             "77: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
920             "86: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 4),
921             "88: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 4),
922             "91: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 4),
923             "95: " + getCheckMessage(MSG_ERROR, "member def modifier", 6, 8),
924             "101: " + getCheckMessage(MSG_ERROR, "int", 10, 12),
925             "106: " + getCheckMessage(MSG_ERROR, "member def modifier", 6, 8),
926             "111: " + getCheckMessage(MSG_ERROR, "class def rcurly", 6, 4),
927             "113: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 4),
928             "119: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 8),
929             "122: " + getCheckMessage(MSG_ERROR, "class def ident", 10, 8),
930             "124: " + getCheckMessage(MSG_ERROR, "class def rcurly", 10, 8),
931             "127: " + getCheckMessage(MSG_ERROR, "member def type", 10, 12),
932             "132: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 10, 8),
933             "133: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 8, "10, 14"),
934             "137: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 8, "10, 14"),
935             "141: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 6, "8, 12"),
936             "142: " + getCheckMessage(MSG_ERROR, "method def modifier", 12, 10),
937             "144: " + getCheckMessage(MSG_ERROR, "method def rcurly", 12, 10),
938             "145: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 6, "8, 12"),
939             "150: " + getCheckMessage(MSG_ERROR, "method def modifier", 10, 12),
940             "152: " + getCheckMessage(MSG_ERROR, "method def rcurly", 10, 12),
941             "188: " + getCheckMessage(MSG_ERROR, "class", 0, 4),
942         };
943         verifyWarns(checkConfig, fileName, expected);
944     }
945 
946     @Test
947     public void testInvalidBlockWithChecker()
948             throws Exception {
949         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
950 
951         checkConfig.addAttribute("arrayInitIndent", "4");
952         checkConfig.addAttribute("basicOffset", "4");
953         checkConfig.addAttribute("braceAdjustment", "0");
954         checkConfig.addAttribute("caseIndent", "4");
955         checkConfig.addAttribute("forceStrictCondition", "false");
956         checkConfig.addAttribute("lineWrappingIndentation", "4");
957         checkConfig.addAttribute("tabWidth", "4");
958         checkConfig.addAttribute("throwsIndent", "4");
959         final String fileName = getPath("InputIndentationInvalidBlockIndent.java");
960         final String[] expected = {
961             "26: " + getCheckMessage(MSG_ERROR, "block lcurly", 7, 8),
962             "27: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
963             "29: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
964             "30: " + getCheckMessage(MSG_ERROR, "block rcurly", 7, 8),
965             "32: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
966             "34: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 8),
967             "35: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
968             "38: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
969             "39: " + getCheckMessage(MSG_CHILD_ERROR, "block", 13, 12),
970             "41: " + getCheckMessage(MSG_CHILD_ERROR, "block", 13, 12),
971             "42: " + getCheckMessage(MSG_ERROR, "block rcurly", 9, 8),
972             "45: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
973             "46: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
974             "48: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
975             "49: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 8),
976             "52: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
977             "55: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
978             "59: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
979             "63: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
980             "68: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
981             "70: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
982             "71: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
983             "86: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
984             "95: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
985             "96: " + getCheckMessage(MSG_ERROR, "static initialization", 6, 4),
986             "100: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 7, 8),
987             "103: " + getCheckMessage(MSG_ERROR, "static initialization", 6, 4),
988             "105: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 2, 4),
989             "107: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
990             "109: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
991             "111: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
992             "113: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
993             "116: " + getCheckMessage(MSG_ERROR, "static initialization lcurly", 2, 4),
994             "117: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
995             "118: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
996             "123: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
997             "128: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 4, 8),
998             "129: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 2, 4),
999             "134: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
1000             "137: " + getCheckMessage(MSG_ERROR, "block lcurly", 2, 4),
1001             "138: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 4),
1002             "141: " + getCheckMessage(MSG_ERROR, "block lcurly", 2, 4),
1003             "143: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 4),
1004             "145: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 4),
1005             "147: " + getCheckMessage(MSG_ERROR, "block rcurly", 2, 4),
1006             "150: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 8),
1007         };
1008         verifyWarns(checkConfig, fileName, expected);
1009     }
1010 
1011     @Test
1012     public void testInvalidIfWithChecker()
1013             throws Exception {
1014         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1015 
1016         checkConfig.addAttribute("arrayInitIndent", "4");
1017         checkConfig.addAttribute("basicOffset", "4");
1018         checkConfig.addAttribute("braceAdjustment", "0");
1019         checkConfig.addAttribute("caseIndent", "4");
1020         checkConfig.addAttribute("forceStrictCondition", "false");
1021         checkConfig.addAttribute("lineWrappingIndentation", "4");
1022         checkConfig.addAttribute("tabWidth", "4");
1023         checkConfig.addAttribute("throwsIndent", "4");
1024         final String fileName = getPath("InputIndentationInvalidIfIndent.java");
1025         final String[] expected = {
1026             "55: " + getCheckMessage(MSG_ERROR, "if", 1, 8),
1027             "60: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
1028             "61: " + getCheckMessage(MSG_ERROR, "if lcurly", 9, 8),
1029             "62: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
1030             "64: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
1031             "65: " + getCheckMessage(MSG_ERROR, "if lcurly", 5, 8),
1032             "66: " + getCheckMessage(MSG_ERROR, "if rcurly", 5, 8),
1033             "70: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
1034             "71: " + getCheckMessage(MSG_ERROR, "else rcurly", 7, 8),
1035             "74: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
1036 
1037             "75: " + getCheckMessage(MSG_ERROR, "if lcurly", 7, 8),
1038             "77: " + getCheckMessage(MSG_ERROR, "else", 9, 8),
1039             "79: " + getCheckMessage(MSG_ERROR, "else rcurly", 9, 8),
1040             "82: " + getCheckMessage(MSG_ERROR, "if", 10, 8),
1041             "83: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
1042             "84: " + getCheckMessage(MSG_ERROR, "else", 9, 8),
1043             "85: " + getCheckMessage(MSG_ERROR, "else lcurly", 7, 8),
1044             "86: " + getCheckMessage(MSG_ERROR, "else rcurly", 9, 8),
1045 
1046             "90: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
1047             "91: " + getCheckMessage(MSG_ERROR, "if lcurly", 9, 8),
1048             "92: " + getCheckMessage(MSG_ERROR, "if rcurly", 9, 8),
1049             "93: " + getCheckMessage(MSG_ERROR, "else lcurly", 7, 8),
1050             "94: " + getCheckMessage(MSG_ERROR, "else rcurly", 10, 8),
1051             "97: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
1052             "98: " + getCheckMessage(MSG_ERROR, "if lcurly", 10, 8),
1053             "99: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
1054             "100: " + getCheckMessage(MSG_ERROR, "else rcurly", 7, 8),
1055             "103: " + getCheckMessage(MSG_ERROR, "if", 5, 8),
1056             "104: " + getCheckMessage(MSG_ERROR, "if rcurly", 11, 8),
1057             "105: " + getCheckMessage(MSG_ERROR, "else", 5, 8),
1058             "106: " + getCheckMessage(MSG_ERROR, "else rcurly", 11, 8),
1059 
1060             "126: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
1061             "131: " + getCheckMessage(MSG_ERROR, "if lcurly", 10, 8),
1062             "132: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
1063             "137: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
1064             "138: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
1065             "140: " + getCheckMessage(MSG_CHILD_ERROR, "else", 10, 12),
1066             "141: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 12),
1067 
1068             "148: " + getCheckMessage(MSG_CHILD_ERROR, "if", 16, 12),
1069             "149: " + getCheckMessage(MSG_ERROR, "if rcurly", 9, 8),
1070             "152: " + getCheckMessage(MSG_CHILD_ERROR, "else", 16, 12),
1071             "158: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
1072             "162: " + getCheckMessage(MSG_CHILD_ERROR, "else", 40, 12),
1073             "169: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
1074 
1075             "172: " + getCheckMessage(MSG_CHILD_ERROR, "else", 14, 12),
1076             "178: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
1077             "180: " + getCheckMessage(MSG_CHILD_ERROR, "else", 10, 12),
1078             "184: " + getCheckMessage(MSG_ERROR, "if", 10, 8),
1079             "185: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
1080             "186: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
1081             "187: " + getCheckMessage(MSG_ERROR, "else", 10, 8),
1082 
1083             "188: " + getCheckMessage(MSG_CHILD_ERROR, "else", 14, 12),
1084             "189: " + getCheckMessage(MSG_ERROR, "else rcurly", 10, 8),
1085             "192: " + getCheckMessage(MSG_CHILD_ERROR, "if", 9, 12),
1086             "193: " + getCheckMessage(MSG_CHILD_ERROR, "if", 11, 12),
1087             "197: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
1088             "200: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
1089             "207: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
1090             "209: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
1091 
1092             "225: " + getCheckMessage(MSG_ERROR, "if", 10, 12),
1093             "229: " + getCheckMessage(MSG_CHILD_ERROR, "if", 18, 20),
1094             "240: " + getCheckMessage(MSG_ERROR, "if rparen", 10, 8),
1095             "245: " + getCheckMessage(MSG_ERROR, "if rparen", 6, 8),
1096             "251: " + getCheckMessage(MSG_ERROR, "if lparen", 6, 8),
1097             "253: " + getCheckMessage(MSG_ERROR, "if rparen", 6, 8),
1098             "256: " + getCheckMessage(MSG_ERROR, "if", 0, 8),
1099             "257: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
1100             "258: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
1101             "259: " + getCheckMessage(MSG_ERROR, "if rcurly", 0, 8),
1102             "260: " + getCheckMessage(MSG_ERROR, "if", 0, 8),
1103             "262: " + getCheckMessage(MSG_ERROR, "else", 0, 8),
1104         };
1105         verifyWarns(checkConfig, fileName, expected);
1106     }
1107 
1108     @Test
1109     public void testInvalidWhileWithChecker()
1110             throws Exception {
1111         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1112 
1113         checkConfig.addAttribute("arrayInitIndent", "4");
1114         checkConfig.addAttribute("basicOffset", "4");
1115         checkConfig.addAttribute("braceAdjustment", "0");
1116         checkConfig.addAttribute("caseIndent", "4");
1117         checkConfig.addAttribute("forceStrictCondition", "false");
1118         checkConfig.addAttribute("lineWrappingIndentation", "4");
1119         checkConfig.addAttribute("tabWidth", "4");
1120         checkConfig.addAttribute("throwsIndent", "4");
1121         final String fileName = getPath("InputIndentationInvalidWhileIndent.java");
1122         final String[] expected = {
1123             "25: " + getCheckMessage(MSG_ERROR, "while", 9, 8),
1124             "26: " + getCheckMessage(MSG_ERROR, "while rcurly", 7, 8),
1125             "28: " + getCheckMessage(MSG_ERROR, "while", 7, 8),
1126             "29: " + getCheckMessage(MSG_ERROR, "while lcurly", 9, 8),
1127             "30: " + getCheckMessage(MSG_ERROR, "while rcurly", 9, 8),
1128 
1129             "32: " + getCheckMessage(MSG_ERROR, "while", 9, 8),
1130             "33: " + getCheckMessage(MSG_ERROR, "while lcurly", 6, 8),
1131             "34: " + getCheckMessage(MSG_CHILD_ERROR, "while", 14, 12),
1132             "35: " + getCheckMessage(MSG_ERROR, "while rcurly", 6, 8),
1133 
1134             "37: " + getCheckMessage(MSG_ERROR, "while", 10, 8),
1135             "39: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
1136             "41: " + getCheckMessage(MSG_ERROR, "while", 10, 8),
1137             "44: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
1138 
1139             "46: " + getCheckMessage(MSG_ERROR, "while", 6, 8),
1140             "47: " + getCheckMessage(MSG_ERROR, "while lcurly", 10, 8),
1141             "50: " + getCheckMessage(MSG_ERROR, "while rcurly", 6, 8),
1142             "53: " + getCheckMessage(MSG_ERROR, "if", 14, 12),
1143             "54: " + getCheckMessage(MSG_CHILD_ERROR, "if", 18, 16),
1144             "55: " + getCheckMessage(MSG_ERROR, "if rcurly", 14, 12),
1145             "56: " + getCheckMessage(MSG_CHILD_ERROR, "while", 14, 12),
1146             "57: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
1147 
1148             "60: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
1149             "66: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
1150             "71: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
1151             "78: " + getCheckMessage(MSG_ERROR, "while rparen", 5, 8),
1152             "85: " + getCheckMessage(MSG_ERROR, "while rparen", 10, 8),
1153             "92: " + getCheckMessage(MSG_ERROR, "while rparen", 10, 8),
1154             "99: " + getCheckMessage(MSG_CHILD_ERROR, "while", 8, 12),
1155         };
1156         verifyWarns(checkConfig, fileName, expected);
1157     }
1158 
1159     @Test
1160     public void testInvalidInvalidAnonymousClass() throws Exception {
1161         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1162 
1163         checkConfig.addAttribute("arrayInitIndent", "4");
1164         checkConfig.addAttribute("basicOffset", "4");
1165         checkConfig.addAttribute("braceAdjustment", "0");
1166         checkConfig.addAttribute("caseIndent", "4");
1167         checkConfig.addAttribute("forceStrictCondition", "false");
1168         checkConfig.addAttribute("lineWrappingIndentation", "4");
1169         checkConfig.addAttribute("tabWidth", "4");
1170         checkConfig.addAttribute("throwsIndent", "4");
1171         final String fileName = getPath("InputIndentationInvalidAnonymousClassIndent.java");
1172         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1173         verifyWarns(checkConfig, fileName, expected);
1174     }
1175 
1176     @Test
1177     public void testInvalidForWithChecker()
1178             throws Exception {
1179         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1180 
1181         checkConfig.addAttribute("arrayInitIndent", "4");
1182         checkConfig.addAttribute("basicOffset", "4");
1183         checkConfig.addAttribute("braceAdjustment", "0");
1184         checkConfig.addAttribute("caseIndent", "4");
1185         checkConfig.addAttribute("forceStrictCondition", "false");
1186         checkConfig.addAttribute("lineWrappingIndentation", "4");
1187         checkConfig.addAttribute("tabWidth", "4");
1188         checkConfig.addAttribute("throwsIndent", "4");
1189         final String fileName = getPath("InputIndentationInvalidForIndent.java");
1190         final String[] expected = {
1191             "26: " + getCheckMessage(MSG_ERROR, "for", 6, 8),
1192             "27: " + getCheckMessage(MSG_ERROR, "for rcurly", 10, 8),
1193             "29: " + getCheckMessage(MSG_ERROR, "for", 9, 8),
1194             "30: " + getCheckMessage(MSG_ERROR, "for lcurly", 6, 8),
1195             "31: " + getCheckMessage(MSG_ERROR, "for rcurly", 6, 8),
1196             "35: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
1197 
1198             "36: " + getCheckMessage(MSG_ERROR, "for rcurly", 10, 8),
1199             "39: " + getCheckMessage(MSG_ERROR, "for lcurly", 10, 8),
1200             "40: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
1201             "48: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
1202             "54: " + getCheckMessage(MSG_ERROR, "for", 7, 8),
1203 
1204             "55: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
1205             "64: " + getCheckMessage(MSG_CHILD_ERROR, "for", 7, 12),
1206 
1207             "69: " + getCheckMessage(MSG_ERROR, "for", 6, 8),
1208             "70: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
1209             "71: " + getCheckMessage(MSG_CHILD_ERROR, "for", 14, 16),
1210             "72: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
1211             "81: " + getCheckMessage(MSG_ERROR, "for rparen", 12, 8),
1212             "86: " + getCheckMessage(MSG_ERROR, "method def modifier", 2, 4),
1213             "87: " + getCheckMessage(MSG_ERROR, "for", 4, 8),
1214             "88: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 12),
1215             "89: " + getCheckMessage(MSG_CHILD_ERROR, "for", 6, 12),
1216             "90: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 16),
1217             "92: " + getCheckMessage(MSG_ERROR, "for", 0, 8),
1218             "93: " + getCheckMessage(MSG_ERROR, "for lparen", 0, 8),
1219             "94: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
1220             "95: " + getCheckMessage(MSG_ERROR, ";", 0, 4),
1221             "96: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
1222             "97: " + getCheckMessage(MSG_ERROR, ";", 0, 4),
1223             "98: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
1224         };
1225         verifyWarns(checkConfig, fileName, expected);
1226     }
1227 
1228     @Test
1229     public void testValidForWithChecker()
1230             throws Exception {
1231         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1232 
1233         checkConfig.addAttribute("arrayInitIndent", "4");
1234         checkConfig.addAttribute("basicOffset", "4");
1235         checkConfig.addAttribute("braceAdjustment", "0");
1236         checkConfig.addAttribute("caseIndent", "4");
1237         checkConfig.addAttribute("forceStrictCondition", "false");
1238         checkConfig.addAttribute("lineWrappingIndentation", "4");
1239         checkConfig.addAttribute("tabWidth", "4");
1240         checkConfig.addAttribute("throwsIndent", "4");
1241         final String fileName = getPath("InputIndentationValidForIndent.java");
1242         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1243         verifyWarns(checkConfig, fileName, expected);
1244     }
1245 
1246     @Test
1247     public void testValidDoWhileWithChecker()
1248             throws Exception {
1249         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1250 
1251         checkConfig.addAttribute("arrayInitIndent", "4");
1252         checkConfig.addAttribute("basicOffset", "4");
1253         checkConfig.addAttribute("braceAdjustment", "0");
1254         checkConfig.addAttribute("caseIndent", "4");
1255         checkConfig.addAttribute("forceStrictCondition", "false");
1256         checkConfig.addAttribute("lineWrappingIndentation", "4");
1257         checkConfig.addAttribute("tabWidth", "4");
1258         checkConfig.addAttribute("throwsIndent", "4");
1259         final String fileName = getPath("InputIndentationValidDoWhileIndent.java");
1260         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1261         verifyWarns(checkConfig, fileName, expected);
1262     }
1263 
1264     @Test
1265     public void testInvalidDoWhileWithChecker()
1266             throws Exception {
1267         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1268 
1269         checkConfig.addAttribute("arrayInitIndent", "4");
1270         checkConfig.addAttribute("basicOffset", "4");
1271         checkConfig.addAttribute("braceAdjustment", "0");
1272         checkConfig.addAttribute("caseIndent", "4");
1273         checkConfig.addAttribute("forceStrictCondition", "false");
1274         checkConfig.addAttribute("lineWrappingIndentation", "4");
1275         checkConfig.addAttribute("tabWidth", "4");
1276         checkConfig.addAttribute("throwsIndent", "4");
1277         final String fileName = getPath("InputIndentationInvalidDoWhileIndent.java");
1278         final String[] expected = {
1279             "7: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
1280             "8: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
1281             "9: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
1282             "10: " + getCheckMessage(MSG_ERROR, "do..while rcurly", 0, 8),
1283             "11: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
1284             "12: " + getCheckMessage(MSG_ERROR, "do..while while", 0, 8),
1285             "13: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
1286             "14: " + getCheckMessage(MSG_ERROR, "do..while lcurly", 0, 8),
1287             "15: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
1288             "16: " + getCheckMessage(MSG_ERROR, "do..while while", 0, 8),
1289             "17: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
1290             "18: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
1291             "19: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
1292             "20: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
1293             "21: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
1294             "22: " + getCheckMessage(MSG_CHILD_ERROR, "do..while", 0, 8),
1295             "23: " + getCheckMessage(MSG_ERROR, "do..while rparen", 0, 8),
1296         };
1297         verifyWarns(checkConfig, fileName, expected);
1298     }
1299 
1300     @Test
1301     public void testValidBlockWithChecker()
1302             throws Exception {
1303         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1304 
1305         checkConfig.addAttribute("arrayInitIndent", "4");
1306         checkConfig.addAttribute("basicOffset", "4");
1307         checkConfig.addAttribute("braceAdjustment", "0");
1308         checkConfig.addAttribute("caseIndent", "4");
1309         checkConfig.addAttribute("forceStrictCondition", "false");
1310         checkConfig.addAttribute("lineWrappingIndentation", "4");
1311         checkConfig.addAttribute("tabWidth", "4");
1312         checkConfig.addAttribute("throwsIndent", "4");
1313         final String fileName = getPath("InputIndentationValidBlockIndent.java");
1314         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1315         verifyWarns(checkConfig, fileName, expected);
1316     }
1317 
1318     @Test
1319     public void testValidWhileWithChecker()
1320             throws Exception {
1321         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1322 
1323         checkConfig.addAttribute("arrayInitIndent", "4");
1324         checkConfig.addAttribute("basicOffset", "4");
1325         checkConfig.addAttribute("braceAdjustment", "0");
1326         checkConfig.addAttribute("caseIndent", "4");
1327         checkConfig.addAttribute("forceStrictCondition", "false");
1328         checkConfig.addAttribute("lineWrappingIndentation", "4");
1329         checkConfig.addAttribute("tabWidth", "4");
1330         checkConfig.addAttribute("throwsIndent", "4");
1331         final String fileName = getPath("InputIndentationValidWhileIndent.java");
1332         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1333         verifyWarns(checkConfig, fileName, expected);
1334     }
1335 
1336     @Test
1337     public void testValidClassDefWithChecker()
1338             throws Exception {
1339         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1340 
1341         checkConfig.addAttribute("arrayInitIndent", "4");
1342         checkConfig.addAttribute("basicOffset", "4");
1343         checkConfig.addAttribute("braceAdjustment", "0");
1344         checkConfig.addAttribute("caseIndent", "4");
1345         checkConfig.addAttribute("forceStrictCondition", "false");
1346         checkConfig.addAttribute("lineWrappingIndentation", "4");
1347         checkConfig.addAttribute("tabWidth", "4");
1348         checkConfig.addAttribute("throwsIndent", "4");
1349         final String fileName = getPath("InputIndentationValidClassDefIndent.java");
1350         final String[] expected = {
1351             "49: " + getCheckMessage(MSG_ERROR, "class", 0, 4),
1352             "71: " + getCheckMessage(MSG_ERROR, "int", 8, 12),
1353         };
1354         verifyWarns(checkConfig, fileName, expected);
1355     }
1356 
1357     @Test
1358     public void testValidInterfaceDefWithChecker()
1359             throws Exception {
1360         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1361 
1362         checkConfig.addAttribute("arrayInitIndent", "4");
1363         checkConfig.addAttribute("basicOffset", "4");
1364         checkConfig.addAttribute("braceAdjustment", "0");
1365         checkConfig.addAttribute("caseIndent", "4");
1366         checkConfig.addAttribute("forceStrictCondition", "false");
1367         checkConfig.addAttribute("lineWrappingIndentation", "4");
1368         checkConfig.addAttribute("tabWidth", "4");
1369         checkConfig.addAttribute("throwsIndent", "4");
1370         final String fileName = getPath("InputIndentationValidInterfaceDefIndent.java");
1371         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1372         verifyWarns(checkConfig, fileName, expected);
1373     }
1374 
1375     @Test
1376     public void testValidCommaWithChecker()
1377             throws Exception {
1378         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1379 
1380         checkConfig.addAttribute("arrayInitIndent", "4");
1381         checkConfig.addAttribute("basicOffset", "4");
1382         checkConfig.addAttribute("braceAdjustment", "0");
1383         checkConfig.addAttribute("caseIndent", "4");
1384         checkConfig.addAttribute("forceStrictCondition", "false");
1385         checkConfig.addAttribute("lineWrappingIndentation", "4");
1386         checkConfig.addAttribute("tabWidth", "4");
1387         checkConfig.addAttribute("throwsIndent", "4");
1388         final String fileName = getPath("InputIndentationValidCommaIndent.java");
1389         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1390         verifyWarns(checkConfig, fileName, expected);
1391     }
1392 
1393     @Test
1394     public void testTabs() throws Exception {
1395         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1396 
1397         checkConfig.addAttribute("arrayInitIndent", "4");
1398         checkConfig.addAttribute("basicOffset", "4");
1399         checkConfig.addAttribute("braceAdjustment", "0");
1400         checkConfig.addAttribute("caseIndent", "4");
1401         checkConfig.addAttribute("forceStrictCondition", "false");
1402         checkConfig.addAttribute("lineWrappingIndentation", "4");
1403         checkConfig.addAttribute("tabWidth", "4");
1404         checkConfig.addAttribute("throwsIndent", "4");
1405         final String[] expected = {
1406             "29: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 9, 8),
1407         };
1408         verifyWarns(checkConfig, getPath("InputIndentationUseTabs.java"), expected);
1409     }
1410 
1411     @Test
1412     public void testIndentationLevel() throws Exception {
1413         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1414 
1415         checkConfig.addAttribute("arrayInitIndent", "4");
1416         checkConfig.addAttribute("basicOffset", "2");
1417         checkConfig.addAttribute("braceAdjustment", "0");
1418         checkConfig.addAttribute("caseIndent", "4");
1419         checkConfig.addAttribute("forceStrictCondition", "false");
1420         checkConfig.addAttribute("lineWrappingIndentation", "2");
1421         checkConfig.addAttribute("tabWidth", "4");
1422         checkConfig.addAttribute("throwsIndent", "4");
1423         final String[] expected = {
1424             "29: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 5, 4),
1425         };
1426         verifyWarns(checkConfig, getPath("InputIndentationUseTwoSpaces.java"), expected);
1427     }
1428 
1429     @Test
1430     public void testThrowsIndentationLevel() throws Exception {
1431         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1432 
1433         checkConfig.addAttribute("arrayInitIndent", "4");
1434         checkConfig.addAttribute("basicOffset", "4");
1435         checkConfig.addAttribute("braceAdjustment", "0");
1436         checkConfig.addAttribute("caseIndent", "4");
1437         checkConfig.addAttribute("forceStrictCondition", "false");
1438         checkConfig.addAttribute("lineWrappingIndentation", "4");
1439         checkConfig.addAttribute("tabWidth", "4");
1440         checkConfig.addAttribute("throwsIndent", "8");
1441         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1442         verifyWarns(checkConfig, getPath("InputIndentationInvalidThrowsIndent.java"), expected);
1443     }
1444 
1445     @Test
1446     public void testThrowsIndentationLevel2() throws Exception {
1447         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1448 
1449         checkConfig.addAttribute("basicOffset", "1");
1450         checkConfig.addAttribute("forceStrictCondition", "true");
1451         checkConfig.addAttribute("lineWrappingIndentation", "3");
1452         checkConfig.addAttribute("tabWidth", "4");
1453         checkConfig.addAttribute("throwsIndent", "5");
1454         final String[] expected = {
1455             "7: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
1456             "10: " + getCheckMessage(MSG_ERROR, "NullPointerException", 0, 6),
1457             "13: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
1458             "16: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
1459             "18: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
1460             "19: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
1461             "22: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
1462             "23: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
1463             "24: " + getCheckMessage(MSG_ERROR, "NullPointerException", 0, 6),
1464             "27: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
1465             "28: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
1466             "31: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
1467             "37: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
1468         };
1469         verifyWarns(checkConfig, getPath("InputIndentationInvalidThrowsIndent2.java"), expected);
1470     }
1471 
1472     @Test
1473     public void testCaseLevel() throws Exception {
1474         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1475 
1476         checkConfig.addAttribute("arrayInitIndent", "4");
1477         checkConfig.addAttribute("basicOffset", "4");
1478         checkConfig.addAttribute("braceAdjustment", "0");
1479         checkConfig.addAttribute("caseIndent", "0");
1480         checkConfig.addAttribute("forceStrictCondition", "false");
1481         checkConfig.addAttribute("lineWrappingIndentation", "4");
1482         checkConfig.addAttribute("tabWidth", "4");
1483         checkConfig.addAttribute("throwsIndent", "4");
1484         final String[] expected = {
1485             "27: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 8),
1486         };
1487         verifyWarns(checkConfig, getPath("InputIndentationCaseLevel.java"), expected);
1488     }
1489 
1490     @Test
1491     public void testBraceAdjustment() throws Exception {
1492         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1493 
1494         checkConfig.addAttribute("arrayInitIndent", "4");
1495         checkConfig.addAttribute("basicOffset", "4");
1496         checkConfig.addAttribute("braceAdjustment", "2");
1497         checkConfig.addAttribute("caseIndent", "4");
1498         checkConfig.addAttribute("forceStrictCondition", "false");
1499         checkConfig.addAttribute("lineWrappingIndentation", "4");
1500         checkConfig.addAttribute("tabWidth", "4");
1501         checkConfig.addAttribute("throwsIndent", "4");
1502         final String[] expected = {
1503             "28: " + getCheckMessage(MSG_ERROR, "if rcurly", 8, 10),
1504         };
1505         verifyWarns(checkConfig, getPath("InputIndentationBraceAdjustment.java"), expected);
1506     }
1507 
1508     @Test
1509     public void testInvalidAssignWithChecker() throws Exception {
1510         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1511 
1512         checkConfig.addAttribute("arrayInitIndent", "4");
1513         checkConfig.addAttribute("basicOffset", "4");
1514         checkConfig.addAttribute("braceAdjustment", "0");
1515         checkConfig.addAttribute("caseIndent", "4");
1516         checkConfig.addAttribute("forceStrictCondition", "false");
1517         checkConfig.addAttribute("lineWrappingIndentation", "4");
1518         checkConfig.addAttribute("tabWidth", "4");
1519         checkConfig.addAttribute("throwsIndent", "4");
1520         final String[] expected = {
1521             "22: " + getCheckMessage(MSG_ERROR, "getLineNo", 10, 12),
1522             "24: " + getCheckMessage(MSG_ERROR, "getLine", 10, 12),
1523             "28: " + getCheckMessage(MSG_ERROR, "=", 9, 12),
1524             "29: " + getCheckMessage(MSG_ERROR, "1", 10, 12),
1525         };
1526         verifyWarns(checkConfig, getPath("InputIndentationInvalidAssignIndent.java"), expected);
1527     }
1528 
1529     @Test
1530     public void testInvalidImportIndent() throws Exception {
1531         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1532         checkConfig.addAttribute("basicOffset", "8");
1533         checkConfig.addAttribute("tabWidth", "4");
1534         final String[] expected = {
1535             "4: " + getCheckMessage(MSG_ERROR, ".", 2, 4),
1536             "5: " + getCheckMessage(MSG_ERROR, "import", 1, 0),
1537         };
1538         verifyWarns(checkConfig, getPath("InputIndentationInvalidImportIndent.java"), expected);
1539     }
1540 
1541     @Test
1542     public void testValidAssignWithChecker() throws Exception {
1543         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1544 
1545         checkConfig.addAttribute("arrayInitIndent", "4");
1546         checkConfig.addAttribute("basicOffset", "4");
1547         checkConfig.addAttribute("braceAdjustment", "0");
1548         checkConfig.addAttribute("caseIndent", "4");
1549         checkConfig.addAttribute("forceStrictCondition", "false");
1550         checkConfig.addAttribute("lineWrappingIndentation", "4");
1551         checkConfig.addAttribute("tabWidth", "4");
1552         checkConfig.addAttribute("throwsIndent", "4");
1553         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1554         verifyWarns(checkConfig, getPath("InputIndentationValidAssignIndent.java"), expected);
1555     }
1556 
1557     @Test
1558     public void test15Extensions() throws Exception {
1559         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1560 
1561         checkConfig.addAttribute("arrayInitIndent", "4");
1562         checkConfig.addAttribute("basicOffset", "4");
1563         checkConfig.addAttribute("braceAdjustment", "0");
1564         checkConfig.addAttribute("caseIndent", "4");
1565         checkConfig.addAttribute("forceStrictCondition", "false");
1566         checkConfig.addAttribute("lineWrappingIndentation", "4");
1567         checkConfig.addAttribute("tabWidth", "4");
1568         checkConfig.addAttribute("throwsIndent", "4");
1569         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1570         verifyWarns(checkConfig, getPath("InputIndentation15Extensions.java"), expected);
1571     }
1572 
1573     @Test
1574     public void testTryResources() throws Exception {
1575         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1576 
1577         checkConfig.addAttribute("arrayInitIndent", "4");
1578         checkConfig.addAttribute("basicOffset", "4");
1579         checkConfig.addAttribute("braceAdjustment", "0");
1580         checkConfig.addAttribute("caseIndent", "4");
1581         checkConfig.addAttribute("forceStrictCondition", "false");
1582         checkConfig.addAttribute("lineWrappingIndentation", "4");
1583         checkConfig.addAttribute("tabWidth", "4");
1584         checkConfig.addAttribute("throwsIndent", "4");
1585         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1586         verifyWarns(checkConfig, getPath("InputIndentationValidTryResourcesIndent.java"),
1587                expected);
1588     }
1589 
1590     @Test
1591     public void testSwitchCustom() throws Exception {
1592         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1593 
1594         checkConfig.addAttribute("arrayInitIndent", "4");
1595         checkConfig.addAttribute("basicOffset", "4");
1596         checkConfig.addAttribute("braceAdjustment", "0");
1597         checkConfig.addAttribute("caseIndent", "4");
1598         checkConfig.addAttribute("forceStrictCondition", "false");
1599         checkConfig.addAttribute("lineWrappingIndentation", "8");
1600         checkConfig.addAttribute("tabWidth", "4");
1601         checkConfig.addAttribute("throwsIndent", "8");
1602         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1603         verifyWarns(checkConfig, getPath("InputIndentationSwitchCustom.java"),
1604                expected);
1605     }
1606 
1607     @Test
1608     public void testSynchronizedStatement() throws Exception {
1609         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1610         checkConfig.addAttribute("arrayInitIndent", "4");
1611         checkConfig.addAttribute("basicOffset", "4");
1612         checkConfig.addAttribute("braceAdjustment", "0");
1613         checkConfig.addAttribute("caseIndent", "4");
1614         checkConfig.addAttribute("forceStrictCondition", "false");
1615         checkConfig.addAttribute("lineWrappingIndentation", "8");
1616         checkConfig.addAttribute("tabWidth", "4");
1617         checkConfig.addAttribute("throwsIndent", "8");
1618         final String[] expected = {
1619             "27: " + getCheckMessage(MSG_CHILD_ERROR, "synchronized", 0, 12),
1620             "30: " + getCheckMessage(MSG_ERROR, "synchronized lparen", 12, 8),
1621         };
1622         verifyWarns(checkConfig, getPath("InputIndentationSynchronizedStatement.java"), expected);
1623     }
1624 
1625     @Test
1626     public void testSynchronizedMethod() throws Exception {
1627         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1628         checkConfig.addAttribute("arrayInitIndent", "4");
1629         checkConfig.addAttribute("basicOffset", "4");
1630         checkConfig.addAttribute("braceAdjustment", "0");
1631         checkConfig.addAttribute("caseIndent", "4");
1632         checkConfig.addAttribute("forceStrictCondition", "false");
1633         checkConfig.addAttribute("lineWrappingIndentation", "8");
1634         checkConfig.addAttribute("tabWidth", "4");
1635         checkConfig.addAttribute("throwsIndent", "8");
1636         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1637         verifyWarns(checkConfig, getPath("InputIndentationSynchronizedMethod.java"), expected);
1638     }
1639 
1640     @Test
1641     public void testAnonymousClassInMethod() throws Exception {
1642         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1643         checkConfig.addAttribute("tabWidth", "8");
1644         checkConfig.addAttribute("basicOffset", "2");
1645         checkConfig.addAttribute("braceAdjustment", "0");
1646         checkConfig.addAttribute("caseIndent", "2");
1647         checkConfig.addAttribute("lineWrappingIndentation", "4");
1648         checkConfig.addAttribute("throwsIndent", "4");
1649         checkConfig.addAttribute("arrayInitIndent", "2");
1650         final String[] expected = {
1651             "19: " + getCheckMessage(MSG_ERROR, "method def modifier", 8, 2),
1652             "20: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 16, 4),
1653             "21: " + getCheckMessage(MSG_ERROR_MULTI, "method def modifier", 24, "18, 20, 22"),
1654             "23: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "method def", 32, "20, 22, 24"),
1655             "24: " + getCheckMessage(MSG_ERROR_MULTI, "method def rcurly", 24, "18, 20, 22"),
1656             "26: " + getCheckMessage(MSG_ERROR, "method def rcurly", 8, 2),
1657         };
1658         verifyWarns(checkConfig, getPath("InputIndentationAnonymousClassInMethod.java"), expected);
1659     }
1660 
1661     @Test
1662     public void testAnonymousClassInMethodWithCurlyOnNewLine() throws Exception {
1663         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1664         checkConfig.addAttribute("tabWidth", "4");
1665         checkConfig.addAttribute("basicOffset", "4");
1666         checkConfig.addAttribute("braceAdjustment", "0");
1667         checkConfig.addAttribute("caseIndent", "4");
1668         checkConfig.addAttribute("lineWrappingIndentation", "8");
1669         checkConfig.addAttribute("throwsIndent", "4");
1670         checkConfig.addAttribute("arrayInitIndent", "4");
1671         final String[] expected = {
1672             "40: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 18, "8, 12, 16"),
1673             "42: " + getCheckMessage(MSG_ERROR, "new", 14, 16),
1674             "48: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 14, "8, 12, 16"),
1675             "60: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 18, "8, 12, 16"),
1676             "66: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 18, "8, 12, 16"),
1677             "69: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 14, "8, 12, 16"),
1678             "75: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 14, "8, 12, 16"),
1679         };
1680         verifyWarns(checkConfig,
1681             getPath("InputIndentationAnonymousClassInMethodCurlyOnNewLine.java"), expected);
1682     }
1683 
1684     @Test
1685     public void testAnnotationDefinition() throws Exception {
1686         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1687         checkConfig.addAttribute("tabWidth", "4");
1688         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1689         verifyWarns(checkConfig, getPath("InputIndentationAnnotationDefinition.java"), expected);
1690     }
1691 
1692     @Test
1693     public void testPackageDeclaration() throws Exception {
1694         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1695         checkConfig.addAttribute("tabWidth", "4");
1696         final String[] expected = {
1697             "1: " + getCheckMessage(MSG_ERROR, "package def", 1, 0),
1698         };
1699         verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration.java"), expected);
1700     }
1701 
1702     @Test
1703     public void testPackageDeclaration2() throws Exception {
1704         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1705         checkConfig.addAttribute("tabWidth", "4");
1706         final String[] expected = {
1707             "2: " + getCheckMessage(MSG_ERROR, "package def", 1, 0),
1708         };
1709         verifyWarns(checkConfig,
1710             getPath("package-info.java"), expected);
1711     }
1712 
1713     @Test
1714     public void testPackageDeclaration3() throws Exception {
1715         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1716         checkConfig.addAttribute("tabWidth", "4");
1717         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1718         verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration3.java"), expected);
1719     }
1720 
1721     @Test
1722     public void testPackageDeclaration4() throws Exception {
1723         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1724         checkConfig.addAttribute("tabWidth", "4");
1725         final String[] expected = {
1726             "2: " + getCheckMessage(MSG_ERROR, "com", 0, 4),
1727             "3: " + getCheckMessage(MSG_ERROR, "checks", 0, 4),
1728         };
1729         verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration4.java"), expected);
1730     }
1731 
1732     @Test
1733     public void testLambda1() throws Exception {
1734         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1735         checkConfig.addAttribute("tabWidth", "2");
1736         checkConfig.addAttribute("basicOffset", "2");
1737         checkConfig.addAttribute("lineWrappingIndentation", "4");
1738         final String[] expected = {
1739             "46: " + getCheckMessage(MSG_ERROR, "block lcurly", 5, 4),
1740             "47: " + getCheckMessage(MSG_ERROR, "block rcurly", 5, 4),
1741             "50: " + getCheckMessage(MSG_ERROR, "lambda arguments", 9, 8),
1742             "51: " + getCheckMessage(MSG_ERROR, "lambda", 11, 12),
1743             "52: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
1744             "64: " + getCheckMessage(MSG_CHILD_ERROR, "block", 7, 6),
1745             "65: " + getCheckMessage(MSG_ERROR, "block rcurly", 5, 4),
1746             "179: " + getCheckMessage(MSG_CHILD_ERROR, "block", 9, 10),
1747             "180: " + getCheckMessage(MSG_CHILD_ERROR, "block", 11, 10),
1748             "185: " + getCheckMessage(MSG_ERROR, "block rcurly", 7, 8),
1749         };
1750         verifyWarns(checkConfig, getPath("InputIndentationLambda1.java"), expected);
1751     }
1752 
1753     @Test
1754     public void testLambda2() throws Exception {
1755         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1756         checkConfig.addAttribute("tabWidth", "4");
1757         checkConfig.addAttribute("basicOffset", "4");
1758         checkConfig.addAttribute("lineWrappingIndentation", "8");
1759         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1760         verifyWarns(checkConfig, getPath("InputIndentationLambda2.java"), expected);
1761     }
1762 
1763     @Test
1764     public void testSeparatedStatements() throws Exception {
1765         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1766         checkConfig.addAttribute("tabWidth", "4");
1767         final String fileName = getPath("InputIndentationSeparatedStatements.java");
1768         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1769         verifyWarns(checkConfig, fileName, expected);
1770     }
1771 
1772     @Test
1773     public void testSeparatedLineWithJustSpaces() throws Exception {
1774         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1775         checkConfig.addAttribute("tabWidth", "4");
1776         final String fileName = getPath("InputIndentationSeparatedStatementWithSpaces.java");
1777         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1778         verify(checkConfig, fileName, expected);
1779     }
1780 
1781     @Test
1782     public void testTwoStatementsPerLine() throws Exception {
1783         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1784         checkConfig.addAttribute("tabWidth", "4");
1785         checkConfig.addAttribute("basicOffset", "4");
1786         final String fileName = getPath("InputIndentationTwoStatementsPerLine.java");
1787         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1788         verifyWarns(checkConfig, fileName, expected);
1789     }
1790 
1791     @Test
1792     public void testMethodChaining() throws Exception {
1793         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1794         checkConfig.addAttribute("tabWidth", "4");
1795         checkConfig.addAttribute("basicOffset", "4");
1796         final String fileName = getPath("InputIndentationChainedMethods.java");
1797         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1798         verifyWarns(checkConfig, fileName, expected);
1799     }
1800 
1801     @Test
1802     public void testMultipleAnnotationsWithWrappedLines() throws Exception {
1803         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1804         checkConfig.addAttribute("tabWidth", "4");
1805         checkConfig.addAttribute("basicOffset", "4");
1806         checkConfig.addAttribute("forceStrictCondition", "true");
1807         final String fileName =
1808             getPath("InputIndentationCorrectMultipleAnnotationsWithWrappedLines.java");
1809         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1810         verifyWarns(checkConfig, fileName, expected);
1811     }
1812 
1813     @Test
1814     public void testMethodPrecedeByAnnotationsWithParameterOnSeparateLine() throws Exception {
1815         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1816         checkConfig.addAttribute("tabWidth", "4");
1817         checkConfig.addAttribute("basicOffset", "2");
1818         checkConfig.addAttribute("braceAdjustment", "0");
1819         checkConfig.addAttribute("caseIndent", "2");
1820         checkConfig.addAttribute("throwsIndent", "4");
1821         checkConfig.addAttribute("lineWrappingIndentation", "4");
1822         checkConfig.addAttribute("arrayInitIndent", "2");
1823         final String fileName =
1824             getPath("InputIndentationMethodPrecededByAnnotationWithParameterOnSeparateLine.java");
1825         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1826         verify(checkConfig, fileName, expected);
1827     }
1828 
1829     @Test
1830     public void testAnnotationIncorrect() throws Exception {
1831         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1832         checkConfig.addAttribute("tabWidth", "4");
1833         checkConfig.addAttribute("basicOffset", "4");
1834         checkConfig.addAttribute("braceAdjustment", "0");
1835         checkConfig.addAttribute("lineWrappingIndentation", "4");
1836         final String fileName =
1837             getPath("InputIndentationAnnotationIncorrect.java");
1838         final String[] expected = {
1839             "11: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
1840             "14: " + getCheckMessage(MSG_ERROR, "(", 8, 12),
1841             "19: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
1842         };
1843         verify(checkConfig, fileName, expected);
1844     }
1845 
1846     @Test
1847     public void testInputAnnotationScopeIndentationCheck() throws Exception {
1848         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1849         checkConfig.addAttribute("tabWidth", "4");
1850         checkConfig.addAttribute("basicOffset", "4");
1851         checkConfig.addAttribute("forceStrictCondition", "true");
1852         final String fileName = getPath("InputIndentationAnnotationScopeIndentationCheck.java");
1853         final String[] expected = {
1854             "9: " + getCheckMessage(MSG_ERROR, "}", 8, 0),
1855         };
1856         verifyWarns(checkConfig, fileName, expected);
1857     }
1858 
1859     @Test
1860     public void testInputAnnotationDefIndentationCheck() throws Exception {
1861         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1862         checkConfig.addAttribute("tabWidth", "4");
1863         checkConfig.addAttribute("arrayInitIndent", "4");
1864         checkConfig.addAttribute("basicOffset", "4");
1865         checkConfig.addAttribute("braceAdjustment", "0");
1866         checkConfig.addAttribute("lineWrappingIndentation", "4");
1867         checkConfig.addAttribute("forceStrictCondition", "true");
1868         final String fileName = getPath("InputIndentationCustomAnnotation.java");
1869         final String[] expected = {
1870             "14: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 0),
1871             "15: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
1872             "16: " + getCheckMessage(MSG_ERROR, "@", 5, 0),
1873             "17: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 0, 4),
1874             "18: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
1875             "20: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 0),
1876             "22: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 0, 4),
1877             "23: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
1878             "25: " + getCheckMessage(MSG_ERROR, "@", 5, 0),
1879             "26: " + getCheckMessage(MSG_ERROR, "AnnotationWithLineWrap", 5, 0),
1880             "30: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 0),
1881             "31: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 0),
1882             "34: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 5, 4),
1883             "35: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 4),
1884             "36: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 0, 4),
1885             "37: " + getCheckMessage(MSG_ERROR, "@", 0, 4),
1886             "38: " + getCheckMessage(MSG_ERROR, "AnnotationInnerLineWrap", 8, 4),
1887             "41: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 7, 8),
1888             "58: " + getCheckMessage(MSG_ERROR, "AnnotationInnerLineWrap2", 4, 0),
1889             "59: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 3, 4),
1890             "60: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 7, 4),
1891             "61: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 4, 0),
1892             "72: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 4),
1893             "117: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 4),
1894             "128: " + getCheckMessage(MSG_ERROR, "interface", 1, 0),
1895             "134: " + getCheckMessage(MSG_ERROR, "@", 11, 0),
1896             "137: " + getCheckMessage(MSG_ERROR, "@", 16, 0),
1897             "144: " + getCheckMessage(MSG_ERROR, "@", 12, 4),
1898             "148: " + getCheckMessage(MSG_ERROR, "class def ident", 16, 0),
1899         };
1900         verifyWarns(checkConfig, fileName, expected);
1901     }
1902 
1903     @Test
1904     public void testTryResourcesStrict() throws Exception {
1905         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1906         checkConfig.addAttribute("tabWidth", "4");
1907         checkConfig.addAttribute("forceStrictCondition", "true");
1908         checkConfig.addAttribute("braceAdjustment", "0");
1909         checkConfig.addAttribute("lineWrappingIndentation", "4");
1910         final String fileName = getPath("InputIndentationTryWithResourcesStrict.java");
1911         final String[] expected = {
1912             "26: " + getCheckMessage(MSG_ERROR, "try resource", 0, 12),
1913             "28: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 13, "8, 12"),
1914             "33: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 16),
1915             "39: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 12),
1916             "59: " + getCheckMessage(MSG_ERROR, "try resource", 20, 16),
1917             "84: " + getCheckMessage(MSG_ERROR, "writ", 19, 12),
1918             "91: " + getCheckMessage(MSG_ERROR, "writ", 19, 16),
1919             "98: " + getCheckMessage(MSG_ERROR, "writ", 21, 16),
1920             "113: " + getCheckMessage(MSG_ERROR, "zipFileName", 17, 16),
1921             "120: " + getCheckMessage(MSG_ERROR, "zipFileName", 15, 16),
1922             "130: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
1923             "135: " + getCheckMessage(MSG_CHILD_ERROR, "try", 15, 12),
1924             "141: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
1925             "142: " + getCheckMessage(MSG_CHILD_ERROR, "try", 9, 12),
1926             "146: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
1927             "147: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 11, 16),
1928             "148: " + getCheckMessage(MSG_CHILD_ERROR, "try", 13, 12),
1929             "150: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
1930             "151: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 7, "8, 12"),
1931             "155: " + getCheckMessage(MSG_ERROR, "try", 9, 8),
1932             "161: " + getCheckMessage(MSG_ERROR, ".", 13, 12),
1933             "167: " + getCheckMessage(MSG_ERROR, ".", 11, 12),
1934         };
1935         verifyWarns(checkConfig, fileName, expected);
1936     }
1937 
1938     @Test
1939     public void testTryResourcesNotStrict() throws Exception {
1940         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1941         checkConfig.addAttribute("tabWidth", "4");
1942         checkConfig.addAttribute("braceAdjustment", "0");
1943         checkConfig.addAttribute("lineWrappingIndentation", "4");
1944         final String fileName = getPath("InputIndentationTryResourcesNotStrict.java");
1945         final String[] expected = {
1946             "27: " + getCheckMessage(MSG_ERROR, "try resource", 0, 12),
1947             "33: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 16),
1948             "39: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 12),
1949             "120: " + getCheckMessage(MSG_ERROR, "zipFileName", 15, 16),
1950             "130: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
1951             "135: " + getCheckMessage(MSG_CHILD_ERROR, "try", 15, 12),
1952             "141: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
1953             "142: " + getCheckMessage(MSG_CHILD_ERROR, "try", 9, 12),
1954             "146: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
1955             "147: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 11, 16),
1956             "148: " + getCheckMessage(MSG_CHILD_ERROR, "try", 13, 12),
1957             "150: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
1958             "151: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 7, "8, 12"),
1959             "164: " + getCheckMessage(MSG_ERROR, ".", 8, 12),
1960             "172: " + getCheckMessage(MSG_ERROR, "new", 11, 12),
1961         };
1962         verifyWarns(checkConfig, fileName, expected);
1963     }
1964 
1965     /**
1966      * Verifies that the arguments of {@link IndentationCheck#MSG_ERROR},
1967      * {@link IndentationCheck#MSG_CHILD_ERROR}, {@link IndentationCheck#MSG_CHILD_ERROR_MULTI},
1968      * {@link IndentationCheck#MSG_CHILD_ERROR_MULTI} are in appropriate order.
1969      *
1970      * <p>In other tests, the argument 0 and text before it are chopped off and only the rest of
1971      * messages are verified. Therefore, the argument 0 is required to be the first argument in
1972      * the messages above. If we update the messages in the future, it is required to keep the
1973      * arguments in appropriate order to ensure other tests will work.</p>
1974      *
1975      * @see IndentComment#getExpectedMessagePostfix(String)
1976      */
1977     @Test
1978     public void testArgumentOrderOfErrorMessages() {
1979         final String[] arguments = {"##0##", "##1##", "##2##"};
1980         final String[] messages = {
1981             getCheckMessage(MSG_ERROR, (Object[]) arguments),
1982             getCheckMessage(MSG_CHILD_ERROR, (Object[]) arguments),
1983             getCheckMessage(MSG_ERROR_MULTI, (Object[]) arguments),
1984             getCheckMessage(MSG_CHILD_ERROR_MULTI, (Object[]) arguments),
1985         };
1986         final boolean isInOrder = Arrays.stream(messages).allMatch(msg -> {
1987             final int indexOfArgumentZero = msg.indexOf(arguments[0]);
1988             return Arrays.stream(arguments).mapToInt(msg::indexOf)
1989                     .allMatch(index -> index >= indexOfArgumentZero);
1990         });
1991         assertTrue(
1992                 "the argument 0 of error messages (indentation.error, indentation.child.error,"
1993                         + " indentation.error.multi, indentation.child.error.multi)"
1994                         + " is required to be the first argument of them",
1995                 isInOrder);
1996     }
1997 
1998     @Test
1999     public void testEmptyArray() throws Exception {
2000         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2001         checkConfig.addAttribute("tabWidth", "4");
2002         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2003         verifyWarns(checkConfig, getPath("InputIndentationEmptyArray.java"), expected);
2004     }
2005 
2006     @Test
2007     public void testNewHandler() throws Exception {
2008         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2009         checkConfig.addAttribute("tabWidth", "4");
2010         final String[] expected = {
2011             "8: " + getCheckMessage(MSG_ERROR, "Object", 0, 12),
2012             "10: " + getCheckMessage(MSG_ERROR, "(", 0, 12),
2013             "13: " + getCheckMessage(MSG_CHILD_ERROR, "operator new", 0, 8),
2014             "15: " + getCheckMessage(MSG_ERROR, "operator new lparen", 0, 8),
2015         };
2016         verifyWarns(checkConfig, getPath("InputIndentationNewHandler.java"), expected);
2017     }
2018 
2019     private static final class IndentAudit implements AuditListener {
2020 
2021         private final IndentComment[] comments;
2022         private int position;
2023 
2024         /* package */ IndentAudit(IndentComment... comments) {
2025             this.comments = Arrays.copyOf(comments, comments.length);
2026         }
2027 
2028         @Override
2029         public void auditStarted(AuditEvent event) {
2030             // No code needed
2031         }
2032 
2033         @Override
2034         public void auditFinished(AuditEvent event) {
2035             // No code needed
2036         }
2037 
2038         @Override
2039         public void fileStarted(AuditEvent event) {
2040             // No code needed
2041         }
2042 
2043         @Override
2044         public void fileFinished(AuditEvent event) {
2045             // No code needed
2046         }
2047 
2048         @Override
2049         public void addError(AuditEvent event) {
2050             final int line = event.getLine();
2051             final String message = event.getMessage();
2052 
2053             if (position >= comments.length) {
2054                 fail("found a warning when none was expected for #" + position + " at line " + line
2055                         + " with message " + message);
2056             }
2057 
2058             final IndentComment comment = comments[position];
2059             position++;
2060 
2061             final String possibleExceptedMessages = Arrays.stream(comment.getExpectedMessages())
2062                     .reduce("", (cur, next) -> cur + "\"" + next + "\", ");
2063             final String assertMessage = String.format(
2064                     Locale.ROOT,
2065                     "input expected warning #%d at line %d to report one of the following: %s"
2066                             + "but got instead: %d: %s",
2067                     position, comment.getLineNumber(), possibleExceptedMessages, line, message);
2068             assertTrue(assertMessage, line == comment.getLineNumber()
2069                     && Arrays.stream(comment.getExpectedMessages()).anyMatch(message::endsWith));
2070         }
2071 
2072         @Override
2073         public void addException(AuditEvent event, Throwable throwable) {
2074             // No code needed
2075         }
2076 
2077     }
2078 
2079     private static final class IndentComment {
2080 
2081         /** Used to locate the index of argument zero of error messages. */
2082         private static final String FAKE_ARGUMENT_ZERO = "##0##";
2083         private final int lineNumber;
2084         private final int indent;
2085         /** Used for when violations report nodes not first on the line. */
2086         private final int indentOffset;
2087         private final boolean expectedNonStrict;
2088         private final String expectedWarning;
2089         private final boolean warning;
2090 
2091         /* package */ IndentComment(Matcher match, int lineNumber) {
2092             this.lineNumber = lineNumber;
2093             indent = Integer.parseInt(match.group(1));
2094             if (match.group(2) == null) {
2095                 indentOffset = 0;
2096             }
2097             else {
2098                 indentOffset = Integer.parseInt(match.group(2));
2099             }
2100             expectedNonStrict = match.group(3) != null;
2101             expectedWarning = match.group(4).replace(",", ", ");
2102             warning = match.group(5) != null;
2103         }
2104 
2105         public String[] getExpectedMessages() {
2106             final String[] expectedMessages;
2107             if (expectedWarning.contains(",")) {
2108                 expectedMessages = new String[] {
2109                     getExpectedMessagePostfix(MSG_ERROR_MULTI),
2110                     getExpectedMessagePostfix(MSG_CHILD_ERROR_MULTI),
2111                 };
2112             }
2113             else {
2114                 expectedMessages = new String[] {
2115                     getExpectedMessagePostfix(MSG_ERROR),
2116                     getExpectedMessagePostfix(MSG_CHILD_ERROR),
2117                 };
2118             }
2119             return expectedMessages;
2120         }
2121 
2122         private String getExpectedMessagePostfix(final String messageKey) {
2123             final String msg = getCheckMessage(IndentationCheck.class, messageKey,
2124                     FAKE_ARGUMENT_ZERO, indent + indentOffset, expectedWarning);
2125             final int indexOfMsgPostfix = msg.indexOf(FAKE_ARGUMENT_ZERO)
2126                     + FAKE_ARGUMENT_ZERO.length();
2127             return msg.substring(indexOfMsgPostfix);
2128         }
2129 
2130         public int getLineNumber() {
2131             return lineNumber;
2132         }
2133 
2134         public int getIndent() {
2135             return indent;
2136         }
2137 
2138         public int getIndentOffset() {
2139             return indentOffset;
2140         }
2141 
2142         public boolean isExpectedNonStrict() {
2143             return expectedNonStrict;
2144         }
2145 
2146         public String getExpectedWarning() {
2147             return expectedWarning;
2148         }
2149 
2150         public boolean isWarning() {
2151             return warning;
2152         }
2153 
2154     }
2155 
2156 }