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