1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.AtclauseOrderCheck.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 AtclauseOrderCheckTest extends AbstractModuleTestSupport {
32
33 @Override
34 protected String getPackageLocation() {
35 return "com/puppycrawl/tools/checkstyle/checks/javadoc/atclauseorder";
36 }
37
38 @Test
39 public void testGetAcceptableTokens() {
40 final AtclauseOrderCheck checkObj = new AtclauseOrderCheck();
41 final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
42 assertWithMessage("Default acceptable tokens are invalid")
43 .that(checkObj.getAcceptableTokens())
44 .isEqualTo(expected);
45 }
46
47 @Test
48 public void testGetRequiredTokens() {
49 final AtclauseOrderCheck checkObj = new AtclauseOrderCheck();
50 final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
51 assertWithMessage("Default acceptable tokens are invalid")
52 .that(checkObj.getAcceptableTokens())
53 .isEqualTo(expected);
54 }
55
56 @Test
57 public void testCorrect1() throws Exception {
58 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
59
60 verifyWithInlineConfigParser(
61 getPath("InputAtclauseOrderCorrect1.java"), expected);
62 }
63
64 @Test
65 public void testCorrect2() throws Exception {
66 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
67
68 verifyWithInlineConfigParser(
69 getPath("InputAtclauseOrderCorrect2.java"), expected);
70 }
71
72 @Test
73 public void testCorrect3() throws Exception {
74 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
75
76 verifyWithInlineConfigParser(
77 getPath("InputAtclauseOrderCorrect3.java"), expected);
78 }
79
80 @Test
81 public void testCorrect4() throws Exception {
82 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
83
84 verifyWithInlineConfigParser(
85 getPath("InputAtclauseOrderCorrect4.java"), expected);
86 }
87
88 @Test
89 public void testIncorrect1() throws Exception {
90 final String tagOrder = "[@author, @version, @param, @return, @throws, @exception, @see,"
91 + " @since, @serial, @serialField, @serialData, @deprecated]";
92 final String[] expected = {
93 "20: " + getCheckMessage(MSG_KEY, tagOrder),
94 "22: " + getCheckMessage(MSG_KEY, tagOrder),
95 "23: " + getCheckMessage(MSG_KEY, tagOrder),
96 "51: " + getCheckMessage(MSG_KEY, tagOrder),
97 "61: " + getCheckMessage(MSG_KEY, tagOrder),
98 "62: " + getCheckMessage(MSG_KEY, tagOrder),
99 "63: " + getCheckMessage(MSG_KEY, tagOrder),
100 "73: " + getCheckMessage(MSG_KEY, tagOrder),
101 "80: " + getCheckMessage(MSG_KEY, tagOrder),
102 "97: " + getCheckMessage(MSG_KEY, tagOrder),
103 "98: " + getCheckMessage(MSG_KEY, tagOrder),
104 "110: " + getCheckMessage(MSG_KEY, tagOrder),
105 "111: " + getCheckMessage(MSG_KEY, tagOrder),
106 "112: " + getCheckMessage(MSG_KEY, tagOrder),
107 };
108 verifyWithInlineConfigParser(
109 getPath("InputAtclauseOrderIncorrect1.java"), expected);
110 }
111
112 @Test
113 public void testIncorrect2() throws Exception {
114 final String tagOrder = "[@author, @version, @param, @return, @throws, @exception, @see,"
115 + " @since, @serial, @serialField, @serialData, @deprecated]";
116 final String[] expected = {
117 "20: " + getCheckMessage(MSG_KEY, tagOrder),
118 "22: " + getCheckMessage(MSG_KEY, tagOrder),
119 "23: " + getCheckMessage(MSG_KEY, tagOrder),
120 "33: " + getCheckMessage(MSG_KEY, tagOrder),
121 "41: " + getCheckMessage(MSG_KEY, tagOrder),
122 "42: " + getCheckMessage(MSG_KEY, tagOrder),
123 "52: " + getCheckMessage(MSG_KEY, tagOrder),
124 "53: " + getCheckMessage(MSG_KEY, tagOrder),
125 "63: " + getCheckMessage(MSG_KEY, tagOrder),
126 "64: " + getCheckMessage(MSG_KEY, tagOrder),
127 "74: " + getCheckMessage(MSG_KEY, tagOrder),
128 "77: " + getCheckMessage(MSG_KEY, tagOrder),
129 "88: " + getCheckMessage(MSG_KEY, tagOrder),
130 "98: " + getCheckMessage(MSG_KEY, tagOrder),
131 };
132 verifyWithInlineConfigParser(
133 getPath("InputAtclauseOrderIncorrect2.java"), expected);
134 }
135
136 @Test
137 public void testIncorrect3() throws Exception {
138 final String tagOrder = "[@author, @version, @param, @return, @throws, @exception, @see,"
139 + " @since, @serial, @serialField, @serialData, @deprecated]";
140 final String[] expected = {
141 "20: " + getCheckMessage(MSG_KEY, tagOrder),
142 "22: " + getCheckMessage(MSG_KEY, tagOrder),
143 "23: " + getCheckMessage(MSG_KEY, tagOrder),
144 "33: " + getCheckMessage(MSG_KEY, tagOrder),
145 "40: " + getCheckMessage(MSG_KEY, tagOrder),
146 "48: " + getCheckMessage(MSG_KEY, tagOrder),
147 "61: " + getCheckMessage(MSG_KEY, tagOrder),
148 "68: " + getCheckMessage(MSG_KEY, tagOrder),
149 };
150 verifyWithInlineConfigParser(
151 getPath("InputAtclauseOrderIncorrect3.java"), expected);
152 }
153
154 @Test
155 public void testIncorrect4() throws Exception {
156 final String tagOrder = "[@author, @version, @param, @return, @throws, @exception, @see,"
157 + " @since, @serial, @serialField, @serialData, @deprecated]";
158 final String[] expected = {
159 "20: " + getCheckMessage(MSG_KEY, tagOrder),
160 "22: " + getCheckMessage(MSG_KEY, tagOrder),
161 "23: " + getCheckMessage(MSG_KEY, tagOrder),
162 "33: " + getCheckMessage(MSG_KEY, tagOrder),
163 "40: " + getCheckMessage(MSG_KEY, tagOrder),
164 "50: " + getCheckMessage(MSG_KEY, tagOrder),
165 "52: " + getCheckMessage(MSG_KEY, tagOrder),
166 "65: " + getCheckMessage(MSG_KEY, tagOrder),
167 "66: " + getCheckMessage(MSG_KEY, tagOrder),
168 "76: " + getCheckMessage(MSG_KEY, tagOrder),
169 "78: " + getCheckMessage(MSG_KEY, tagOrder),
170 "91: " + getCheckMessage(MSG_KEY, tagOrder),
171 "93: " + getCheckMessage(MSG_KEY, tagOrder),
172 "94: " + getCheckMessage(MSG_KEY, tagOrder),
173 "104: " + getCheckMessage(MSG_KEY, tagOrder),
174 };
175 verifyWithInlineConfigParser(
176 getPath("InputAtclauseOrderIncorrect4.java"), expected);
177 }
178
179 @Test
180 public void testIncorrectCustom1() throws Exception {
181 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
182
183 verifyWithInlineConfigParser(
184 getPath("InputAtclauseOrderIncorrectCustom1.java"), expected);
185 }
186
187 @Test
188 public void testIncorrectCustom2() throws Exception {
189 final String tagOrder = "[@since, @version, @param, @return, @throws, @exception,"
190 + " @deprecated, @see, @serial, @serialField, @serialData, @author]";
191 final String[] expected = {
192 "30: " + getCheckMessage(MSG_KEY, tagOrder),
193 };
194 verifyWithInlineConfigParser(
195 getPath("InputAtclauseOrderIncorrectCustom2.java"), expected);
196 }
197
198 @Test
199 public void testIncorrectCustom3() throws Exception {
200 final String tagOrder = "[@since, @version, @param, @return, @throws, @exception,"
201 + " @deprecated, @see, @serial, @serialField, @serialData, @author]";
202 final String[] expected = {
203 "30: " + getCheckMessage(MSG_KEY, tagOrder),
204 };
205 verifyWithInlineConfigParser(
206 getPath("InputAtclauseOrderIncorrectCustom3.java"), expected);
207 }
208
209 @Test
210 public void testIncorrectCustom4() throws Exception {
211 final String tagOrder = "[@since, @version, @param, @return, @throws, @exception,"
212 + " @deprecated, @see, @serial, @serialField, @serialData, @author]";
213 final String[] expected = {
214 "30: " + getCheckMessage(MSG_KEY, tagOrder),
215 };
216 verifyWithInlineConfigParser(
217 getPath("InputAtclauseOrderIncorrectCustom4.java"), expected);
218 }
219
220 @Test
221 public void testPackageInfo() throws Exception {
222
223 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
224 verifyWithInlineConfigParser(
225 getPath("package-info.java"), expected);
226 }
227
228 @Test
229 public void testAtclauseOrderRecords() throws Exception {
230 final String tagOrder = "[@author, @version, @param, @return, @throws, @exception,"
231 + " @see, @since, @serial, @serialField, @serialData, @deprecated]";
232
233 final String[] expected = {
234 "36: " + getCheckMessage(MSG_KEY, tagOrder),
235 "37: " + getCheckMessage(MSG_KEY, tagOrder),
236 "38: " + getCheckMessage(MSG_KEY, tagOrder),
237 "48: " + getCheckMessage(MSG_KEY, tagOrder),
238 "49: " + getCheckMessage(MSG_KEY, tagOrder),
239 "58: " + getCheckMessage(MSG_KEY, tagOrder),
240 "77: " + getCheckMessage(MSG_KEY, tagOrder),
241 "92: " + getCheckMessage(MSG_KEY, tagOrder),
242 };
243 verifyWithInlineConfigParser(
244 getNonCompilablePath("InputAtclauseOrderRecords.java"), expected);
245 }
246
247 @Test
248 public void testMethodReturningArrayType() throws Exception {
249 final String tagOrder = "[@author, @version, @param, @return, @throws, @exception, @see,"
250 + " @since, @serial, @serialField, @serialData, @deprecated]";
251 final String[] expected = {
252 "20: " + getCheckMessage(MSG_KEY, tagOrder),
253 "32: " + getCheckMessage(MSG_KEY, tagOrder),
254 "33: " + getCheckMessage(MSG_KEY, tagOrder),
255 };
256 verifyWithInlineConfigParser(
257 getPath("InputAtclauseOrderMethodReturningArrayType.java"), expected);
258 }
259
260 @Test
261 public void testAtclauseOrderLotsOfRecords1() throws Exception {
262 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
263
264 verifyWithInlineConfigParser(
265 getNonCompilablePath("InputAtclauseOrderLotsOfRecords1.java"), expected);
266 }
267
268 @Test
269 public void testAtclauseOrderLotsOfRecords2() throws Exception {
270 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
271
272 verifyWithInlineConfigParser(
273 getNonCompilablePath("InputAtclauseOrderLotsOfRecords2.java"), expected);
274 }
275
276 @Test
277 public void testAtclauseOrderLotsOfRecords3() throws Exception {
278 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
279
280 verifyWithInlineConfigParser(
281 getNonCompilablePath("InputAtclauseOrderLotsOfRecords3.java"), expected);
282 }
283
284 @Test
285 public void testAtclauseOrderLotsOfRecords4() throws Exception {
286 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
287
288 verifyWithInlineConfigParser(
289 getNonCompilablePath("InputAtclauseOrderLotsOfRecords4.java"), expected);
290 }
291
292 @Test
293 public void testAtclause() throws Exception {
294 final String tagOrder = "[@author, @version, @param, @return, @throws, @exception, @see,"
295 + " @since, @serial, @serialField, @serialData, @deprecated]";
296 final String[] expected = {
297 "20: " + getCheckMessage(MSG_KEY, tagOrder),
298 "21: " + getCheckMessage(MSG_KEY, tagOrder),
299 "22: " + getCheckMessage(MSG_KEY, tagOrder),
300 "32: " + getCheckMessage(MSG_KEY, tagOrder),
301 "33: " + getCheckMessage(MSG_KEY, tagOrder),
302 "34: " + getCheckMessage(MSG_KEY, tagOrder),
303 "44: " + getCheckMessage(MSG_KEY, tagOrder),
304 "45: " + getCheckMessage(MSG_KEY, tagOrder),
305 "46: " + getCheckMessage(MSG_KEY, tagOrder),
306 "59: " + getCheckMessage(MSG_KEY, tagOrder),
307 "60: " + getCheckMessage(MSG_KEY, tagOrder),
308 "61: " + getCheckMessage(MSG_KEY, tagOrder),
309 "73: " + getCheckMessage(MSG_KEY, tagOrder),
310 "74: " + getCheckMessage(MSG_KEY, tagOrder),
311 "75: " + getCheckMessage(MSG_KEY, tagOrder),
312 "88: " + getCheckMessage(MSG_KEY, tagOrder),
313 "89: " + getCheckMessage(MSG_KEY, tagOrder),
314 "90: " + getCheckMessage(MSG_KEY, tagOrder),
315 "100: " + getCheckMessage(MSG_KEY, tagOrder),
316 "101: " + getCheckMessage(MSG_KEY, tagOrder),
317 "102: " + getCheckMessage(MSG_KEY, tagOrder),
318 };
319
320 verifyWithInlineConfigParser(
321 getPath("InputAtclauseOrderWithAnnotationsOutsideJavadoc.java"), expected);
322 }
323
324 @Test
325 public void testNewArrayDeclaratorStructure() throws Exception {
326 final String tagOrder = "[@author, @version, @param, @return, @throws, @exception, @see,"
327 + " @since, @serial, @serialField, @serialData, @deprecated]";
328
329 final String[] expected = {
330 "41: " + getCheckMessage(MSG_KEY, tagOrder),
331 "58: " + getCheckMessage(MSG_KEY, tagOrder),
332 "78: " + getCheckMessage(MSG_KEY, tagOrder),
333 "79: " + getCheckMessage(MSG_KEY, tagOrder),
334 "80: " + getCheckMessage(MSG_KEY, tagOrder),
335 };
336
337 verifyWithInlineConfigParser(
338 getPath("InputAtclauseOrderNewArrayDeclaratorStructure.java"), expected);
339 }
340
341 @Test
342 public void testTrim() throws Exception {
343 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
344 verifyWithInlineConfigParser(
345 getPath("InputAtclauseOrder1.java"),
346 expected);
347 }
348 }