KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > javadoc > JavadocMethodCheckTest


1 package com.puppycrawl.tools.checkstyle.checks.javadoc;
2
3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
5 import com.puppycrawl.tools.checkstyle.api.Scope;
6
7 import java.io.File JavaDoc;
8
9 public class JavadocMethodCheckTest extends BaseCheckTestCase
10 {
11     private DefaultConfiguration mCheckConfig;
12
13     public void setUp()
14     {
15         mCheckConfig = createCheckConfig(JavadocMethodCheck.class);
16     }
17
18     public void testTags() throws Exception JavaDoc
19     {
20         final String JavaDoc[] expected = {
21             "14:5: Missing a Javadoc comment.",
22             "18:9: Unused @param tag for 'unused'.",
23             "24: Expected an @return tag.",
24             "33: Expected an @return tag.",
25             "40:16: Expected @throws tag for 'Exception'.",
26             "49:16: Expected @throws tag for 'Exception'.",
27             "53:9: Unused @throws tag for 'WrongException'.",
28             "55:16: Expected @throws tag for 'Exception'.",
29             "55:27: Expected @throws tag for 'NullPointerException'.",
30             "60:22: Expected @param tag for 'aOne'.",
31             "68:22: Expected @param tag for 'aOne'.",
32             "72:9: Unused @param tag for 'WrongParam'.",
33             "73:23: Expected @param tag for 'aOne'.",
34             "73:33: Expected @param tag for 'aTwo'.",
35             "78:8: Unused @param tag for 'Unneeded'.",
36             "79: Unused Javadoc tag.",
37             "87:8: Duplicate @return tag.",
38             "109:23: Expected @param tag for 'aOne'.",
39             "109:55: Expected @param tag for 'aFour'.",
40             "109:66: Expected @param tag for 'aFive'.",
41             "178:8: Unused @throws tag for 'ThreadDeath'.",
42             "179:8: Unused @throws tag for 'ArrayStoreException'.",
43             "236:8: Unused @throws tag for 'java.io.FileNotFoundException'.",
44             "254:8: Unused @throws tag for 'java.io.FileNotFoundException'.",
45             "256:28: Expected @throws tag for 'IOException'.",
46             "262:8: Unused @param tag for 'aParam'.",
47             "320:9: Missing a Javadoc comment.",
48             "329:5: Missing a Javadoc comment.",
49             "333: Unused Javadoc tag.",
50         };
51
52         verify(mCheckConfig, getPath("InputTags.java"), expected);
53     }
54
55     public void testTagsWithResolver() throws Exception JavaDoc
56     {
57         mCheckConfig.addAttribute("allowUndeclaredRTE", "true");
58         final String JavaDoc[] expected = {
59             "14:5: Missing a Javadoc comment.",
60             "18:9: Unused @param tag for 'unused'.",
61             "24: Expected an @return tag.",
62             "33: Expected an @return tag.",
63             "40:16: Expected @throws tag for 'Exception'.",
64             "49:16: Expected @throws tag for 'Exception'.",
65             "55:16: Expected @throws tag for 'Exception'.",
66             "55:27: Expected @throws tag for 'NullPointerException'.",
67             "60:22: Expected @param tag for 'aOne'.",
68             "68:22: Expected @param tag for 'aOne'.",
69             "72:9: Unused @param tag for 'WrongParam'.",
70             "73:23: Expected @param tag for 'aOne'.",
71             "73:33: Expected @param tag for 'aTwo'.",
72             "78:8: Unused @param tag for 'Unneeded'.",
73             "79: Unused Javadoc tag.",
74             "87:8: Duplicate @return tag.",
75             "109:23: Expected @param tag for 'aOne'.",
76             "109:55: Expected @param tag for 'aFour'.",
77             "109:66: Expected @param tag for 'aFive'.",
78             "236:8: Unused @throws tag for 'java.io.FileNotFoundException'.",
79             "254:8: Unused @throws tag for 'java.io.FileNotFoundException'.",
80             "256:28: Expected @throws tag for 'IOException'.",
81             "262:8: Unused @param tag for 'aParam'.",
82             "320:9: Missing a Javadoc comment.",
83             "329:5: Missing a Javadoc comment.",
84             "333: Unused Javadoc tag.", };
85         verify(mCheckConfig, getPath("InputTags.java"), expected);
86     }
87
88     public void testStrictJavadoc() throws Exception JavaDoc
89     {
90         final String JavaDoc[] expected = {
91             "12:9: Missing a Javadoc comment.",
92             "18:13: Missing a Javadoc comment.",
93             "25:13: Missing a Javadoc comment.",
94             "38:9: Missing a Javadoc comment.",
95             "49:5: Missing a Javadoc comment.",
96             "54:5: Missing a Javadoc comment.",
97             "59:5: Missing a Javadoc comment.",
98             "64:5: Missing a Javadoc comment.",
99             "69:5: Missing a Javadoc comment.",
100             "74:5: Missing a Javadoc comment.",
101             "79:5: Missing a Javadoc comment.",
102             "84:5: Missing a Javadoc comment.",
103             "94:32: Expected @param tag for 'aA'." };
104         verify(mCheckConfig, getPath("InputPublicOnly.java"), expected);
105     }
106
107     public void testNoJavadoc() throws Exception JavaDoc
108     {
109         mCheckConfig.addAttribute("scope", Scope.NOTHING.getName());
110         final String JavaDoc[] expected = {};
111         verify(mCheckConfig, getPath("InputPublicOnly.java"), expected);
112     }
113
114     // pre 1.4 relaxed mode is roughly equivalent with check=protected
115
public void testRelaxedJavadoc() throws Exception JavaDoc
116     {
117         mCheckConfig.addAttribute("scope", Scope.PROTECTED.getName());
118         final String JavaDoc[] expected = {
119             "59:5: Missing a Javadoc comment.",
120             "64:5: Missing a Javadoc comment.",
121             "79:5: Missing a Javadoc comment.",
122             "84:5: Missing a Javadoc comment." };
123         verify(mCheckConfig, getPath("InputPublicOnly.java"), expected);
124     }
125
126     public void testScopeInnerInterfacesPublic() throws Exception JavaDoc
127     {
128         mCheckConfig.addAttribute("scope", Scope.PUBLIC.getName());
129         final String JavaDoc[] expected = {
130             "43:9: Missing a Javadoc comment.",
131             "44:9: Missing a Javadoc comment." };
132         verify(mCheckConfig, getPath("InputScopeInnerInterfaces.java"), expected);
133     }
134
135     public void testScopeAnonInnerPrivate() throws Exception JavaDoc
136     {
137         mCheckConfig.addAttribute("scope", Scope.PRIVATE.getName());
138         final String JavaDoc[] expected = {};
139         verify(mCheckConfig, getPath("InputScopeAnonInner.java"), expected);
140     }
141
142     public void testScopeAnonInnerAnonInner() throws Exception JavaDoc
143     {
144         mCheckConfig.addAttribute("scope", Scope.ANONINNER.getName());
145         final String JavaDoc[] expected = {
146             "26:9: Missing a Javadoc comment.",
147             "39:17: Missing a Javadoc comment.",
148             "53:17: Missing a Javadoc comment.", };
149         verify(mCheckConfig, getPath("InputScopeAnonInner.java"), expected);
150     }
151
152     public void testScopeAnonInnerWithResolver() throws Exception JavaDoc
153     {
154         mCheckConfig.addAttribute("allowUndeclaredRTE", "true");
155         final String JavaDoc[] expected = {};
156         verify(mCheckConfig, getPath("InputScopeAnonInner.java"), expected);
157     }
158
159     public void testTagsWithSubclassesAllowed() throws Exception JavaDoc
160     {
161         mCheckConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
162         final String JavaDoc[] expected = {
163             "14:5: Missing a Javadoc comment.",
164             "18:9: Unused @param tag for 'unused'.",
165             "24: Expected an @return tag.",
166             "33: Expected an @return tag.",
167             "40:16: Expected @throws tag for 'Exception'.",
168             "49:16: Expected @throws tag for 'Exception'.",
169             "55:16: Expected @throws tag for 'Exception'.",
170             "55:27: Expected @throws tag for 'NullPointerException'.",
171             "60:22: Expected @param tag for 'aOne'.",
172             "68:22: Expected @param tag for 'aOne'.",
173             "72:9: Unused @param tag for 'WrongParam'.",
174             "73:23: Expected @param tag for 'aOne'.",
175             "73:33: Expected @param tag for 'aTwo'.",
176             "78:8: Unused @param tag for 'Unneeded'.",
177             "79: Unused Javadoc tag.",
178             "87:8: Duplicate @return tag.",
179             "109:23: Expected @param tag for 'aOne'.",
180             "109:55: Expected @param tag for 'aFour'.",
181             "109:66: Expected @param tag for 'aFive'.",
182             "178:8: Unused @throws tag for 'ThreadDeath'.",
183             "179:8: Unused @throws tag for 'ArrayStoreException'.",
184             "256:28: Expected @throws tag for 'IOException'.",
185             "262:8: Unused @param tag for 'aParam'.",
186             "320:9: Missing a Javadoc comment.",
187             "329:5: Missing a Javadoc comment.",
188             "333: Unused Javadoc tag.", };
189         verify(mCheckConfig, getPath("InputTags.java"), expected);
190     }
191
192     public void testScopes() throws Exception JavaDoc
193     {
194         final String JavaDoc[] expected = {
195             "8:5: Missing a Javadoc comment.",
196             "9:5: Missing a Javadoc comment.",
197             "10:5: Missing a Javadoc comment.",
198             "11:5: Missing a Javadoc comment.",
199             "19:9: Missing a Javadoc comment.",
200             "20:9: Missing a Javadoc comment.",
201             "21:9: Missing a Javadoc comment.",
202             "22:9: Missing a Javadoc comment.",
203             "31:9: Missing a Javadoc comment.",
204             "32:9: Missing a Javadoc comment.",
205             "33:9: Missing a Javadoc comment.",
206             "34:9: Missing a Javadoc comment.",
207             "43:9: Missing a Javadoc comment.",
208             "44:9: Missing a Javadoc comment.",
209             "45:9: Missing a Javadoc comment.",
210             "46:9: Missing a Javadoc comment.",
211             "56:5: Missing a Javadoc comment.",
212             "57:5: Missing a Javadoc comment.",
213             "58:5: Missing a Javadoc comment.",
214             "59:5: Missing a Javadoc comment.",
215             "67:9: Missing a Javadoc comment.",
216             "68:9: Missing a Javadoc comment.",
217             "69:9: Missing a Javadoc comment.",
218             "70:9: Missing a Javadoc comment.",
219             "79:9: Missing a Javadoc comment.",
220             "80:9: Missing a Javadoc comment.",
221             "81:9: Missing a Javadoc comment.",
222             "82:9: Missing a Javadoc comment.",
223             "91:9: Missing a Javadoc comment.",
224             "92:9: Missing a Javadoc comment.",
225             "93:9: Missing a Javadoc comment.",
226             "94:9: Missing a Javadoc comment.",
227             "103:9: Missing a Javadoc comment.",
228             "104:9: Missing a Javadoc comment.",
229             "105:9: Missing a Javadoc comment.",
230             "106:9: Missing a Javadoc comment.", };
231         verify(mCheckConfig, getPath("javadoc" + File.separator
232                                     + "InputNoJavadoc.java"), expected);
233     }
234
235     public void testScopes2() throws Exception JavaDoc
236     {
237         mCheckConfig.addAttribute("scope", Scope.PROTECTED.getName());
238         final String JavaDoc[] expected = {
239             "8:5: Missing a Javadoc comment.",
240             "9:5: Missing a Javadoc comment.",
241             "19:9: Missing a Javadoc comment.",
242             "20:9: Missing a Javadoc comment.", };
243         verify(mCheckConfig, getPath("javadoc" + File.separator
244                                     + "InputNoJavadoc.java"), expected);
245     }
246
247     public void testExcludeScope() throws Exception JavaDoc
248     {
249         mCheckConfig.addAttribute("scope", Scope.PRIVATE.getName());
250         mCheckConfig.addAttribute("excludeScope", Scope.PROTECTED.getName());
251         final String JavaDoc[] expected = {
252             "10:5: Missing a Javadoc comment.",
253             "11:5: Missing a Javadoc comment.",
254             "21:9: Missing a Javadoc comment.",
255             "22:9: Missing a Javadoc comment.",
256             "31:9: Missing a Javadoc comment.",
257             "32:9: Missing a Javadoc comment.",
258             "33:9: Missing a Javadoc comment.",
259             "34:9: Missing a Javadoc comment.",
260             "43:9: Missing a Javadoc comment.",
261             "44:9: Missing a Javadoc comment.",
262             "45:9: Missing a Javadoc comment.",
263             "46:9: Missing a Javadoc comment.",
264             "56:5: Missing a Javadoc comment.",
265             "57:5: Missing a Javadoc comment.",
266             "58:5: Missing a Javadoc comment.",
267             "59:5: Missing a Javadoc comment.",
268             "67:9: Missing a Javadoc comment.",
269             "68:9: Missing a Javadoc comment.",
270             "69:9: Missing a Javadoc comment.",
271             "70:9: Missing a Javadoc comment.",
272             "79:9: Missing a Javadoc comment.",
273             "80:9: Missing a Javadoc comment.",
274             "81:9: Missing a Javadoc comment.",
275             "82:9: Missing a Javadoc comment.",
276             "91:9: Missing a Javadoc comment.",
277             "92:9: Missing a Javadoc comment.",
278             "93:9: Missing a Javadoc comment.",
279             "94:9: Missing a Javadoc comment.",
280             "103:9: Missing a Javadoc comment.",
281             "104:9: Missing a Javadoc comment.",
282             "105:9: Missing a Javadoc comment.",
283             "106:9: Missing a Javadoc comment.", };
284         verify(mCheckConfig, getPath("javadoc" + File.separator
285                                     + "InputNoJavadoc.java"), expected);
286     }
287
288     public void testAllowMissingJavadoc() throws Exception JavaDoc
289     {
290         mCheckConfig.addAttribute("allowMissingJavadoc", "true");
291         final String JavaDoc[] expected = {};
292         verify(mCheckConfig, getPath("javadoc" + File.separator
293                                     + "InputNoJavadoc.java"), expected);
294     }
295
296     public void testSetterGetterOff() throws Exception JavaDoc
297     {
298         final String JavaDoc[] expected = {
299             "5:5: Missing a Javadoc comment.",
300             "10:5: Missing a Javadoc comment.",
301             "15:5: Missing a Javadoc comment.",
302             "20:5: Missing a Javadoc comment.",
303             "26:5: Missing a Javadoc comment.",
304             "30:5: Missing a Javadoc comment.",
305             "35:5: Missing a Javadoc comment.",
306             "41:5: Missing a Javadoc comment.",
307             "46:5: Missing a Javadoc comment.", };
308         verify(mCheckConfig, getPath("javadoc" + File.separator
309                                     + "InputSetterGetter.java"), expected);
310     }
311
312     public void testSetterGetterOn() throws Exception JavaDoc
313     {
314         mCheckConfig.addAttribute("allowMissingPropertyJavadoc", "true");
315         final String JavaDoc[] expected = {
316             "15:5: Missing a Javadoc comment.",
317             "20:5: Missing a Javadoc comment.",
318             "26:5: Missing a Javadoc comment.",
319             "30:5: Missing a Javadoc comment.",
320             "35:5: Missing a Javadoc comment.",
321             "41:5: Missing a Javadoc comment.", };
322         verify(mCheckConfig, getPath("javadoc" + File.separator
323                                     + "InputSetterGetter.java"), expected);
324     }
325
326     public void testTypeParamsTags() throws Exception JavaDoc
327     {
328         final String JavaDoc[] expected = {
329             "26:8: Unused @param tag for '<BB>'.",
330             "28:13: Expected @param tag for '<Z>'.", };
331         verify(mCheckConfig, getPath("InputTypeParamsTags.java"), expected);
332     }
333
334     public void test_1168408_1() throws Exception JavaDoc
335     {
336         final String JavaDoc[] expected = {};
337         verify(mCheckConfig, getPath("javadoc/Test1.java"), expected);
338     }
339
340     public void test_1168408_2() throws Exception JavaDoc
341     {
342         final String JavaDoc[] expected = {};
343         verify(mCheckConfig, getPath("javadoc/Test2.java"), expected);
344     }
345
346     public void test_1168408_3() throws Exception JavaDoc
347     {
348         mCheckConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
349         mCheckConfig.addAttribute("allowUndeclaredRTE", "true");
350         final String JavaDoc[] expected = {};
351         verify(mCheckConfig, getPath("javadoc/Test3.java"), expected);
352     }
353
354     public void test_generics_1() throws Exception JavaDoc
355     {
356         mCheckConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
357         mCheckConfig.addAttribute("allowUndeclaredRTE", "true");
358         final String JavaDoc[] expected = {
359             "15:34: Expected @throws tag for 'RE'.",
360             "23:37: Expected @throws tag for 'RE'.",
361             "31:13: Expected @param tag for '<NPE>'.",
362             "38:12: Unused @throws tag for 'E'.",
363             "41:38: Expected @throws tag for 'RuntimeException'.",
364             "42:13: Expected @throws tag for 'java.lang.RuntimeException'.",
365         };
366         verify(mCheckConfig, getPath("javadoc/TestGenerics.java"), expected);
367     }
368
369     public void test_generics_2() throws Exception JavaDoc
370     {
371         mCheckConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
372         final String JavaDoc[] expected = {
373             "15:34: Expected @throws tag for 'RE'.",
374             "23:37: Expected @throws tag for 'RE'.",
375             "31:13: Expected @param tag for '<NPE>'.",
376             "38:12: Unused @throws tag for 'E'.",
377             "41:38: Expected @throws tag for 'RuntimeException'.",
378             "42:13: Expected @throws tag for 'java.lang.RuntimeException'.",
379         };
380         verify(mCheckConfig, getPath("javadoc/TestGenerics.java"), expected);
381     }
382
383     public void test_generics_3() throws Exception JavaDoc
384     {
385         final String JavaDoc[] expected = {
386             "6:8: Unused @throws tag for 'RE'.",
387             "15:34: Expected @throws tag for 'RE'.",
388             "31:13: Expected @param tag for '<NPE>'.",
389             "38:12: Unused @throws tag for 'E'.",
390             "41:38: Expected @throws tag for 'RuntimeException'.",
391             "42:13: Expected @throws tag for 'java.lang.RuntimeException'.",
392         };
393         verify(mCheckConfig, getPath("javadoc/TestGenerics.java"), expected);
394     }
395
396     public void test_1379666() throws Exception JavaDoc
397     {
398         mCheckConfig.addAttribute("allowThrowsTagsForSubclasses", "true");
399         mCheckConfig.addAttribute("allowUndeclaredRTE", "true");
400         final String JavaDoc[] expected = {};
401         verify(mCheckConfig, getPath("javadoc/Test_1379666.java"), expected);
402     }
403
404     public void testInheritDoc() throws Exception JavaDoc
405     {
406         final String JavaDoc[] expected = {
407                 "4:5: Invalid use of the {@inheritDoc} tag.",
408                 "9:5: Invalid use of the {@inheritDoc} tag.",};
409         verify(mCheckConfig, getPath("javadoc/InputInheritDoc.java"), expected);
410     }
411 }
412
Popular Tags