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.rule487modifiers;
21  
22  import org.junit.Test;
23  
24  import com.google.checkstyle.test.base.AbstractModuleTestSupport;
25  import com.puppycrawl.tools.checkstyle.api.Configuration;
26  import com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck;
27  
28  public class ModifierOrderTest extends AbstractModuleTestSupport {
29  
30      @Override
31      protected String getPackageLocation() {
32          return "com/google/checkstyle/test/chapter4formatting/rule487modifiers";
33      }
34  
35      @Test
36      public void testModifierOrder() throws Exception {
37  
38          final Class<ModifierOrderCheck> clazz = ModifierOrderCheck.class;
39          final String msgMod = "mod.order";
40          final String msgAnnotation = "annotation.order";
41  
42          final String[] expected = {
43              "3:10: " + getCheckMessage(clazz, msgMod, "abstract"),
44              "5:19: " + getCheckMessage(clazz, msgMod, "private"),
45              "7:18: " + getCheckMessage(clazz, msgMod, "public"),
46              "15:14: " + getCheckMessage(clazz, msgMod, "private"),
47              "25:13: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
48              "30:13: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
49              "40:34: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation4"),
50              "46:14: " + getCheckMessage(clazz, msgMod, "protected"),
51              "48:18: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
52              "50:40: " + getCheckMessage(clazz, msgMod, "final"),
53              "52:29: " + getCheckMessage(clazz, msgMod, "static"),
54              "54:18: " + getCheckMessage(clazz, msgMod, "final"),
55              "56:49: " + getCheckMessage(clazz, msgMod, "private"),
56              "58:20: " + getCheckMessage(clazz, msgMod, "synchronized"),
57              "60:29: " + getCheckMessage(clazz, msgMod, "protected"),
58              "62:14: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
59              "80:11: " + getCheckMessage(clazz, msgMod, "private"),
60              "96:15: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
61              "98:12: " + getCheckMessage(clazz, msgMod, "protected"),
62              "102:12: " + getCheckMessage(clazz, msgMod, "synchronized"),
63              "104:12: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
64              "106:19: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
65              "108:18: " + getCheckMessage(clazz, msgMod, "static"),
66              "110:25: " + getCheckMessage(clazz, msgMod, "private"),
67              "137:27: " + getCheckMessage(clazz, msgMod, "private"),
68              "139:26: " + getCheckMessage(clazz, msgMod, "public"),
69              "143:23: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
70              "145:26: " + getCheckMessage(clazz, msgMod, "protected"),
71              "147:20: " + getCheckMessage(clazz, msgMod, "synchronized"),
72              "149:20: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
73              "151:20: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
74              "153:33: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
75              "155:26: " + getCheckMessage(clazz, msgMod, "private"),
76              "168:35: " + getCheckMessage(clazz, msgMod, "private"),
77              "170:34: " + getCheckMessage(clazz, msgMod, "public"),
78              "172:35: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
79              "174:31: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
80              "176:34: " + getCheckMessage(clazz, msgMod, "protected"),
81              "178:28: " + getCheckMessage(clazz, msgMod, "synchronized"),
82              "182:28: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
83              "184:41: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
84              "186:34: " + getCheckMessage(clazz, msgMod, "private"),
85              "197:27: " + getCheckMessage(clazz, msgMod, "private"),
86              "199:26: " + getCheckMessage(clazz, msgMod, "public"),
87              "203:22: " + getCheckMessage(clazz, msgMod, "protected"),
88              "205:26: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
89              "207:41: " + getCheckMessage(clazz, msgMod, "final"),
90              "209:37: " + getCheckMessage(clazz, msgMod, "final"),
91              "211:26: " + getCheckMessage(clazz, msgMod, "final"),
92              "213:50: " + getCheckMessage(clazz, msgMod, "private"),
93              "215:28: " + getCheckMessage(clazz, msgMod, "synchronized"),
94              "217:37: " + getCheckMessage(clazz, msgMod, "protected"),
95              "219:22: " + getCheckMessage(clazz, msgAnnotation, "@MyAnnotation2"),
96              "245:14: " + getCheckMessage(clazz, msgMod, "default"),
97          };
98  
99          final Configuration checkConfig = getModuleConfig("ModifierOrder");
100         final String filePath = getPath("InputModifierOrder.java");
101 
102         final Integer[] warnList = getLinesWithWarn(filePath);
103         verify(checkConfig, filePath, expected, warnList);
104     }
105 }