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.AbstractJavadocCheck.MSG_KEY_UNCLOSED_HTML_TAG;
24 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.MSG_DUPLICATE_TAG;
25 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.MSG_EXPECTED_TAG;
26 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.MSG_INVALID_INHERIT_DOC;
27 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.MSG_RETURN_EXPECTED;
28 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.MSG_UNUSED_TAG;
29 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.MSG_UNUSED_TAG_GENERAL;
30
31 import org.junit.jupiter.api.Test;
32
33 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
34 import com.puppycrawl.tools.checkstyle.api.JavadocCommentsTokenTypes;
35 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
36 import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
37 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
38
39 public class JavadocMethodCheckTest extends AbstractModuleTestSupport {
40
41 @Override
42 public String getPackageLocation() {
43 return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod";
44 }
45
46 @Test
47 public void testGetAcceptableTokens() {
48 final JavadocMethodCheck javadocMethodCheck = new JavadocMethodCheck();
49
50 final int[] actual = javadocMethodCheck.getAcceptableTokens();
51 final int[] expected = {
52 TokenTypes.METHOD_DEF,
53 TokenTypes.CTOR_DEF,
54 TokenTypes.ANNOTATION_FIELD_DEF,
55 TokenTypes.COMPACT_CTOR_DEF,
56 };
57
58 assertWithMessage("Default acceptable tokens are invalid")
59 .that(actual)
60 .isEqualTo(expected);
61 }
62
63 @Test
64 public void extendAnnotationTest() throws Exception {
65 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
66 verifyWithInlineConfigParser(
67 getPath("InputJavadocMethodExtendAnnotation.java"), expected);
68 }
69
70 @Test
71 public void allowedAnnotationsTest() throws Exception {
72 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
73 verifyWithInlineConfigParser(
74 getPath("InputJavadocMethodAllowedAnnotations.java"), expected);
75 }
76
77 @Test
78 public void testThrowsDetectionOne() throws Exception {
79 final String[] expected = {
80 "26:19: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
81 "UnsupportedOperationException"),
82 "38:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
83 "UnsupportedOperationException"),
84 "42:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
85 "IllegalArgumentException"),
86 "56:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
87 "UnsupportedOperationException"),
88 "61:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
89 "IllegalArgumentException"),
90 "73:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
91 "UnsupportedOperationException"),
92 "77:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
93 "IllegalArgumentException"),
94 "89:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
95 "UnsupportedOperationException"),
96 "93:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
97 "IllegalArgumentException"),
98 };
99 verifyWithInlineConfigParser(
100 getPath("InputJavadocMethodThrowsDetectionOne.java"), expected);
101 }
102
103 @Test
104 public void testThrowsDetectionTwo() throws Exception {
105 final String[] expected = {
106 "27:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
107 "IllegalArgumentException"),
108 "42:31: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
109 "IllegalArgumentException"),
110 "55:19: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
111 "UnsupportedOperationException"),
112 "71:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
113 "RuntimeException"),
114 "85:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
115 "RuntimeException"),
116 };
117 verifyWithInlineConfigParser(
118 getPath("InputJavadocMethodThrowsDetectionTwo.java"), expected);
119 }
120
121 @Test
122 public void testThrowsNoIdentifier() throws Exception {
123 verifyWithInlineConfigParser(
124 getJavadocWithErrorPath("InputJavadocMethodThrowsDetectionTwo.java"),
125 CommonUtil.EMPTY_STRING_ARRAY);
126 }
127
128 @Test
129 public void testExtraThrowsOne() throws Exception {
130 final String[] expected = {
131 "51:56: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalStateException"),
132 "67:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
133 "80:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
134 "93:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
135 "java.lang.IllegalArgumentException"),
136 };
137 verifyWithInlineConfigParser(
138 getPath("InputJavadocMethodExtraThrowsOne.java"), expected);
139 }
140
141 @Test
142 public void testExtraThrowsTwo() throws Exception {
143 final String[] expected = {
144 "46:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "FileNotFoundException"),
145 };
146 verifyWithInlineConfigParser(
147 getPath("InputJavadocMethodExtraThrowsTwo.java"), expected);
148 }
149
150 @Test
151 public void testIgnoreThrowsOne() throws Exception {
152 final String[] expected = {
153 "35:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
154 "38:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalStateException"),
155 "55:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
156 };
157 verifyWithInlineConfigParser(
158 getPath("InputJavadocMethodIgnoreThrowsOne.java"), expected);
159 }
160
161 @Test
162 public void testIgnoreThrowsTwo() throws Exception {
163 final String[] expected = {
164 "52:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
165 "109:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
166 };
167 verifyWithInlineConfigParser(
168 getPath("InputJavadocMethodIgnoreThrowsTwo.java"), expected);
169 }
170
171 @Test
172 public void testTagsOne() throws Exception {
173 final String[] expected = {
174 "50:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
175 "89:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
176 };
177 verifyWithInlineConfigParser(
178 getPath("InputJavadocMethodTags.java"), expected);
179 }
180
181 @Test
182 public void testTagsTwo() throws Exception {
183 final String[] expected = {
184 "29:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unused"),
185 "36: " + getCheckMessage(MSG_RETURN_EXPECTED),
186 "45: " + getCheckMessage(MSG_RETURN_EXPECTED),
187 "52:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
188 "60:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
189 "66:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
190 "66:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "NullPointerException"),
191 "71:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
192 "79:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
193 "83:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "WrongParam"),
194 "85:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
195 "85:33: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aTwo"),
196 "91:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "Unneeded"),
197 "92: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
198 "101:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
199
200 };
201 verifyWithInlineConfigParser(
202 getPath("InputJavadocMethodTags1One.java"), expected);
203 }
204
205 @Test
206 public void testTagsThree() throws Exception {
207 final String[] expected = {
208 "67:28: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IOException"),
209 "73:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "aParam"),
210 "116: " + getCheckMessage(MSG_RETURN_EXPECTED),
211 "116:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aParam"),
212 };
213 verifyWithInlineConfigParser(
214 getPath("InputJavadocMethodTags1Three.java"), expected);
215 }
216
217 @Test
218 public void testStrictJavadocOne() throws Exception {
219 final String[] expected = {
220 "78:29: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aA"),
221 "83:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aA"),
222 "88:41: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aA"),
223 "93:37: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aA"),
224 };
225 verifyWithInlineConfigParser(
226 getPath("InputJavadocMethodPublicOnlyOne.java"), expected);
227 }
228
229 @Test
230 public void testStrictJavadocTwo() throws Exception {
231 final String[] expected = {
232 "22:32: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aA"),
233 };
234 verifyWithInlineConfigParser(
235 getPath("InputJavadocMethodPublicOnlyTwo.java"), expected);
236 }
237
238 @Test
239 public void testNoJavadocOne() throws Exception {
240 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
241 verifyWithInlineConfigParser(
242 getPath("InputJavadocMethodPublicOnly1One.java"), expected);
243 }
244
245 @Test
246 public void testNoJavadocTwo() throws Exception {
247 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
248 verifyWithInlineConfigParser(
249 getPath("InputJavadocMethodPublicOnly1Two.java"), expected);
250 }
251
252
253 @Test
254 public void testRelaxedJavadoc() throws Exception {
255 final String[] expected = {
256 "48:41: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aA"),
257 "53:37: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aA"),
258 };
259 verifyWithInlineConfigParser(
260 getPath("InputJavadocMethodProtectedScopeJavadocTwo.java"), expected);
261 }
262
263 @Test
264 public void testScopeInnerInterfacesPublic() throws Exception {
265 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
266 verifyWithInlineConfigParser(
267 getPath("InputJavadocMethodScopeInnerInterfaces.java"), expected);
268 }
269
270 @Test
271 public void testScopeAnonInnerPrivate() throws Exception {
272 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
273 verifyWithInlineConfigParser(
274 getPath("InputJavadocMethodScopeAnonInner.java"), expected);
275 }
276
277 @Test
278 public void testScopes() throws Exception {
279 final String[] expected = {
280 "29: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
281 "32: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
282 "35: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
283 "38: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
284 };
285 verifyWithInlineConfigParser(
286 getPath("InputJavadocMethodNoJavadocDefault.java"), expected);
287 }
288
289 @Test
290 public void testScopes2() throws Exception {
291 final String[] expected = {
292 "29: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
293 "32: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
294 };
295 verifyWithInlineConfigParser(
296 getPath("InputJavadocMethodNoJavadocProtectedScope.java"), expected);
297 }
298
299 @Test
300 public void testExcludeScope() throws Exception {
301 final String[] expected = {
302 "29: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
303 "34: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
304 "37: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
305 };
306 verifyWithInlineConfigParser(
307 getPath("InputJavadocMethodNoJavadocOnlyPrivateScope.java"), expected);
308 }
309
310 @Test
311 public void testAllowMissingJavadocTags() throws Exception {
312 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
313 verifyWithInlineConfigParser(
314 getPath("InputJavadocMethodMissingJavadocNoMissingTags.java"),
315 expected);
316 }
317
318 @Test
319 public void testSurroundingAccessModifier() throws Exception {
320 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
321 verifyWithInlineConfigParser(
322 getPath("InputJavadocMethodSurroundingAccessModifier.java"), expected);
323 }
324
325 @Test
326 public void testDoAllowMissingJavadocTagsByDefault() throws Exception {
327 final String[] expected = {
328 "24: " + getCheckMessage(MSG_RETURN_EXPECTED),
329 "35:26: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "number"),
330 "66: " + getCheckMessage(MSG_RETURN_EXPECTED),
331 "76: " + getCheckMessage(MSG_RETURN_EXPECTED),
332 "88: " + getCheckMessage(MSG_RETURN_EXPECTED),
333 };
334 verifyWithInlineConfigParser(
335 getPath("InputJavadocMethodMissingJavadocTagsDefault.java"), expected);
336 }
337
338 @Test
339 public void testSetterGetter() throws Exception {
340 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
341 verifyWithInlineConfigParser(
342 getPath("InputJavadocMethodSetterGetter.java"), expected);
343 }
344
345 @Test
346 public void testTypeParamsTags() throws Exception {
347 final String[] expected = {
348 "39:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "<BB>"),
349 "41:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "<Z>"),
350 };
351 verifyWithInlineConfigParser(
352 getPath("InputJavadocMethodTypeParamsTags.java"), expected);
353 }
354
355 @Test
356 public void testAllowUndocumentedParamsTags() throws Exception {
357 final String[] expected = {
358 "34:6: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unexpectedParam"),
359 "35:6: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unexpectedParam2"),
360 "37:13: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unexpectedParam3"),
361 "38:6: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unexpectedParam4"),
362 "67:7: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "t"),
363 "69:34: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "w"),
364 "79:7: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "x"),
365 "80:34: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "y"),
366 };
367 verifyWithInlineConfigParser(
368 getPath("InputJavadocMethodParamsTags.java"), expected);
369 }
370
371 @Test
372 public void test11684081() throws Exception {
373 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
374 verifyWithInlineConfigParser(
375 getPath("InputJavadocMethod_01.java"), expected);
376 }
377
378 @Test
379 public void test11684082() throws Exception {
380 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
381 verifyWithInlineConfigParser(
382 getPath("InputJavadocMethod_02.java"), expected);
383 }
384
385 @Test
386 public void test11684083() throws Exception {
387 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
388 verifyWithInlineConfigParser(
389 getPath("InputJavadocMethod_03.java"), expected);
390 }
391
392 @Test
393 public void testGenerics() throws Exception {
394 final String[] expected = {
395 "30:34: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "RE"),
396 "47:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "<NPE>"),
397 "58:38: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "RuntimeException"),
398 "59:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "java.lang.RuntimeException"),
399 "90:20: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "value"),
400 "90:6: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "<T>"),
401 "90: " + getCheckMessage(MSG_RETURN_EXPECTED),
402 };
403 verifyWithInlineConfigParser(
404 getPath("InputJavadocMethodGenerics.java"), expected);
405 }
406
407 @Test
408 public void test1379666() throws Exception {
409 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
410 verifyWithInlineConfigParser(
411 getPath("InputJavadocMethod_1379666.java"), expected);
412 }
413
414 @Test
415 public void testInheritDoc() throws Exception {
416 final String[] expected = {
417 "19:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
418 "24:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
419 "44:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
420 "49:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
421 "55:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
422 "60:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
423 };
424 verifyWithInlineConfigParser(
425 getPath("InputJavadocMethodInheritDoc.java"), expected);
426 }
427
428 @Test
429 public void testAllowToSkipOverridden() throws Exception {
430 final String[] expected = {
431 "20:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "BAD"),
432 "31:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "BAD"),
433 };
434 verifyWithInlineConfigParser(
435 getPath("InputJavadocMethodsNotSkipWritten.java"), expected);
436 }
437
438 @Test
439 public void testJava8ReceiverParameter() throws Exception {
440 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
441 verifyWithInlineConfigParser(
442 getPath("InputJavadocMethodReceiverParameter.java"), expected);
443 }
444
445 @Test
446 public void testJavadocInMethod() throws Exception {
447 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
448 verifyWithInlineConfigParser(
449 getPath("InputJavadocMethodJavadocInMethod.java"), expected);
450 }
451
452 @Test
453 public void testConstructor() throws Exception {
454 final String[] expected = {
455 "22:49: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "p1"),
456 "25:50: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "p1"),
457 };
458 verifyWithInlineConfigParser(
459 getPath("InputJavadocMethodConstructor.java"), expected);
460 }
461
462 @Test
463 public void testJavadocMethodRecordsAndCompactCtors() throws Exception {
464 final String[] expected = {
465 "30:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
466 "44:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws",
467 "java.lang.IllegalArgumentException"),
468 "57:12: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "properties"),
469 "64:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
470 "76:12: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "properties"),
471 "79:9: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "myString"),
472 "83:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
473 "95:12: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "properties"),
474 "98:35: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "myInt"),
475 "103:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IllegalArgumentException"),
476 };
477 verifyWithInlineConfigParser(
478 getPath("InputJavadocMethodRecordsAndCompactCtors.java"), expected);
479 }
480
481 @Test
482 public void testGetRequiredTokens() {
483 final int[] expected = CommonUtil.EMPTY_INT_ARRAY;
484 final JavadocMethodCheck check = new JavadocMethodCheck();
485 final int[] actual = check.getRequiredTokens();
486 assertWithMessage("Required tokens differ from expected")
487 .that(actual)
488 .isEqualTo(expected);
489 }
490
491 @Test
492 public void testWithoutLogErrors() throws Exception {
493 verifyWithInlineConfigParser(
494 getPath("InputJavadocMethodLoadErrors.java"),
495 CommonUtil.EMPTY_STRING_ARRAY);
496 }
497
498 @Test
499 public void testCompilationUnit() throws Exception {
500 verifyWithInlineConfigParser(
501 getPath("InputJavadocMethodCompilationUnit.java"),
502 CommonUtil.EMPTY_STRING_ARRAY);
503 }
504
505 @Test
506 public void testDefaultAccessModifier() throws Exception {
507 final String[] expected = {
508 "22:32: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "a"),
509 "27:43: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "b"),
510 };
511 verifyWithInlineConfigParser(
512 getPath("InputJavadocMethodDefaultAccessModifier.java"), expected);
513 }
514
515 @Test
516 public void testAccessModifierEnum() throws Exception {
517 final String[] expected = {
518 "28:17: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "i"),
519 };
520 verifyWithInlineConfigParser(
521 getPath("InputJavadocMethodEnum.java"), expected);
522 }
523
524 @Test
525 public void testCustomMessages() throws Exception {
526 final String msgReturnExpectedCustom =
527 "@return tag should be present and have description :)";
528 final String msgUnusedTagCustom = "Unused @param tag for 'unused' :)";
529 final String msgExpectedTagCustom = "Expected @param tag for 'a' :)";
530 final String[] expected = {
531 "22: " + msgReturnExpectedCustom,
532 "26:9: " + msgUnusedTagCustom,
533 "33:22: " + msgExpectedTagCustom,
534 };
535
536 verifyWithInlineConfigParser(
537 getPath("InputJavadocMethodCustomMessage.java"), expected);
538 }
539
540 @Test
541 public void test1() throws Exception {
542 final String[] expected = {
543 "30: " + getCheckMessage(MSG_RETURN_EXPECTED),
544 };
545 verifyWithInlineConfigParser(
546 getPath("InputJavadocMethod1.java"), expected);
547 }
548
549 @Test
550 public void test3() throws Exception {
551 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
552 verifyWithInlineConfigParser(
553 getPath("InputJavadocMethod3.java"), expected);
554 }
555
556 @Test
557 public void testJavadocMethodRecords() throws Exception {
558 final String[] expected = {};
559 verifyWithInlineConfigParser(
560 getPath("InputJavadocMethodRecords.java"), expected);
561 }
562
563 @Test
564 public void testJavadocMethodRecords2() throws Exception {
565 final String[] expected = {
566 "39:12: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "lastName"),
567 "54:12: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "lastName"),
568 };
569 verifyWithInlineConfigParser(
570 getPath("InputJavadocMethodRecords2.java"), expected);
571 }
572
573 @Test
574 public void testJavadocMethodRecords3() throws Exception {
575 final String[] expected = {};
576 verifyWithInlineConfigParser(
577 getPath("InputJavadocMethodRecords3.java"), expected);
578 }
579
580 @Test
581 public void testJavadocMethodAboveComments() throws Exception {
582 final String[] expected = {
583 "23:29: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
584 "31:30: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
585 "56:30: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
586 "66:32: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
587 "76:33: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
588 "85:33: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
589 "94:33: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
590 };
591 verifyWithInlineConfigParser(
592 getPath("InputJavadocMethodAboveComments.java"), expected);
593 }
594
595 @Test
596 public void testJavadocMethodAllowInlineReturn() throws Exception {
597 final String[] expected = {
598 "32: " + getCheckMessage(MSG_RETURN_EXPECTED),
599 "39: " + getCheckMessage(MSG_RETURN_EXPECTED),
600 };
601 verifyWithInlineConfigParser(
602 getPath("InputJavadocMethodAllowInlineReturn.java"), expected);
603 }
604
605 @Test
606 public void testJavadocMethodDoNotAllowInlineReturn() throws Exception {
607 final String[] expected = {
608 "21: " + getCheckMessage(MSG_RETURN_EXPECTED),
609 "33: " + getCheckMessage(MSG_RETURN_EXPECTED),
610 "40: " + getCheckMessage(MSG_RETURN_EXPECTED),
611 };
612 verifyWithInlineConfigParser(
613 getPath("InputJavadocMethodDoNotAllowInlineReturn.java"), expected);
614 }
615
616 @Test
617 public void testJavadocMethodBlockComment() throws Exception {
618 final String[] expected = {
619 "29: " + getCheckMessage(MSG_RETURN_EXPECTED),
620 };
621 verifyWithInlineConfigParser(
622 getPath("InputJavadocMethodBlockComment.java"), expected);
623 }
624
625 @Test
626 public void testJavadocMethodHtml() throws Exception {
627 final String[] expected = {
628 "20: " + getCheckMessage(MSG_KEY_UNCLOSED_HTML_TAG, "p"),
629 };
630 verifyWithInlineConfigParser(
631 getPath("InputJavadocMethodHtml.java"), expected);
632
633 }
634
635 @Test
636 public void testJavadocMethodDuplicateThrows() throws Exception {
637 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
638 verifyWithInlineConfigParser(
639 getPath("InputJavadocMethodDuplicateThrows.java"), expected);
640 }
641
642 @Test
643 public void testJavadocMethodDuplicateParam() throws Exception {
644 final String[] expected = {
645 "21:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@param"),
646 "30:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@param"),
647 "38:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@param"),
648 "47:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "extra"),
649 "48:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@param"),
650 "57:12: " + getCheckMessage(MSG_DUPLICATE_TAG, "@param"),
651 };
652 verifyWithInlineConfigParser(
653 getPath("InputJavadocMethodDuplicateParam.java"), expected);
654 }
655
656
657
658
659
660
661
662 @Test
663 public void testImproperJavadocToken() {
664 final JavadocMethodCheck check = new JavadocMethodCheck();
665
666 final JavadocNodeImpl ast = new JavadocNodeImpl();
667 ast.setType(JavadocCommentsTokenTypes.EQUALS);
668 ast.setText("EQUALS");
669
670 final IllegalArgumentException exc = TestUtil.getExpectedThrowable(
671 IllegalArgumentException.class,
672 () -> check.visitJavadocToken(ast));
673
674 assertWithMessage("Message must include token name")
675 .that(exc.getMessage())
676 .contains("EQUALS");
677 }
678
679 }