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