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