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.javadoc;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTagContinuationIndentationCheck.MSG_KEY;
24  
25  import org.junit.jupiter.api.Test;
26  
27  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
29  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
30  
31  public class JavadocTagContinuationIndentationCheckTest
32          extends AbstractModuleTestSupport {
33  
34      @Override
35      public String getPackageLocation() {
36          return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadoctagcontinuationindentation";
37      }
38  
39      @Test
40      public void testGetRequiredTokens() {
41          final JavadocTagContinuationIndentationCheck checkObj =
42              new JavadocTagContinuationIndentationCheck();
43          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN };
44          assertWithMessage("Default required tokens are invalid")
45              .that(checkObj.getRequiredTokens())
46              .isEqualTo(expected);
47      }
48  
49      @Test
50      public void testFp() throws Exception {
51          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
52          verifyWithInlineConfigParser(
53                  getPath("InputJavadocTagContinuationIndentationGuavaFalsePositive.java"),
54                 expected);
55      }
56  
57      @Test
58      public void testCheck() throws Exception {
59          final String[] expected = {
60              "56: " + getCheckMessage(MSG_KEY, 4),
61          };
62          verifyWithInlineConfigParser(
63                  getPath("InputJavadocTagContinuationIndentation.java"),
64                  expected);
65      }
66  
67      @Test
68      public void testCheckMethod456() throws Exception {
69          final String[] expected = {
70              "40: " + getCheckMessage(MSG_KEY, 4),
71              "43: " + getCheckMessage(MSG_KEY, 4),
72          };
73          verifyWithInlineConfigParser(
74                  getPath("InputJavadocTagContinuationIndentationMethod456.java"),
75                  expected);
76      }
77  
78      @Test
79      public void testCheckInnerClass() throws Exception {
80          final String[] expected = {
81              "95: " + getCheckMessage(MSG_KEY, 4),
82              "98: " + getCheckMessage(MSG_KEY, 4),
83          };
84          verifyWithInlineConfigParser(
85                  getPath("InputJavadocTagContinuationIndentationInnerClass.java"),
86                  expected);
87      }
88  
89      @Test
90      public void testCheckAnonymousClass() throws Exception {
91          final String[] expected = {
92              "20: " + getCheckMessage(MSG_KEY, 4),
93              "22: " + getCheckMessage(MSG_KEY, 4),
94              "87: " + getCheckMessage(MSG_KEY, 4),
95              "90: " + getCheckMessage(MSG_KEY, 4),
96              "92: " + getCheckMessage(MSG_KEY, 4),
97          };
98          verifyWithInlineConfigParser(
99                  getPath("InputJavadocTagContinuationIndentationAnonymousClass.java"),
100                 expected);
101     }
102 
103     @Test
104     public void testCheckOthers() throws Exception {
105         final String[] expected = {
106             "21: " + getCheckMessage(MSG_KEY, 4),
107             "35: " + getCheckMessage(MSG_KEY, 4),
108             "37: " + getCheckMessage(MSG_KEY, 4),
109             "57: " + getCheckMessage(MSG_KEY, 4),
110         };
111         verifyWithInlineConfigParser(
112                 getPath("InputJavadocTagContinuationIndentationOthers.java"),
113                 expected);
114     }
115 
116     @Test
117     public void testCheckWithOffset3() throws Exception {
118         final String[] expected = {
119             "16: " + getCheckMessage(MSG_KEY, 3),
120             "29: " + getCheckMessage(MSG_KEY, 3),
121         };
122         verifyWithInlineConfigParser(
123                 getPath("InputJavadocTagContinuationIndentationOffset3.java"),
124                 expected);
125     }
126 
127     @Test
128     public void testCheckWithDescription() throws Exception {
129         final String[] expected = {
130             "19: " + getCheckMessage(MSG_KEY, 4),
131             "20: " + getCheckMessage(MSG_KEY, 4),
132             "21: " + getCheckMessage(MSG_KEY, 4),
133             "53: " + getCheckMessage(MSG_KEY, 4),
134             "55: " + getCheckMessage(MSG_KEY, 4),
135             "56: " + getCheckMessage(MSG_KEY, 4),
136             "76: " + getCheckMessage(MSG_KEY, 4),
137             "77: " + getCheckMessage(MSG_KEY, 4),
138         };
139         verifyWithInlineConfigParser(
140                 getPath("InputJavadocTagContinuationIndentationDescription.java"),
141                 expected);
142     }
143 
144     @Test
145     public void testBlockTag() throws Exception {
146         final String[] expected = {
147             "21: " + getCheckMessage(MSG_KEY, 4),
148             "31: " + getCheckMessage(MSG_KEY, 4),
149             "40: " + getCheckMessage(MSG_KEY, 4),
150             "57: " + getCheckMessage(MSG_KEY, 4),
151             "67: " + getCheckMessage(MSG_KEY, 4),
152             "68: " + getCheckMessage(MSG_KEY, 4),
153             "95: " + getCheckMessage(MSG_KEY, 4),
154             "96: " + getCheckMessage(MSG_KEY, 4),
155             "97: " + getCheckMessage(MSG_KEY, 4),
156             "98: " + getCheckMessage(MSG_KEY, 4),
157             "99: " + getCheckMessage(MSG_KEY, 4),
158             "100: " + getCheckMessage(MSG_KEY, 4),
159             "101: " + getCheckMessage(MSG_KEY, 4),
160             "102: " + getCheckMessage(MSG_KEY, 4),
161             "103: " + getCheckMessage(MSG_KEY, 4),
162             "104: " + getCheckMessage(MSG_KEY, 4),
163             "105: " + getCheckMessage(MSG_KEY, 4),
164             "106: " + getCheckMessage(MSG_KEY, 4),
165             "107: " + getCheckMessage(MSG_KEY, 4),
166             "108: " + getCheckMessage(MSG_KEY, 4),
167             "113: " + getCheckMessage(MSG_KEY, 4),
168             "114: " + getCheckMessage(MSG_KEY, 4),
169         };
170         verifyWithInlineConfigParser(
171                 getPath("InputJavadocTagContinuationIndentationBlockTag.java"),
172                 expected);
173     }
174 
175     @Test
176     public void testContinuationIndentation() throws Exception {
177         final String[] expected = {
178             "23: " + getCheckMessage(MSG_KEY, 4),
179         };
180         verifyWithInlineConfigParser(
181                 getPath("InputJavadocTagContinuationIndentation1.java"),
182                 expected);
183     }
184 
185     @Test
186     public void testJavadocTagContinuationIndentationCheck1() throws Exception {
187         final String[] expected = {
188             "25: " + getCheckMessage(MSG_KEY, 4),
189             "28: " + getCheckMessage(MSG_KEY, 4),
190             "29: " + getCheckMessage(MSG_KEY, 4),
191         };
192         verifyWithInlineConfigParser(
193                 getPath("InputJavadocTagContinuationIndentationCheck1.java"),
194                 expected);
195     }
196 
197     @Test
198     public void testJavadocTagContinuationIndentationCheckHtml() throws Exception {
199         final String[] expected = {
200             "15: " + getCheckMessage(MSG_KEY, 4),
201             "18: " + getCheckMessage(MSG_KEY, 4),
202             "28: " + getCheckMessage(MSG_KEY, 4),
203             "29: " + getCheckMessage(MSG_KEY, 4),
204             "30: " + getCheckMessage(MSG_KEY, 4),
205             "50: " + getCheckMessage(MSG_KEY, 4),
206             "51: " + getCheckMessage(MSG_KEY, 4),
207             "52: " + getCheckMessage(MSG_KEY, 4),
208             "63: " + getCheckMessage(MSG_KEY, 4),
209             "64: " + getCheckMessage(MSG_KEY, 4),
210             "65: " + getCheckMessage(MSG_KEY, 4),
211             "75: " + getCheckMessage(MSG_KEY, 4),
212             "76: " + getCheckMessage(MSG_KEY, 4),
213             "83: " + getCheckMessage(MSG_KEY, 4),
214             "90: " + getCheckMessage(MSG_KEY, 4),
215         };
216         verifyWithInlineConfigParser(
217                 getPath("InputJavadocTagContinuationIndentationCheckHtml.java"),
218                 expected);
219     }
220 
221     @Test
222     public void testJavadocTagContinuationIndentationCheckPreTag() throws Exception {
223         final String[] expected = {
224             "91: " + getCheckMessage(MSG_KEY, 4),
225             "101: " + getCheckMessage(MSG_KEY, 4),
226             "102: " + getCheckMessage(MSG_KEY, 4),
227             "103: " + getCheckMessage(MSG_KEY, 4),
228         };
229         verifyWithInlineConfigParser(
230             getPath("InputJavadocTagContinuationIndentationPreTag.java"), expected);
231     }
232 
233     @Test
234     public void testJavadocTagContinuationIndentationCheckPreTag2() throws Exception {
235         final String[] expected = {
236             "32: " + getCheckMessage(MSG_KEY, 4),
237             "33: " + getCheckMessage(MSG_KEY, 4),
238             "34: " + getCheckMessage(MSG_KEY, 4),
239             "35: " + getCheckMessage(MSG_KEY, 4),
240         };
241         verifyWithInlineConfigParser(
242             getPath("InputJavadocTagContinuationIndentationPreTag2.java"), expected);
243     }
244 
245     @Test
246     public void testJavadocTagContinuationIndentationCheckPreTag2Two() throws Exception {
247         final String[] expected = {
248             "23: " + getCheckMessage(MSG_KEY, 4),
249             "31: " + getCheckMessage(MSG_KEY, 4),
250             "32: " + getCheckMessage(MSG_KEY, 4),
251             "33: " + getCheckMessage(MSG_KEY, 4),
252             "34: " + getCheckMessage(MSG_KEY, 4),
253             "35: " + getCheckMessage(MSG_KEY, 4),
254             "36: " + getCheckMessage(MSG_KEY, 4),
255             "37: " + getCheckMessage(MSG_KEY, 4),
256             "38: " + getCheckMessage(MSG_KEY, 4),
257             "43: " + getCheckMessage(MSG_KEY, 4),
258             "44: " + getCheckMessage(MSG_KEY, 4),
259             "45: " + getCheckMessage(MSG_KEY, 4),
260         };
261         verifyWithInlineConfigParser(
262             getPath("InputJavadocTagContinuationIndentationPreTag2Two.java"), expected);
263     }
264 
265     @Test
266     public void testJavadocTagContinuationIndentationCheckPreTag3() throws Exception {
267         final String[] expected = {
268             "34: " + getCheckMessage(MSG_KEY, 4),
269             "35: " + getCheckMessage(MSG_KEY, 4),
270             "36: " + getCheckMessage(MSG_KEY, 4),
271             "37: " + getCheckMessage(MSG_KEY, 4),
272         };
273         verifyWithInlineConfigParser(
274             getPath("InputJavadocTagContinuationIndentationPreTag3.java"), expected);
275     }
276 
277 }