View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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.modifier;
21  
22  import static com.puppycrawl.tools.checkstyle.checks.modifier.InterfaceMemberImpliedModifierCheck.MSG_KEY;
23  
24  import org.junit.jupiter.api.Test;
25  
26  import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
27  
28  public class InterfaceMemberImpliedModifierCheckExamplesTest
29          extends AbstractExamplesModuleTestSupport {
30  
31      @Override
32      public String getPackageLocation() {
33          return "com/puppycrawl/tools/checkstyle/checks/modifier/interfacememberimpliedmodifier";
34      }
35  
36      @Test
37      public void testExample1() throws Exception {
38          final String[] expected = {
39              "16:3: " + getCheckMessage(MSG_KEY, "final"),
40              "16:3: " + getCheckMessage(MSG_KEY, "public"),
41              "16:3: " + getCheckMessage(MSG_KEY, "static"),
42              "24:3: " + getCheckMessage(MSG_KEY, "abstract"),
43              "24:3: " + getCheckMessage(MSG_KEY, "public"),
44              "28:3: " + getCheckMessage(MSG_KEY, "public"),
45              "28:3: " + getCheckMessage(MSG_KEY, "static"),
46              "32:5: " + getCheckMessage(MSG_KEY, "abstract"),
47              "32:5: " + getCheckMessage(MSG_KEY, "public"),
48          };
49  
50          verifyWithInlineConfigParser(getPath("Example1.java"), expected);
51      }
52  
53      @Test
54      public void testExample2() throws Exception {
55          final String[] expected = {
56              "19:3: " + getCheckMessage(MSG_KEY, "final"),
57              "19:3: " + getCheckMessage(MSG_KEY, "public"),
58              "19:3: " + getCheckMessage(MSG_KEY, "static"),
59              "27:3: " + getCheckMessage(MSG_KEY, "abstract"),
60              "27:3: " + getCheckMessage(MSG_KEY, "public"),
61              "35:5: " + getCheckMessage(MSG_KEY, "abstract"),
62              "35:5: " + getCheckMessage(MSG_KEY, "public"),
63          };
64  
65          verifyWithInlineConfigParser(getPath("Example2.java"), expected);
66      }
67  
68      @Test
69      public void testExample3() throws Exception {
70          final String[] expected = {
71              "28:3: " + getCheckMessage(MSG_KEY, "abstract"),
72              "28:3: " + getCheckMessage(MSG_KEY, "public"),
73              "32:3: " + getCheckMessage(MSG_KEY, "public"),
74              "32:3: " + getCheckMessage(MSG_KEY, "static"),
75              "36:5: " + getCheckMessage(MSG_KEY, "abstract"),
76              "36:5: " + getCheckMessage(MSG_KEY, "public"),
77          };
78          verifyWithInlineConfigParser(getPath("Example3.java"), expected);
79      }
80  
81      @Test
82      public void testExample4() throws Exception {
83          final String[] expected = {
84              "19:3: " + getCheckMessage(MSG_KEY, "final"),
85              "19:3: " + getCheckMessage(MSG_KEY, "public"),
86              "19:3: " + getCheckMessage(MSG_KEY, "static"),
87              "31:3: " + getCheckMessage(MSG_KEY, "public"),
88              "31:3: " + getCheckMessage(MSG_KEY, "static"),
89          };
90          verifyWithInlineConfigParser(getPath("Example4.java"), expected);
91      }
92  
93      @Test
94      public void testExample5() throws Exception {
95          final String[] expected = {
96              "18:3: " + getCheckMessage(MSG_KEY, "final"),
97              "18:3: " + getCheckMessage(MSG_KEY, "public"),
98              "18:3: " + getCheckMessage(MSG_KEY, "static"),
99              "26:3: " + getCheckMessage(MSG_KEY, "abstract"),
100             "26:3: " + getCheckMessage(MSG_KEY, "public"),
101             "30:3: " + getCheckMessage(MSG_KEY, "static"),
102             "34:5: " + getCheckMessage(MSG_KEY, "abstract"),
103             "34:5: " + getCheckMessage(MSG_KEY, "public"),
104         };
105         verifyWithInlineConfigParser(getPath("Example5.java"), expected);
106     }
107 
108     @Test
109     public void testExample6() throws Exception {
110         final String[] expected = {
111             "18:3: " + getCheckMessage(MSG_KEY, "final"),
112             "18:3: " + getCheckMessage(MSG_KEY, "public"),
113             "18:3: " + getCheckMessage(MSG_KEY, "static"),
114             "26:3: " + getCheckMessage(MSG_KEY, "abstract"),
115             "26:3: " + getCheckMessage(MSG_KEY, "public"),
116             "30:3: " + getCheckMessage(MSG_KEY, "public"),
117             "34:5: " + getCheckMessage(MSG_KEY, "abstract"),
118             "34:5: " + getCheckMessage(MSG_KEY, "public"),
119         };
120         verifyWithInlineConfigParser(getPath("Example6.java"), expected);
121     }
122 
123     @Test
124     public void testExample7() throws Exception {
125         final String[] expected = {
126             "18:3: " + getCheckMessage(MSG_KEY, "final"),
127             "18:3: " + getCheckMessage(MSG_KEY, "static"),
128             "26:3: " + getCheckMessage(MSG_KEY, "abstract"),
129             "26:3: " + getCheckMessage(MSG_KEY, "public"),
130             "30:3: " + getCheckMessage(MSG_KEY, "public"),
131             "30:3: " + getCheckMessage(MSG_KEY, "static"),
132             "34:5: " + getCheckMessage(MSG_KEY, "abstract"),
133             "34:5: " + getCheckMessage(MSG_KEY, "public"),
134         };
135         verifyWithInlineConfigParser(getPath("Example7.java"), expected);
136     }
137 
138     @Test
139     public void testExample8() throws Exception {
140         final String[] expected = {
141             "18:3: " + getCheckMessage(MSG_KEY, "final"),
142             "18:3: " + getCheckMessage(MSG_KEY, "public"),
143             "26:3: " + getCheckMessage(MSG_KEY, "abstract"),
144             "26:3: " + getCheckMessage(MSG_KEY, "public"),
145             "30:3: " + getCheckMessage(MSG_KEY, "public"),
146             "30:3: " + getCheckMessage(MSG_KEY, "static"),
147             "34:5: " + getCheckMessage(MSG_KEY, "abstract"),
148             "34:5: " + getCheckMessage(MSG_KEY, "public"),
149         };
150         verifyWithInlineConfigParser(getPath("Example8.java"), expected);
151     }
152 
153 }