View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 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.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.MSG_CLASS_INFO;
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_JAVADOC_MISSING;
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  import static org.junit.Assert.assertArrayEquals;
31  
32  import org.junit.Test;
33  
34  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
35  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
36  import com.puppycrawl.tools.checkstyle.api.Scope;
37  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
38  import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
39  
40  public class JavadocMethodCheckTest extends AbstractModuleTestSupport {
41      @Override
42      protected 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.PACKAGE_DEF,
53              TokenTypes.IMPORT,
54              TokenTypes.CLASS_DEF,
55              TokenTypes.ENUM_DEF,
56              TokenTypes.INTERFACE_DEF,
57              TokenTypes.METHOD_DEF,
58              TokenTypes.CTOR_DEF,
59              TokenTypes.ANNOTATION_FIELD_DEF,
60          };
61  
62          assertArrayEquals("Default acceptable tokens are invalid", expected, actual);
63      }
64  
65      @Test
66      public void testLogLoadErrors() throws Exception {
67          final DefaultConfiguration config = createModuleConfig(JavadocMethodCheck.class);
68          config.addAttribute("logLoadErrors", "true");
69          config.addAttribute("allowUndeclaredRTE", "true");
70          final String[] expected = {
71              "7:8: " + getCheckMessage(MSG_CLASS_INFO, "@throws", "InvalidExceptionName"),
72          };
73          verify(config, getPath("InputJavadocMethodLoadErrors.java"), expected);
74      }
75  
76      @Test
77      public void extendAnnotationTest() throws Exception {
78          final DefaultConfiguration config = createModuleConfig(JavadocMethodCheck.class);
79          config.addAttribute("allowedAnnotations", "MyAnnotation, Override");
80          config.addAttribute("minLineCount", "2");
81          final String[] expected = {
82              "44:1: " + getCheckMessage(MSG_JAVADOC_MISSING),
83          };
84          verify(config, getPath("InputJavadocMethodExtendAnnotation.java"), expected);
85      }
86  
87      @Test
88      public void newTest() throws Exception {
89          final DefaultConfiguration config = createModuleConfig(JavadocMethodCheck.class);
90          config.addAttribute("allowedAnnotations", "MyAnnotation, Override");
91          config.addAttribute("minLineCount", "2");
92          final String[] expected = {
93              "57:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
94          };
95          verify(config, getPath("InputJavadocMethodSmallMethods.java"), expected);
96      }
97  
98      @Test
99      public void allowedAnnotationsTest() throws Exception {
100 
101         final DefaultConfiguration config = createModuleConfig(JavadocMethodCheck.class);
102         config.addAttribute("allowedAnnotations", "Override,ThisIsOk, \t\n\t ThisIsOkToo");
103         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
104         verify(config, getPath("InputJavadocMethodAllowedAnnotations.java"), expected);
105     }
106 
107     @Test
108     public void testTags() throws Exception {
109         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
110         checkConfig.addAttribute("validateThrows", "true");
111         final String[] expected = {
112             "14:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
113             "18:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unused"),
114             "24: " + getCheckMessage(MSG_RETURN_EXPECTED),
115             "33: " + getCheckMessage(MSG_RETURN_EXPECTED),
116             "40:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
117             "49:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
118             "53:9: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "WrongException"),
119             "55:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
120             "55:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "NullPointerException"),
121             "60:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
122             "68:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
123             "72:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "WrongParam"),
124             "73:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
125             "73:33: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aTwo"),
126             "78:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "Unneeded"),
127             "79: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
128             "87:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
129             "109:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
130             "109:55: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aFour"),
131             "109:66: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aFive"),
132             "178:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "ThreadDeath"),
133             "179:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "ArrayStoreException"),
134             "236:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "java.io.FileNotFoundException"),
135             "254:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "java.io.FileNotFoundException"),
136             "256:28: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IOException"),
137             "262:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "aParam"),
138             "305: " + getCheckMessage(MSG_RETURN_EXPECTED),
139             "305:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aParam"),
140             "328:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
141             "337:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
142         };
143 
144         verify(checkConfig, getPath("InputJavadocMethodTags.java"), expected);
145     }
146 
147     @Test
148     public void testTagsWithResolver() throws Exception {
149         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
150         checkConfig.addAttribute("allowUndeclaredRTE", "true");
151         checkConfig.addAttribute("validateThrows", "true");
152         final String[] expected = {
153             "14:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
154             "18:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unused"),
155             "24: " + getCheckMessage(MSG_RETURN_EXPECTED),
156             "33: " + getCheckMessage(MSG_RETURN_EXPECTED),
157             "40:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
158             "49:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
159             "55:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
160             "55:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "NullPointerException"),
161             "60:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
162             "68:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
163             "72:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "WrongParam"),
164             "73:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
165             "73:33: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aTwo"),
166             "78:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "Unneeded"),
167             "79: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
168             "87:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
169             "109:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
170             "109:55: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aFour"),
171             "109:66: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aFive"),
172             "236:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "java.io.FileNotFoundException"),
173             "254:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "java.io.FileNotFoundException"),
174             "256:28: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IOException"),
175             "262:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "aParam"),
176             "305: " + getCheckMessage(MSG_RETURN_EXPECTED),
177             "305:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aParam"),
178             "328:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
179             "337:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
180         };
181         verify(checkConfig, getPath("InputJavadocMethodTags.java"), expected);
182     }
183 
184     @Test
185     public void testStrictJavadoc() throws Exception {
186         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
187         final String[] expected = {
188             "12:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
189             "18:13: " + getCheckMessage(MSG_JAVADOC_MISSING),
190             "25:13: " + getCheckMessage(MSG_JAVADOC_MISSING),
191             "38:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
192             "49:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
193             "54:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
194             "59:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
195             "64:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
196             "69:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
197             "74:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
198             "79:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
199             "84:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
200             "94:32: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aA"),
201         };
202         verify(checkConfig, getPath("InputJavadocMethodPublicOnly.java"), expected);
203     }
204 
205     @Test
206     public void testNoJavadoc() throws Exception {
207         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
208         checkConfig.addAttribute("scope", Scope.NOTHING.getName());
209         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
210         verify(checkConfig, getPath("InputJavadocMethodPublicOnly.java"), expected);
211     }
212 
213     // pre 1.4 relaxed mode is roughly equivalent with check=protected
214     @Test
215     public void testRelaxedJavadoc() throws Exception {
216         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
217         checkConfig.addAttribute("scope", Scope.PROTECTED.getName());
218         final String[] expected = {
219             "59:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
220             "64:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
221             "79:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
222             "84:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
223         };
224         verify(checkConfig, getPath("InputJavadocMethodPublicOnly.java"), expected);
225     }
226 
227     @Test
228     public void testScopeInnerInterfacesPublic() throws Exception {
229         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
230         checkConfig.addAttribute("scope", Scope.PUBLIC.getName());
231         final String[] expected = {
232             "43:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
233             "44:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
234         };
235         verify(checkConfig, getPath("InputJavadocMethodScopeInnerInterfaces.java"), expected);
236     }
237 
238     @Test
239     public void testScopeAnonInnerPrivate() throws Exception {
240         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
241         checkConfig.addAttribute("scope", Scope.PRIVATE.getName());
242         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
243         verify(checkConfig, getPath("InputJavadocMethodScopeAnonInner.java"), expected);
244     }
245 
246     @Test
247     public void testScopeAnonInnerAnonInner() throws Exception {
248         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
249         checkConfig.addAttribute("scope", Scope.ANONINNER.getName());
250         final String[] expected = {
251             "26:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
252             "39:17: " + getCheckMessage(MSG_JAVADOC_MISSING),
253             "53:17: " + getCheckMessage(MSG_JAVADOC_MISSING), };
254         verify(checkConfig, getPath("InputJavadocMethodScopeAnonInner.java"), expected);
255     }
256 
257     @Test
258     public void testScopeAnonInnerWithResolver() throws Exception {
259         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
260         checkConfig.addAttribute("allowUndeclaredRTE", "true");
261         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
262         verify(checkConfig, getPath("InputJavadocMethodScopeAnonInner.java"), expected);
263     }
264 
265     @Test
266     public void testTagsWithSubclassesAllowed() throws Exception {
267         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
268         checkConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
269         checkConfig.addAttribute("validateThrows", "true");
270         final String[] expected = {
271             "14:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
272             "18:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "unused"),
273             "24: " + getCheckMessage(MSG_RETURN_EXPECTED),
274             "33: " + getCheckMessage(MSG_RETURN_EXPECTED),
275             "40:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
276             "49:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
277             "55:16: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "Exception"),
278             "55:27: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "NullPointerException"),
279             "60:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
280             "68:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
281             "72:9: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "WrongParam"),
282             "73:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
283             "73:33: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aTwo"),
284             "78:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "Unneeded"),
285             "79: " + getCheckMessage(MSG_UNUSED_TAG_GENERAL),
286             "87:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
287             "109:23: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aOne"),
288             "109:55: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aFour"),
289             "109:66: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aFive"),
290             "178:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "ThreadDeath"),
291             "179:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "ArrayStoreException"),
292             "256:28: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "IOException"),
293             "262:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "aParam"),
294             "305: " + getCheckMessage(MSG_RETURN_EXPECTED),
295             "305:22: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "aParam"),
296             "328:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
297             "337:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
298         };
299         verify(checkConfig, getPath("InputJavadocMethodTags.java"), expected);
300     }
301 
302     @Test
303     public void testScopes() throws Exception {
304         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
305         final String[] expected = {
306             "10:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
307             "11:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
308             "12:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
309             "13:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
310             "21:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
311             "22:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
312             "23:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
313             "24:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
314             "33:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
315             "34:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
316             "35:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
317             "36:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
318             "45:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
319             "46:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
320             "47:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
321             "48:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
322             "58:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
323             "59:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
324             "60:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
325             "61:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
326             "69:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
327             "70:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
328             "71:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
329             "72:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
330             "81:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
331             "82:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
332             "83:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
333             "84:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
334             "93:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
335             "94:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
336             "95:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
337             "96:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
338             "105:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
339             "106:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
340             "107:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
341             "108:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
342             "119:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
343         };
344         verify(checkConfig, getPath("InputJavadocMethodNoJavadoc.java"), expected);
345     }
346 
347     @Test
348     public void testScopes2() throws Exception {
349         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
350         checkConfig.addAttribute("scope", Scope.PROTECTED.getName());
351         final String[] expected = {
352             "10:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
353             "11:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
354             "21:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
355             "22:9: " + getCheckMessage(MSG_JAVADOC_MISSING), };
356         verify(checkConfig, getPath("InputJavadocMethodNoJavadoc.java"), expected);
357     }
358 
359     @Test
360     public void testExcludeScope() throws Exception {
361         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
362         checkConfig.addAttribute("scope", Scope.PRIVATE.getName());
363         checkConfig.addAttribute("excludeScope", Scope.PROTECTED.getName());
364         final String[] expected = {
365             "10:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
366             "12:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
367             "13:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
368             "33:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
369             "35:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
370             "36:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
371             "45:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
372             "47:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
373             "48:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
374             "58:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
375             "60:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
376             "61:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
377             "69:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
378             "71:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
379             "72:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
380             "81:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
381             "83:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
382             "84:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
383             "93:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
384             "95:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
385             "96:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
386             "105:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
387             "107:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
388             "108:9: " + getCheckMessage(MSG_JAVADOC_MISSING),
389             "119:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
390         };
391         verify(checkConfig, getPath("InputJavadocMethodNoJavadoc.java"), expected);
392     }
393 
394     @Test
395     public void testAllowMissingJavadoc() throws Exception {
396         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
397         checkConfig.addAttribute("allowMissingJavadoc", "true");
398         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
399         verify(checkConfig, getPath("InputJavadocMethodNoJavadoc.java"), expected);
400     }
401 
402     @Test
403     public void testAllowMissingJavadocTags() throws Exception {
404         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
405         checkConfig.addAttribute("allowMissingParamTags", "true");
406         checkConfig.addAttribute("allowMissingThrowsTags", "true");
407         checkConfig.addAttribute("allowMissingReturnTag", "true");
408         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
409         verify(checkConfig, getPath("InputJavadocMethodMissingJavadocTags.java"), expected);
410     }
411 
412     @Test
413     public void testDoAllowMissingJavadocTagsByDefault() throws Exception {
414         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
415         final String[] expected = {
416             "10: " + getCheckMessage(MSG_RETURN_EXPECTED),
417             "20:26: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "number"),
418             "30:42: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "ThreadDeath"),
419             "51: " + getCheckMessage(MSG_RETURN_EXPECTED),
420             "61: " + getCheckMessage(MSG_RETURN_EXPECTED),
421             "72: " + getCheckMessage(MSG_RETURN_EXPECTED),
422         };
423         verify(checkConfig, getPath("InputJavadocMethodMissingJavadocTags.java"), expected);
424     }
425 
426     @Test
427     public void testSetterGetterOff() throws Exception {
428         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
429         final String[] expected = {
430             "7:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
431             "12:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
432             "17:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
433             "22:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
434             "28:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
435             "32:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
436             "37:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
437             "43:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
438             "48:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
439             "53:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
440             "55:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
441             "59:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
442             "63:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
443             "67:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
444             "69:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
445             "74:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
446             "76:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
447         };
448         verify(checkConfig, getPath("InputJavadocMethodSetterGetter.java"), expected);
449     }
450 
451     @Test
452     public void testSetterGetterOn() throws Exception {
453         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
454         checkConfig.addAttribute("allowMissingPropertyJavadoc", "true");
455         final String[] expected = {
456             "17:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
457             "22:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
458             "28:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
459             "32:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
460             "37:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
461             "43:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
462             "53:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
463             "55:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
464             "59:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
465             "63:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
466             "67:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
467             "69:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
468             "74:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
469             "76:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
470         };
471         verify(checkConfig, getPath("InputJavadocMethodSetterGetter.java"), expected);
472     }
473 
474     @Test
475     public void testTypeParamsTags() throws Exception {
476         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
477         final String[] expected = {
478             "26:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "<BB>"),
479             "28:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "<Z>"),
480             "53:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "<Z"),
481             "55:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "<Z>"),
482         };
483         verify(checkConfig, getPath("InputJavadocMethodTypeParamsTags.java"), expected);
484     }
485 
486     @Test
487     public void test11684081() throws Exception {
488         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
489         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
490         verify(checkConfig, getPath("InputJavadocMethod_01.java"), expected);
491     }
492 
493     @Test
494     public void test11684082() throws Exception {
495         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
496         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
497         verify(checkConfig, getPath("InputJavadocMethod_02.java"), expected);
498     }
499 
500     @Test
501     public void test11684083() throws Exception {
502         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
503         checkConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
504         checkConfig.addAttribute("allowUndeclaredRTE", "true");
505         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
506         verify(checkConfig, getPath("InputJavadocMethod_03.java"), expected);
507     }
508 
509     @Test
510     public void testGenerics1() throws Exception {
511         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
512         checkConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
513         checkConfig.addAttribute("allowUndeclaredRTE", "true");
514         checkConfig.addAttribute("validateThrows", "true");
515         final String[] expected = {
516             "17:34: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "RE"),
517             "33:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "<NPE>"),
518             "40:12: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "E"),
519             "43:38: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "RuntimeException"),
520             "44:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "java.lang.RuntimeException"),
521         };
522         verify(checkConfig, getPath("InputJavadocMethodGenerics.java"), expected);
523     }
524 
525     @Test
526     public void testGenerics2() throws Exception {
527         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
528         checkConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
529         checkConfig.addAttribute("validateThrows", "true");
530         final String[] expected = {
531             "17:34: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "RE"),
532             "33:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "<NPE>"),
533             "40:12: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "E"),
534             "43:38: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "RuntimeException"),
535             "44:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "java.lang.RuntimeException"),
536         };
537         verify(checkConfig, getPath("InputJavadocMethodGenerics.java"), expected);
538     }
539 
540     @Test
541     public void testGenerics3() throws Exception {
542         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
543         checkConfig.addAttribute("validateThrows", "true");
544         final String[] expected = {
545             "8:8: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "RE"),
546             "17:34: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "RE"),
547             "33:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "<NPE>"),
548             "40:12: " + getCheckMessage(MSG_UNUSED_TAG, "@throws", "E"),
549             "43:38: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "RuntimeException"),
550             "44:13: " + getCheckMessage(MSG_EXPECTED_TAG, "@throws", "java.lang.RuntimeException"),
551         };
552         verify(checkConfig, getPath("InputJavadocMethodGenerics.java"), expected);
553     }
554 
555     @Test
556     public void test1379666() throws Exception {
557         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
558         checkConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
559         checkConfig.addAttribute("allowUndeclaredRTE", "true");
560         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
561         verify(checkConfig, getPath("InputJavadocMethod_1379666.java"), expected);
562     }
563 
564     @Test
565     public void testInheritDoc() throws Exception {
566         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
567         final String[] expected = {
568             "6:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
569             "11:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
570             "31:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
571             "36:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
572             "41:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
573             "46:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
574         };
575         verify(checkConfig, getPath("InputJavadocMethodInheritDoc.java"), expected);
576     }
577 
578     @Test
579     public void testSkipCertainMethods() throws Exception {
580         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
581         checkConfig.addAttribute("ignoreMethodNamesRegex", "^foo.*$");
582         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
583         verify(checkConfig, getPath("InputJavadocMethodIgnoreNameRegex.java"), expected);
584     }
585 
586     @Test
587     public void testNotSkipAnythingWhenSkipRegexDoesNotMatch() throws Exception {
588         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
589         checkConfig.addAttribute("ignoreMethodNamesRegex", "regexThatDoesNotMatch");
590         final String[] expected = {
591             "5:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
592             "9:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
593             "13:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
594         };
595         verify(checkConfig, getPath("InputJavadocMethodIgnoreNameRegex.java"), expected);
596     }
597 
598     @Test
599     public void testMethodsNotSkipWrittenJavadocs() throws Exception {
600         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
601         checkConfig.addAttribute("allowedAnnotations", "MyAnnotation");
602         final String[] expected = {
603             "7:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "BAD"),
604             "17:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "BAD"),
605         };
606         verify(checkConfig, getPath("InputJavadocMethodsNotSkipWritten.java"), expected);
607     }
608 
609     @Test
610     public void testAllowToSkipOverridden() throws Exception {
611         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
612         checkConfig.addAttribute("allowedAnnotations", "MyAnnotation");
613         final String[] expected = {
614             "7:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "BAD"),
615             "17:8: " + getCheckMessage(MSG_UNUSED_TAG, "@param", "BAD"),
616         };
617         verify(checkConfig, getPath("InputJavadocMethodsNotSkipWritten.java"), expected);
618     }
619 
620     @Test
621     public void testJava8ReceiverParameter() throws Exception {
622         final DefaultConfiguration checkConfig = createModuleConfig(JavadocMethodCheck.class);
623         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
624         verify(checkConfig, getPath("InputJavadocMethodReceiverParameter.java"), expected);
625     }
626 }