KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > doctorj > TestExceptionDocAnalyzer


1 package org.incava.doctorj;
2
3 import java.io.*;
4 import java.util.*;
5 import junit.framework.TestCase;
6 import org.incava.analysis.Violation;
7
8
9 public class TestExceptionDocAnalyzer extends Tester
10 {
11     public TestExceptionDocAnalyzer(String JavaDoc name)
12     {
13         super(name);
14     }
15
16     public void xtestMethodExceptionWithoutTag()
17     {
18         evaluate("/** This is a description. */\n" +
19                  "class Test {\n" +
20                  " /** This is a description.\n" +
21                  " * @exception\n" +
22                  " */\n" +
23                  " public void method() throws IOException {}\n" +
24                  "}\n",
25                  new Violation[] {
26                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_WITHOUT_CLASS_NAME, 4, 9, 4, 18),
27                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_DOCUMENTED, 6, 33, 6, 43)
28                  });
29     }
30
31     public void xtestMethodExceptionUndocumented()
32     {
33         evaluate("/** This is a description. */\n" +
34                  "class Test {\n" +
35                  " /** This is a description.\n" +
36                  " * @exception IOException\n" +
37                  " */\n" +
38                  " public void method() throws IOException {}\n" +
39                  "}\n",
40                  new Violation[] {
41                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_WITHOUT_DESCRIPTION, 4, 20, 4, 30)
42                  });
43     }
44
45     public void xtestMethodExceptionMisspelled()
46     {
47         evaluate("/** This is a description. */\n" +
48                  "class Test {\n" +
49                  " /** This is a description.\n" +
50                  " * @exception IOExceptoin thrown on I/O error.\n" +
51                  " */\n" +
52                  " public void method() throws IOException {}\n" +
53                  "}\n",
54                  new Violation[] {
55                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_MISSPELLED, 4, 20, 4, 30)
56                  });
57     }
58     
59     public void xtestMethodExceptionAsNameMisspelled()
60     {
61         evaluate("/** This is a description. */\n" +
62                  "class Test {\n" +
63                  " /** This is a description.\n" +
64                  " * @exception IOExceptoin thrown on I/O error.\n" +
65                  " */\n" +
66                  " public void method() throws java.io.IOException {}\n" +
67                  "}\n",
68                  new Violation[] {
69                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_MISSPELLED, 4, 20, 4, 30)
70                  });
71     }
72     
73     public void xtestMethodExceptionDocumentedButNotInCode()
74     {
75         evaluate("/** This is a description. */\n" +
76                  "class Test {\n" +
77                  " /** This is a description.\n" +
78                  " * @exception IOException thrown on I/O error.\n" +
79                  " */\n" +
80                  " public void method() {}\n" +
81                  "}\n",
82                  new Violation[] {
83                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_IN_THROWS_LIST, 4, 20, 4, 30)
84                  });
85
86         evaluate("/** This is a description. */\n" +
87                  "class Test {\n" +
88                  " /** This is a description.\n" +
89                  " * @exception FileNotFoundException thrown when there is no file\n" +
90                  " * @exception IOException thrown on I/O error.\n" +
91                  " */\n" +
92                  " public void method() throws FileNotFoundException {}\n" +
93                  "}\n",
94                  new Violation[] {
95                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_IN_THROWS_LIST, 5, 20, 5, 30)
96                  });
97     }
98
99     public void xtestMethodExceptionNotDocumented()
100     {
101         evaluate("/** This is a description. */\n" +
102                  "class Test {\n" +
103                  " /** This is a description.\n" +
104                  " */\n" +
105                  " public void method() throws IOException {}\n" +
106                  "}\n",
107                  new Violation[] {
108                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_DOCUMENTED, 5, 33, 5, 43)
109                  });
110
111         evaluate("/** This is a description. */\n" +
112                  "class Test {\n" +
113                  " /** This is a description.\n" +
114                  " * @exception IOException thrown on I/O error.\n" +
115                  " */\n" +
116                  " public void method() throws java.io.IOException {}\n" +
117                  "}\n",
118                  new Violation[] {
119                  });
120
121         evaluate("/** This is a description. */\n" +
122                  "class Test {\n" +
123                  " /** This is a description.\n" +
124                  " * @exception java.io.IOException thrown on I/O error.\n" +
125                  " */\n" +
126                  " public void method() throws java.io.IOException {}\n" +
127                  "}\n",
128                  new Violation[] {
129                  });
130
131         evaluate("/** This is a description. */\n" +
132                  "class Test {\n" +
133                  " /** This is a description.\n" +
134                  " * @exception java.io.IOException thrown on I/O error.\n" +
135                  " */\n" +
136                  " public void method() throws IOException {}\n" +
137                  "}\n",
138                  new Violation[] {
139                  });
140     }
141
142     public void xtestMethodExceptionNotAlphabetical()
143     {
144         evaluate("/** This is a description. */\n" +
145                  "class Test {\n" +
146                  " /** This is a description.\n" +
147                  " * @exception NullPointerException thrown when there is no file\n" +
148                  " * @exception IOException thrown on I/O error.\n" +
149                  " */\n" +
150                  " public void method() throws NullPointerException, IOException {}\n" +
151                  "}\n",
152                  new Violation[] {
153                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTIONS_NOT_ALPHABETICAL, 5, 20, 5, 30)
154                  });
155
156         evaluate("/** This is a description. */\n" +
157                  "class Test {\n" +
158                  " /** This is a description.\n" +
159                  " * @exception ArrayIndexOutOfBoundsException thrown when index >= array.length\n" +
160                  " * @exception NullPointerException thrown when there is no file\n" +
161                  " * @exception IOException thrown on I/O error.\n" +
162                  " */\n" +
163                  " public void method() throws IOException {}\n" +
164                  "}\n",
165                  new Violation[] {
166                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTIONS_NOT_ALPHABETICAL, 6, 20, 6, 30)
167                  });
168     }
169     
170     public void xtestCtorExceptionWithoutTag()
171     {
172         evaluate("/** This is a description. */\n" +
173                  "class Test {\n" +
174                  " /** This is a description.\n" +
175                  " * @exception\n" +
176                  " */\n" +
177                  " public Test() throws IOException {}\n" +
178                  "}\n",
179                  new Violation[] {
180                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_WITHOUT_CLASS_NAME, 4, 9, 4, 18),
181                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_DOCUMENTED, 6, 26, 6, 36)
182                  });
183     }
184
185     public void xtestCtorExceptionUndocumented()
186     {
187         evaluate("/** This is a description. */\n" +
188                  "class Test {\n" +
189                  " /** This is a description.\n" +
190                  " * @exception IOException\n" +
191                  " */\n" +
192                  " public Test() throws IOException {}\n" +
193                  "}\n",
194                  new Violation[] {
195                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_WITHOUT_DESCRIPTION, 4, 20, 4, 30)
196                  });
197     }
198
199     public void xtestCtorExceptionMisspelled()
200     {
201         evaluate("/** This is a description. */\n" +
202                  "class Test {\n" +
203                  " /** This is a description.\n" +
204                  " * @exception IOExceptoin thrown on I/O error.\n" +
205                  " */\n" +
206                  " public Test() throws IOException {}\n" +
207                  "}\n",
208                  new Violation[] {
209                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_MISSPELLED, 4, 20, 4, 30)
210                  });
211     }
212     
213     public void xtestCtorExceptionAsNameMisspelled()
214     {
215         evaluate("/** This is a description. */\n" +
216                  "class Test {\n" +
217                  " /** This is a description.\n" +
218                  " * @exception IOExceptoin thrown on I/O error.\n" +
219                  " */\n" +
220                  " public Test() throws java.io.IOException {}\n" +
221                  "}\n",
222                  new Violation[] {
223                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_MISSPELLED, 4, 20, 4, 30)
224                  });
225     }
226     
227     public void xtestCtorExceptionDocumentedButNotInCode()
228     {
229         evaluate("/** This is a description. */\n" +
230                  "class Test {\n" +
231                  " /** This is a description.\n" +
232                  " * @exception IOException thrown on I/O error.\n" +
233                  " */\n" +
234                  " public Test() {}\n" +
235                  "}\n",
236                  new Violation[] {
237                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_IN_THROWS_LIST, 4, 20, 4, 30)
238                  });
239
240         evaluate("/** This is a description. */\n" +
241                  "class Test {\n" +
242                  " /** This is a description.\n" +
243                  " * @exception FileNotFoundException thrown when there is no file\n" +
244                  " * @exception IOException thrown on I/O error.\n" +
245                  " */\n" +
246                  " public Test() throws FileNotFoundException {}\n" +
247                  "}\n",
248                  new Violation[] {
249                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_IN_THROWS_LIST, 5, 20, 5, 30)
250                  });
251     }
252
253     public void xtestCtorExceptionNotDocumented()
254     {
255         evaluate("/** This is a description. */\n" +
256                  "class Test {\n" +
257                  " /** This is a description.\n" +
258                  " */\n" +
259                  " public Test() throws IOException {}\n" +
260                  "}\n",
261                  new Violation[] {
262                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_DOCUMENTED, 5, 26, 5, 36)
263                  });
264
265         evaluate("/** This is a description. */\n" +
266                  "class Test {\n" +
267                  " /** This is a description.\n" +
268                  " * @exception IOException thrown on I/O error.\n" +
269                  " */\n" +
270                  " public Test() throws java.io.IOException {}\n" +
271                  "}\n",
272                  new Violation[] {
273                  });
274
275         evaluate("/** This is a description. */\n" +
276                  "class Test {\n" +
277                  " /** This is a description.\n" +
278                  " * @exception java.io.IOException thrown on I/O error.\n" +
279                  " */\n" +
280                  " public Test() throws java.io.IOException {}\n" +
281                  "}\n",
282                  new Violation[] {
283                  });
284
285         evaluate("/** This is a description. */\n" +
286                  "class Test {\n" +
287                  " /** This is a description.\n" +
288                  " * @exception java.io.IOException thrown on I/O error.\n" +
289                  " */\n" +
290                  " public Test() throws IOException {}\n" +
291                  "}\n",
292                  new Violation[] {
293                  });
294     }
295
296     public void xtestCtorExceptionNotAlphabetical()
297     {
298         evaluate("/** This is a description. */\n" +
299                  "class Test {\n" +
300                  " /** This is a description.\n" +
301                  " * @exception NullPointerException thrown when there is no file\n" +
302                  " * @exception IOException thrown on I/O error.\n" +
303                  " */\n" +
304                  " public Test() throws NullPointerException, IOException {}\n" +
305                  "}\n",
306                  new Violation[] {
307                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTIONS_NOT_ALPHABETICAL, 5, 20, 5, 30)
308                  });
309
310         evaluate("/** This is a description. */\n" +
311                  "class Test {\n" +
312                  " /** This is a description.\n" +
313                  " * @exception ArrayIndexOutOfBoundsException thrown when index >= array.length\n" +
314                  " * @exception NullPointerException thrown when there is no file\n" +
315                  " * @exception IOException thrown on I/O error.\n" +
316                  " */\n" +
317                  " public Test() throws IOException {}\n" +
318                  "}\n",
319                  new Violation[] {
320                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTIONS_NOT_ALPHABETICAL, 6, 20, 6, 30)
321                  });
322     }
323
324     public void xtestCtorExceptionRuntimeExceptionNotDeclared()
325     {
326         List runtimeExceptions = new ArrayList();
327         runtimeExceptions.addAll(Arrays.asList(new String JavaDoc[] {
328                                                    "java.awt.color.CMMException",
329                                                    "java.awt.color.ProfileDataException",
330
331                                                    "java.awt.geom.IllegalPathStateException",
332         
333                                                    "java.awt.image.ImagingOpException",
334                                                    "java.awt.image.RasterFormatException",
335
336                                                    "java.lang.ArithmeticException",
337                                                    "java.lang.ArrayStoreException",
338                                                    "java.lang.ClassCastException",
339                                                    "java.lang.IllegalArgumentException",
340                                                    "java.lang.IllegalMonitorStateException",
341                                                    "java.lang.IllegalStateException",
342                                                    "java.lang.IndexOutOfBoundsException",
343                                                    "java.lang.NegativeArraySizeException",
344                                                    "java.lang.NullPointerException",
345                                                    "java.lang.SecurityException",
346                                                    // "java.lang.TypeNotPresentException", 1.5 only
347
"java.lang.UnsupportedOperationException",
348
349                                                    // "java.lang.annotation.AnnotationTypeMismatchException", 1.5 only
350
// "java.lang.annotation.IncompleteAnnotationException", 1.5 only
351

352                                                    // "java.lang.reflect.MalformedParameterizedTypeException", 1.5 only
353
"java.lang.reflect.UndeclaredThrowableException",
354
355                                                    "java.nio.BufferOverflowException",
356                                                    "java.nio.BufferUnderflowException",
357
358                                                    "java.security.ProviderException",
359
360                                                    "java.util.ConcurrentModificationException",
361                                                    "java.util.EmptyStackException",
362                                                    "java.util.MissingResourceException",
363                                                    "java.util.NoSuchElementException",
364         
365                                                    // "java.util.concurrent.RejectedExecutionException", 1.5
366

367                                                    // "javax.management.JMRuntimeException",
368

369                                                    "javax.print.attribute.UnmodifiableSetException",
370         
371                                                    "javax.swing.undo.CannotRedoException",
372                                                    "javax.swing.undo.CannotUndoException",
373         
374                                                    "org.omg.CORBA.SystemException",
375         
376                                                    "org.w3c.dom.DOMException",
377         
378                                                    "org.w3c.dom.events.EventException",
379                                                    
380                                                    //"org.w3c.dom.ls.LSException", 1.5
381
}));
382
383         Iterator it = runtimeExceptions.iterator();
384         while (it.hasNext()) {
385             String JavaDoc rtexc = (String JavaDoc)it.next();
386
387             evaluate("/** This is a description.\n" +
388                      " */\n" +
389                      "class Test {\n" +
390                      " /** This is a description.\n" +
391                      " * @exception " + rtexc + " This is a description.\n" +
392                      " */\n" +
393                      " public Test() {}\n" +
394                      "}\n",
395                      new Violation[] {
396                      });
397         }
398     }
399
400     public void xtestFullNameNotImported()
401     {
402         evaluate("/** This is a description.\n" +
403                  " */\n" +
404                  "class Test {\n" +
405                  " /** This is a description.\n" +
406                  " * @exception java.util.NoSuchElementException This is a description.\n" +
407                  " */\n" +
408                  " public Test() {}\n" +
409                  "}\n",
410                  new Violation[] {
411                  });
412     }
413
414     public void xtestShortNameImportedSingle()
415     {
416         evaluate("import java.util.NoSuchElementException;\n" +
417                  "/** This is a description.\n" +
418                  " */\n" +
419                  "class Test {\n" +
420                  " /** This is a description.\n" +
421                  " * @exception NoSuchElementException This is a description.\n" +
422                  " */\n" +
423                  " public Test() {}\n" +
424                  "}\n",
425                  new Violation[] {
426                  });
427     }
428
429     public void xtestShortNameImportedOnDemand()
430     {
431         evaluate("import java.util.*;\n" +
432                  "/** This is a description.\n" +
433                  " */\n" +
434                  "class Test {\n" +
435                  " /** This is a description.\n" +
436                  " * @exception NoSuchElementException This is a description.\n" +
437                  " */\n" +
438                  " public Test() {}\n" +
439                  "}\n",
440                  new Violation[] {
441                  });
442     }
443
444     public void xtestShortNameImportedOnDemandJava1415()
445     {
446         evaluate("import org.apache.xml.utils.*;\n" + // 1.4
447
"import com.sun.org.apache.xml.internal.utils.*;\n" + // 1.5
448
"/** This is a description.\n" +
449                  " */\n" +
450                  "class Test {\n" +
451                  " /** This is a description.\n" +
452                  " * @exception WrappedRuntimeException This is a description.\n" +
453                  " */\n" +
454                  " public Test() {}\n" +
455                  "}\n",
456                  new Violation[] {
457                  });
458     }
459
460     public void testUnknownExceptionReportOnce()
461     {
462         evaluate("/** This is a description.\n" +
463                  " */\n" +
464                  "class Test {\n" +
465                  " /** This is a description.\n" +
466                  " * @exception org.incava.util.NoPointersInJavaException This is a description.\n" +
467                  " */\n" +
468                  " public void foo() {}\n" +
469                  "\n" +
470                  " /** This is a description.\n" +
471                  " * @exception org.incava.util.NoPointersInJavaException This is a description.\n" +
472                  " */\n" +
473                  " public void bar() {}\n" +
474                  "}\n",
475                  new Violation[] {
476                      new Violation(ExceptionDocAnalyzer.MSG_EXCEPTION_NOT_DOCUMENTED, 5, 20, 5, 60)
477                  });
478     }
479
480     public void testErrorShortName()
481     {
482         evaluate("/** This is a description.\n" +
483                  " */\n" +
484                  "class Test {\n" +
485                  " /** This is a description.\n" +
486                  " * @exception LinkageError This is a description.\n" +
487                  " */\n" +
488                  " public void foo() {}\n" +
489                  "}\n",
490                  new Violation[] {
491                  });
492     }
493
494     public void testErrorLongName()
495     {
496         evaluate("/** This is a description.\n" +
497                  " */\n" +
498                  "class Test {\n" +
499                  " /** This is a description.\n" +
500                  " * @exception java.lang.ExceptionInInitializerError This is a description.\n" +
501                  " */\n" +
502                  " public void foo() {}\n" +
503                  "}\n",
504                  new Violation[] {
505                  });
506     }
507
508 }
509
Popular Tags