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.google.checkstyle.test.chapter4formatting.rule4841indentation;
21  
22  import org.junit.Test;
23  
24  import com.google.checkstyle.test.base.AbstractIndentationTestSupport;
25  import com.puppycrawl.tools.checkstyle.api.Configuration;
26  import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
27  
28  public class IndentationTest extends AbstractIndentationTestSupport {
29  
30      @Override
31      protected String getPackageLocation() {
32          return "com/google/checkstyle/test/chapter4formatting/rule4841indentation";
33      }
34  
35      @Test
36      public void testCorrectClass() throws Exception {
37  
38          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
39  
40          final Configuration checkConfig = getModuleConfig("Indentation");
41          final String filePath = getPath("InputIndentationCorrectClass.java");
42  
43          final Integer[] warnList = getLinesWithWarn(filePath);
44          verify(checkConfig, filePath, expected, warnList);
45      }
46  
47      @Test
48      public void testCorrectField() throws Exception {
49  
50          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
51  
52          final Configuration checkConfig = getModuleConfig("Indentation");
53          final String filePath = getPath("InputIndentationCorrectFieldAndParameter.java");
54  
55          final Integer[] warnList = getLinesWithWarn(filePath);
56          verify(checkConfig, filePath, expected, warnList);
57      }
58  
59      @Test
60      public void testCorrectFor() throws Exception {
61  
62          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
63  
64          final Configuration checkConfig = getModuleConfig("Indentation");
65          final String filePath = getPath("InputIndentationCorrectForAndParameter.java");
66  
67          final Integer[] warnList = getLinesWithWarn(filePath);
68          verify(checkConfig, filePath, expected, warnList);
69      }
70  
71      @Test
72      public void testCorrectIf() throws Exception {
73  
74          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
75  
76          final Configuration checkConfig = getModuleConfig("Indentation");
77          final String filePath = getPath("InputIndentationCorrectIfAndParameter.java");
78  
79          final Integer[] warnList = getLinesWithWarn(filePath);
80          verify(checkConfig, filePath, expected, warnList);
81      }
82  
83      @Test
84      public void testCorrect() throws Exception {
85  
86          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
87  
88          final Configuration checkConfig = getModuleConfig("Indentation");
89          final String filePath = getPath("InputIndentationCorrect.java");
90  
91          final Integer[] warnList = getLinesWithWarn(filePath);
92          verify(checkConfig, filePath, expected, warnList);
93      }
94  
95      @Test
96      public void testCorrectReturn() throws Exception {
97  
98          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
99  
100         final Configuration checkConfig = getModuleConfig("Indentation");
101         final String filePath = getPath("InputIndentationCorrectReturnAndParameter.java");
102 
103         final Integer[] warnList = getLinesWithWarn(filePath);
104         verify(checkConfig, filePath, expected, warnList);
105     }
106 
107     @Test
108     public void testCorrectWhile() throws Exception {
109 
110         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
111 
112         final Configuration checkConfig = getModuleConfig("Indentation");
113         final String filePath = getPath("InputIndentationCorrectWhileDoWhileAndParameter.java");
114 
115         final Integer[] warnList = getLinesWithWarn(filePath);
116         verify(checkConfig, filePath, expected, warnList);
117     }
118 }