KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestItemDocAnalyzer extends Tester
10 {
11     static {
12         ItemDocAnalyzer.spellChecker.addDictionary("/home/jpace/proj/doctorj/etc/words.en_US");
13     }
14     
15     public TestItemDocAnalyzer(String JavaDoc name)
16     {
17         super(name);
18     }
19
20     // presence of Javadoc
21

22     public void testDocumentedOuterConcreteNonPublicClass()
23     {
24         evaluate("class Test {\n" +
25                  "}\n",
26                  new Violation[] {
27                      new Violation("Undocumented class", 1, 7, 1, 10)
28                  });
29     }
30
31     public void testDocumentedOuterConcretePublicClass()
32     {
33         evaluate("public class TestHasJavadoc {\n" +
34                  "}\n",
35                  new Violation[] {
36                      new Violation("Undocumented public class", 1, 14, 1, 27)
37                  });
38     }
39
40     public void testDocumentedOuterAbstractNonPublicClass()
41     {
42         evaluate("abstract class TestHasJavadoc {\n" +
43                  "}\n",
44                  new Violation[] {
45                      new Violation("Undocumented abstract class", 1, 16, 1, 29)
46                  });
47     }
48
49     public void testDocumentedOuterAbstractPublicClass()
50     {
51         evaluate("public abstract class TestHasJavadoc {\n" +
52                  "}\n",
53                  new Violation[] {
54                      new Violation("Undocumented public abstract class", 1, 23, 1, 36)
55                  });
56     }
57
58     public void testDocumentedOuterNonPublicInterface()
59     {
60         evaluate("interface TestHasJavadoc {\n" +
61                  "}\n",
62                  new Violation[] {
63                      new Violation("Undocumented interface", 1, 11, 1, 24)
64                  });
65     }
66
67     public void testDocumentedOuterPublicInterface()
68     {
69         evaluate("public interface TestHasJavadoc {\n" +
70                  "}\n",
71                  new Violation[] {
72                      new Violation("Undocumented public interface", 1, 18, 1, 31)
73                  });
74     }
75
76     public void testDocumentedInnerConcreteNonPublicClass()
77     {
78         evaluate("/** this class is commented. */\n" +
79                  "class Test {\n" +
80                  " class InnerTestHasJavadoc {\n" +
81                  " }\n" +
82                  "}\n",
83                  new Violation[] {
84                      new Violation("Undocumented class", 3, 11, 3, 29)
85                  });
86     }
87
88     public void testDocumentedInnerConcretePublicClass()
89     {
90         evaluate("/** this class is commented. */\n" +
91                  "class Test {\n" +
92                  " public class InnerTestHasJavadoc {\n" +
93                  " }\n" +
94                  "}\n",
95                  new Violation[] {
96                      new Violation("Undocumented public class", 3, 18, 3, 36)
97                  });
98     }
99
100     public void testDocumentedInnerAbstractNonPublicClass()
101     {
102         evaluate("/** this class is commented. */\n" +
103                  "class Test {\n" +
104                  " abstract class InnerTestHasJavadoc {\n" +
105                  " }\n" +
106                  "}\n",
107                  new Violation[] {
108                      new Violation("Undocumented abstract class", 3, 20, 3, 38)
109                  });
110     }
111
112     public void testDocumentedInnerAbstractPublicClass()
113     {
114         evaluate("/** this class is commented. */\n" +
115                  "class Test {\n" +
116                  " public abstract class InnerTestHasJavadoc {\n" +
117                  " }\n" +
118                  "}\n",
119                  new Violation[] {
120                      new Violation("Undocumented public abstract class", 3, 27, 3, 45)
121                  });
122     }
123
124     public void testDocumentedInnerNonPublicInterface()
125     {
126         evaluate("/** this interface is commented. */\n" +
127                  "interface TestHasJavadoc {\n" +
128                  " interface InnerTestHasJavadoc {\n" +
129                  " }\n" +
130                  "}\n",
131                  new Violation[] {
132                      new Violation("Undocumented interface", 3, 15, 3, 33)
133                  });
134     }
135
136     public void testDocumentedInnerPublicInterface()
137     {
138         evaluate("/** this interface is commented. */\n" +
139                  "interface TestHasJavadoc {\n" +
140                  " public interface InnerTestHasJavadoc {\n" +
141                  " }\n" +
142                  "}\n",
143                  new Violation[] {
144                      new Violation("Undocumented public interface", 3, 22, 3, 40)
145                  });
146     }
147
148     public void testDocumentedNonPublicConstructor()
149     {
150         evaluate("/** this class is commented. */\n" +
151                  "public class TestHasJavadoc {\n" +
152                  " Test() {} \n" +
153                  "}\n",
154                  new Violation[] {
155                      new Violation("Undocumented constructor", 3, 5, 3, 8)
156                  });
157     }
158
159     public void testDocumentedPublicConstructor()
160     {
161         evaluate("/** this class is commented. */\n" +
162                  "public class TestHasJavadoc {\n" +
163                  " public TestHasJavadoc() {} \n" +
164                  "}\n",
165                  new Violation[] {
166                      new Violation("Undocumented public constructor", 3, 12, 3, 25)
167                  });
168     }
169
170     public void testDocumentedNonPublicMethod()
171     {
172         evaluate("/** this class is commented. */\n" +
173                  "public class TestHasJavadoc {\n" +
174                  " void f() {} \n" +
175                  "}\n",
176                  new Violation[] {
177                      new Violation("Undocumented method", 3, 10, 3, 10)
178                  });
179     }
180
181     public void testDocumentedPublicMethod()
182     {
183         evaluate("/** this class is commented. */\n" +
184                  "public class TestHasJavadoc {\n" +
185                  " public void f() {} \n" +
186                  "}\n",
187                  new Violation[] {
188                      new Violation("Undocumented public method", 3, 17, 3, 17)
189                  });
190     }
191
192     public void testDocumentedNonPublicField()
193     {
194         evaluate("/** this class is commented. */\n" +
195                  "public class TestHasJavadoc {\n" +
196                  " String s;\n" +
197                  "}\n",
198                  new Violation[] {
199                      new Violation("Undocumented field", 3, 12, 3, 12)
200                  });
201     }
202
203     public void testDocumentedPublicField()
204     {
205         evaluate("/** this class is commented. */\n" +
206                  "public class TestHasJavadoc {\n" +
207                  " public String s;\n" +
208                  "}\n",
209                  new Violation[] {
210                      new Violation("Undocumented public field", 3, 19, 3, 19)
211                  });
212     }
213
214     public void testDocumentedPublicFieldMultipleVariables()
215     {
216         evaluate("/** this class is commented. */\n" +
217                  "public class TestHasJavadoc {\n" +
218                  " public String s, t, u, v = \"foo\";\n" +
219                  "}\n",
220                  new Violation[] {
221                      new Violation("Undocumented public field", 3, 19, 3, 28)
222                  });
223     }
224
225     // deprecated
226

227     public void testDeprecatedClassWithText()
228     {
229         evaluate("/** This is a description.\n" +
230                  " * @deprecated Use something else.\n" +
231                  " */\n" +
232                  "class Test {\n" +
233                  "}\n",
234                  new Violation[] {
235                  });
236     }
237
238     public void testDeprecatedClassWithoutText()
239     {
240         evaluate("/** This is a description.\n" +
241                  " * @deprecated\n" +
242                  " */\n" +
243                  "class Test {\n" +
244                  "}\n",
245                  new Violation[] {
246                      new Violation(ItemDocAnalyzer.MSG_DEPRECATED_WITHOUT_TEXT, 2, 5, 2, 15)
247                  });
248     }
249     
250     public void testDeprecatedClassWithoutTextSpaces()
251     {
252         evaluate("/** This is a description.\n" +
253                  " * @deprecated \n" +
254                  " */\n" +
255                  "class Test {\n" +
256                  "}\n",
257                  new Violation[] {
258                      new Violation(ItemDocAnalyzer.MSG_DEPRECATED_WITHOUT_TEXT, 2, 5, 2, 15)
259                  });
260     }
261
262     public void testDeprecatedInterfaceWithText()
263     {
264         evaluate("/** This is a description.\n" +
265                  " * @deprecated Use something else.\n" +
266                  " */\n" +
267                  "interface TestDeprecatedTag {\n" +
268                  "}\n",
269                  new Violation[] {
270                  });
271     }
272
273     public void testDeprecatedInterfaceWithoutText()
274     {
275         evaluate("/** This is a description.\n" +
276                  " * @deprecated\n" +
277                  " */\n" +
278                  "interface TestDeprecatedTag {\n" +
279                  "}\n",
280                  new Violation[] {
281                      new Violation(ItemDocAnalyzer.MSG_DEPRECATED_WITHOUT_TEXT, 2, 5, 2, 15)
282                  });
283     }
284     
285     public void testDeprecatedInterfaceWithoutTextSpaces()
286     {
287         evaluate("/** This is a description.\n" +
288                  " * @deprecated \n" +
289                  " */\n" +
290                  "interface TestDeprecatedTag {\n" +
291                  "}\n",
292                  new Violation[] {
293                      new Violation(ItemDocAnalyzer.MSG_DEPRECATED_WITHOUT_TEXT, 2, 5, 2, 15)
294                  });
295     }
296
297     public void testDeprecatedMethodWithText()
298     {
299         evaluate("/** This is a description.\n" +
300                  " */\n" +
301                  "class Test {\n" +
302                  " /** This is a description.\n" +
303                  " * @deprecated Use something else.\n" +
304                  " */\n" +
305                  " void f() {}\n" +
306                  "}\n",
307                  new Violation[] {
308                  });
309     }
310
311     public void testDeprecatedMethodWithoutText()
312     {
313         evaluate("/** This is a description.\n" +
314                  " */\n" +
315                  "class Test {\n" +
316                  " /** This is a description.\n" +
317                  " * @deprecated\n" +
318                  " */\n" +
319                  " void f() {}\n" +
320                  "}\n",
321                  new Violation[] {
322                      new Violation(ItemDocAnalyzer.MSG_DEPRECATED_WITHOUT_TEXT, 5, 9, 5, 19)
323                  });
324     }
325     
326     public void testDeprecatedMethodWithoutTextSpaces()
327     {
328         evaluate("/** This is a description.\n" +
329                  " */\n" +
330                  "class Test {\n" +
331                  " /** This is a description.\n" +
332                  " * @deprecated \n" +
333                  " */\n" +
334                  " void f() {}\n" +
335                  "}\n",
336                  new Violation[] {
337                      new Violation(ItemDocAnalyzer.MSG_DEPRECATED_WITHOUT_TEXT, 5, 9, 5, 19)
338                  });
339     }
340
341     public void testDeprecatedFieldWithText()
342     {
343         evaluate("/** This is a description.\n" +
344                  " */\n" +
345                  "class Test {\n" +
346                  " /** This is a description.\n" +
347                  " * @deprecated Use something else.\n" +
348                  " */\n" +
349                  " int f;\n" +
350                  "}\n",
351                  new Violation[] {
352                  });
353     }
354
355     public void testDeprecatedFieldWithoutText()
356     {
357         evaluate("/** This is a description.\n" +
358                  " */\n" +
359                  "class Test {\n" +
360                  " /** This is a description.\n" +
361                  " * @deprecated\n" +
362                  " */\n" +
363                  " int f;\n" +
364                  "}\n",
365                  new Violation[] {
366                      new Violation(ItemDocAnalyzer.MSG_DEPRECATED_WITHOUT_TEXT, 5, 9, 5, 19)
367                  });
368     }
369     
370     public void testDeprecatedFieldWithoutTextSpaces()
371     {
372         evaluate("/** This is a description.\n" +
373                  " */\n" +
374                  "class Test {\n" +
375                  " /** This is a description.\n" +
376                  " * @deprecated \n" +
377                  " */\n" +
378                  " int f;\n" +
379                  "}\n",
380                  new Violation[] {
381                      new Violation(ItemDocAnalyzer.MSG_DEPRECATED_WITHOUT_TEXT, 5, 9, 5, 19)
382                  });
383     }
384
385     // see
386

387     public void testSeeClassWithText()
388     {
389         evaluate("/** This is a description.\n" +
390                  " * @see something else\n" +
391                  " */\n" +
392                  "class Test {\n" +
393                  "}\n",
394                  new Violation[] {
395                  });
396
397         evaluate("/** This is a description.\n" +
398                  " * @see elsewhere\n" +
399                  " */\n" +
400                  "class Test {\n" +
401                  "}\n",
402                  new Violation[] {
403                  });
404     }
405
406     public void testSeeClassWithoutText()
407     {
408         evaluate("/** This is a description.\n" +
409                  " * @see\n" +
410                  " */\n" +
411                  "class Test {\n" +
412                  "}\n",
413                  new Violation[] {
414                      new Violation(ItemDocAnalyzer.MSG_SEE_WITHOUT_REFERENCE, 2, 5, 2, 8)
415                  });
416     }
417     
418     public void testSeeClassWithoutTextSpaces()
419     {
420         evaluate("/** This is a description.\n" +
421                  " * @see \n" +
422                  " */\n" +
423                  "class Test {\n" +
424                  "}\n",
425                  new Violation[] {
426                      new Violation(ItemDocAnalyzer.MSG_SEE_WITHOUT_REFERENCE, 2, 5, 2, 8)
427                  });
428     }
429
430     public void testSeeInterfaceWithText()
431     {
432         evaluate("/** This is a description.\n" +
433                  " * @see something else\n" +
434                  " */\n" +
435                  "interface TestSeeTag {\n" +
436                  "}\n",
437                  new Violation[] {
438                  });
439
440         evaluate("/** This is a description.\n" +
441                  " * @see elsewhere\n" +
442                  " */\n" +
443                  "interface TestSeeTag {\n" +
444                  "}\n",
445                  new Violation[] {
446                  });
447     }
448
449     public void testSeeInterfaceWithoutText()
450     {
451         evaluate("/** This is a description.\n" +
452                  " * @see\n" +
453                  " */\n" +
454                  "interface TestSeeTag {\n" +
455                  "}\n",
456                  new Violation[] {
457                      new Violation(ItemDocAnalyzer.MSG_SEE_WITHOUT_REFERENCE, 2, 5, 2, 8)
458                  });
459     }
460     
461     public void testSeeInterfaceWithoutTextSpaces()
462     {
463         evaluate("/** This is a description.\n" +
464                  " * @see \n" +
465                  " */\n" +
466                  "interface TestSeeTag {\n" +
467                  "}\n",
468                  new Violation[] {
469                      new Violation(ItemDocAnalyzer.MSG_SEE_WITHOUT_REFERENCE, 2, 5, 2, 8)
470                  });
471     }
472
473     public void testSeeMethodWithText()
474     {
475         evaluate("/** This is a description.\n" +
476                  " */\n" +
477                  "class Test {\n" +
478                  " /** This is a description.\n" +
479                  " * @see something else\n" +
480                  " */\n" +
481                  " void f() {}\n" +
482                  "}\n",
483                  new Violation[] {
484                  });
485
486         evaluate("/** This is a description.\n" +
487                  " */\n" +
488                  "class Test {\n" +
489                  " /** This is a description.\n" +
490                  " * @see elsewhere\n" +
491                  " */\n" +
492                  " void f() {}\n" +
493                  "}\n",
494                  new Violation[] {
495                  });
496     }
497
498     public void testSeeMethodWithoutText()
499     {
500         evaluate("/** This is a description.\n" +
501                  " */\n" +
502                  "class Test {\n" +
503                  " /** This is a description.\n" +
504                  " * @see\n" +
505                  " */\n" +
506                  " void f() {}\n" +
507                  "}\n",
508                  new Violation[] {
509                      new Violation(ItemDocAnalyzer.MSG_SEE_WITHOUT_REFERENCE, 5, 9, 5, 12)
510                  });
511     }
512     
513     public void testSeeMethodWithoutTextSpaces()
514     {
515         evaluate("/** This is a description.\n" +
516                  " */\n" +
517                  "class Test {\n" +
518                  " /** This is a description.\n" +
519                  " * @see \n" +
520                  " */\n" +
521                  " void f() {}\n" +
522                  "}\n",
523                  new Violation[] {
524                      new Violation(ItemDocAnalyzer.MSG_SEE_WITHOUT_REFERENCE, 5, 9, 5, 12)
525                  });
526     }
527
528     public void testSeeFieldWithText()
529     {
530         evaluate("/** This is a description.\n" +
531                  " */\n" +
532                  "class Test {\n" +
533                  " /** This is a description.\n" +
534                  " * @see something else\n" +
535                  " */\n" +
536                  " int f;\n" +
537                  "}\n",
538                  new Violation[] {
539                  });
540
541         evaluate("/** This is a description.\n" +
542                  " */\n" +
543                  "class Test {\n" +
544                  " /** This is a description.\n" +
545                  " * @see elsewhere\n" +
546                  " */\n" +
547                  " int f;\n" +
548                  "}\n",
549                  new Violation[] {
550                  });
551     }
552
553     public void testSeeFieldWithoutText()
554     {
555         evaluate("/** This is a description.\n" +
556                  " */\n" +
557                  "class Test {\n" +
558                  " /** This is a description.\n" +
559                  " * @see\n" +
560                  " */\n" +
561                  " int f;\n" +
562                  "}\n",
563                  new Violation[] {
564                      new Violation(ItemDocAnalyzer.MSG_SEE_WITHOUT_REFERENCE, 5, 9, 5, 12)
565                  });
566     }
567     
568     public void testSeeFieldWithoutTextSpaces()
569     {
570         evaluate("/** This is a description.\n" +
571                  " */\n" +
572                  "class Test {\n" +
573                  " /** This is a description.\n" +
574                  " * @see \n" +
575                  " */\n" +
576                  " int f;\n" +
577                  "}\n",
578                  new Violation[] {
579                      new Violation(ItemDocAnalyzer.MSG_SEE_WITHOUT_REFERENCE, 5, 9, 5, 12)
580                  });
581     }
582
583     // since
584

585     public void testSinceClassWithText()
586     {
587         evaluate("/** This is a description.\n" +
588                  " * @since some version\n" +
589                  " */\n" +
590                  "class Test {\n" +
591                  "}\n",
592                  new Violation[] {
593                  });
594
595         evaluate("/** This is a description.\n" +
596                  " * @since 3.17\n" +
597                  " */\n" +
598                  "class Test {\n" +
599                  "}\n",
600                  new Violation[] {
601                  });
602     }
603
604     public void testSinceClassWithoutText()
605     {
606         evaluate("/** This is a description.\n" +
607                  " * @since\n" +
608                  " */\n" +
609                  "class Test {\n" +
610                  "}\n",
611                  new Violation[] {
612                      new Violation(ItemDocAnalyzer.MSG_SINCE_WITHOUT_TEXT, 2, 5, 2, 10)
613                  });
614     }
615     
616     public void testSinceClassWithoutTextSpaces()
617     {
618         evaluate("/** This is a description.\n" +
619                  " * @since \n" +
620                  " */\n" +
621                  "class Test {\n" +
622                  "}\n",
623                  new Violation[] {
624                      new Violation(ItemDocAnalyzer.MSG_SINCE_WITHOUT_TEXT, 2, 5, 2, 10)
625                  });
626     }
627
628     public void testSinceInterfaceWithText()
629     {
630         evaluate("/** This is a description.\n" +
631                  " * @since some version\n" +
632                  " */\n" +
633                  "interface SinceTestTag {\n" +
634                  "}\n",
635                  new Violation[] {
636                  });
637
638         evaluate("/** This is a description.\n" +
639                  " * @since 3.17\n" +
640                  " */\n" +
641                  "interface SinceTestTag {\n" +
642                  "}\n",
643                  new Violation[] {
644                  });
645     }
646
647     public void testSinceInterfaceWithoutText()
648     {
649         evaluate("/** This is a description.\n" +
650                  " * @since\n" +
651                  " */\n" +
652                  "interface SinceTestTag {\n" +
653                  "}\n",
654                  new Violation[] {
655                      new Violation(ItemDocAnalyzer.MSG_SINCE_WITHOUT_TEXT, 2, 5, 2, 10)
656                  });
657     }
658     
659     public void testSinceInterfaceWithoutTextSpaces()
660     {
661         evaluate("/** This is a description.\n" +
662                  " * @since \n" +
663                  " */\n" +
664                  "interface SinceTestTag {\n" +
665                  "}\n",
666                  new Violation[] {
667                      new Violation(ItemDocAnalyzer.MSG_SINCE_WITHOUT_TEXT, 2, 5, 2, 10)
668                  });
669     }
670
671     public void testSinceMethodWithText()
672     {
673         evaluate("/** This is a description.\n" +
674                  " */\n" +
675                  "class Test {\n" +
676                  " /** This is a description.\n" +
677                  " * @since some version\n" +
678                  " */\n" +
679                  " void f() {}\n" +
680                  "}\n",
681                  new Violation[] {
682                  });
683
684         evaluate("/** This is a description.\n" +
685                  " */\n" +
686                  "class Test {\n" +
687                  " /** This is a description.\n" +
688                  " * @since 3.17\n" +
689                  " */\n" +
690                  " void f() {}\n" +
691                  "}\n",
692                  new Violation[] {
693                  });
694     }
695
696     public void testSinceMethodWithoutText()
697     {
698         evaluate("/** This is a description.\n" +
699                  " */\n" +
700                  "class Test {\n" +
701                  " /** This is a description.\n" +
702                  " * @since\n" +
703                  " */\n" +
704                  " void f() {}\n" +
705                  "}\n",
706                  new Violation[] {
707                      new Violation(ItemDocAnalyzer.MSG_SINCE_WITHOUT_TEXT, 5, 9, 5, 14)
708                  });
709     }
710     
711     public void testSinceMethodWithoutTextSpaces()
712     {
713         evaluate("/** This is a description.\n" +
714                  " */\n" +
715                  "class Test {\n" +
716                  " /** This is a description.\n" +
717                  " * @since \n" +
718                  " */\n" +
719                  " void f() {}\n" +
720                  "}\n",
721                  new Violation[] {
722                      new Violation(ItemDocAnalyzer.MSG_SINCE_WITHOUT_TEXT, 5, 9, 5, 14)
723                  });
724     }
725
726     public void testSinceFieldWithText()
727     {
728         evaluate("/** This is a description.\n" +
729                  " */\n" +
730                  "class Test {\n" +
731                  " /** This is a description.\n" +
732                  " * @since some version\n" +
733                  " */\n" +
734                  " int f;\n" +
735                  "}\n",
736                  new Violation[] {
737                  });
738
739         evaluate("/** This is a description.\n" +
740                  " */\n" +
741                  "class Test {\n" +
742                  " /** This is a description.\n" +
743                  " * @since 3.17\n" +
744                  " */\n" +
745                  " int f;\n" +
746                  "}\n",
747                  new Violation[] {
748                  });
749     }
750
751     public void testSinceFieldWithoutText()
752     {
753         evaluate("/** This is a description.\n" +
754                  " */\n" +
755                  "class Test {\n" +
756                  " /** This is a description.\n" +
757                  " * @since\n" +
758                  " */\n" +
759                  " int f;\n" +
760                  "}\n",
761                  new Violation[] {
762                      new Violation(ItemDocAnalyzer.MSG_SINCE_WITHOUT_TEXT, 5, 9, 5, 14)
763                  });
764     }
765     
766     public void testSinceFieldWithoutTextSpaces()
767     {
768         evaluate("/** This is a description.\n" +
769                  " */\n" +
770                  "class Test {\n" +
771                  " /** This is a description.\n" +
772                  " * @since \n" +
773                  " */\n" +
774                  " int f;\n" +
775                  "}\n",
776                  new Violation[] {
777                      new Violation(ItemDocAnalyzer.MSG_SINCE_WITHOUT_TEXT, 5, 9, 5, 14)
778                  });
779     }
780
781     // tag order
782

783     public void testNoTags()
784     {
785         evaluate("/** This is a description. */\n" +
786                  "class Test {\n" +
787                  "}\n",
788                  new Violation[] {
789                  });
790     }
791
792     public void testProperOrder()
793     {
794         evaluate("/**\n" +
795                  " * This is a description. \n" +
796                  " * @author me \n" +
797                  " * @version 0.1.2 \n" +
798                  " */\n" +
799                  "class Test {\n" +
800                  "}\n",
801                  new Violation[] {
802                  });
803
804
805         evaluate("/**\n" +
806                  " * This is a description. \n" +
807                  " * @version 0.1.2 \n" +
808                  " * @since 0.1.1 \n" +
809                  " */\n" +
810                  "class Test {\n" +
811                  "}\n",
812                  new Violation[] {
813                  });
814
815         JavadocTags.add(new JavadocTags.TagDescription("@todo", 10, true, true, true, true));
816         evaluate("/**\n" +
817                  " * This is a description. \n" +
818                  " * @version 0.1.2 \n" +
819                  " * @since 0.1.1 \n" +
820                  " * @todo fix exception when index < 0 \n" +
821                  " */\n" +
822                  "class Test {\n" +
823                  "}\n",
824                  new Violation[] {
825                  });
826     }
827
828     public void testImproperOrder()
829     {
830         evaluate("/**\n" +
831                  " * This is a description. \n" +
832                  " * @version 0.1.2 \n" +
833                  " * @author me \n" +
834                  " */\n" +
835                  "class Test {\n" +
836                  "}\n",
837                  new Violation[] {
838                      new Violation(ItemDocAnalyzer.MSG_TAG_IMPROPER_ORDER, 4, 5, 4, 11)
839                  });
840
841         evaluate("/**\n" +
842                  " * This is a description. \n" +
843                  " * @since 0.1.2 \n" +
844                  " * @author me \n" +
845                  " */\n" +
846                  "class Test {\n" +
847                  "}\n",
848                  new Violation[] {
849                      new Violation(ItemDocAnalyzer.MSG_TAG_IMPROPER_ORDER, 4, 5, 4, 11)
850                  });
851
852         evaluate("/**\n" +
853                  " * This is a description. \n" +
854                  " * @author me \n" +
855                  " * @deprecated stop using this class \n" +
856                  " * @since 0.1.2 \n" +
857                  " */\n" +
858                  "class Test {\n" +
859                  "}\n",
860                  new Violation[] {
861                      new Violation(ItemDocAnalyzer.MSG_TAG_IMPROPER_ORDER, 5, 5, 5, 10)
862                  });
863     }
864
865     // tag validity
866

867     public void testValidityClassTags()
868     {
869         evaluate("/** This is a description.\n" +
870                  " * @author me\n" +
871                  " * @version 1.10\n" +
872                  " * @see Spot#run() \n" +
873                  " * @since whenever\n" +
874                  " * @deprecated Use something better than this.\n" +
875                  " */\n" +
876                  "class Test {\n" +
877                  "}\n",
878                  new Violation[] {
879                  });
880
881         evaluate("/** This is a description.\n" +
882                  " * @author me\n" +
883                  " * @version 1.10\n" +
884                  " * @throws NullPointerException Although Java doesn't have pointers.\n" +
885                  " * @see Spot#run() \n" +
886                  " * @since whenever\n" +
887                  " * @deprecated Use something better than this.\n" +
888                  " */\n" +
889                  "class Test {\n" +
890                  "}\n",
891                  new Violation[] {
892                      new Violation("Tag not valid for class", 4, 5, 4, 11)
893                  });
894     }
895
896     public void testValidityInnerClassTags()
897     {
898         evaluate("/** This is a description. */\n" +
899                  "class Test {\n" +
900                  " /** This is a description.\n" +
901                  " * @author me\n" +
902                  " * @version 1.10\n" +
903                  " * @see Spot#run() \n" +
904                  " * @since whenever\n" +
905                  " * @deprecated Use something better than this.\n" +
906                  " */\n" +
907                  " class Inner {\n" +
908                  " }\n" +
909                  "}\n",
910                  new Violation[] {
911                  });
912
913         evaluate("/** This is a description. */\n" +
914                  "class Test {\n" +
915                  " /** This is a description.\n" +
916                  " * @author me\n" +
917                  " * @version 1.10\n" +
918                  " * @throws NullPointerException Although Java doesn't have pointers.\n" +
919                  " * @see Spot#run() \n" +
920                  " * @since whenever\n" +
921                  " * @deprecated Use something better than this.\n" +
922                  " */\n" +
923                  " class Inner {\n" +
924                  " }\n" +
925                  "}\n",
926                  new Violation[] {
927                      new Violation("Tag not valid for class", 6, 9, 6, 15)
928                  });
929     }
930
931     public void testValidityInterfaceTags()
932     {
933         evaluate("/** This is a description.\n" +
934                  " * @author me\n" +
935                  " * @version 1.10\n" +
936                  " * @see Spot#run() \n" +
937                  " * @since whenever\n" +
938                  " * @deprecated Use something better than this.\n" +
939                  " */\n" +
940                  "interface TestValidTag {\n" +
941                  "}\n",
942                  new Violation[] {
943                  });
944
945         evaluate("/** This is a description.\n" +
946                  " * @author me\n" +
947                  " * @version 1.10\n" +
948                  " * @throws NullPointerException Impossible because Java doesn't have pointers.\n" +
949                  " * @see Spot#run() \n" +
950                  " * @since whenever\n" +
951                  " * @deprecated Use something better than this.\n" +
952                  " */\n" +
953                  "interface TestValidTag {\n" +
954                  "}\n",
955                  new Violation[] {
956                      new Violation("Tag not valid for interface", 4, 5, 4, 11)
957                  });
958     }
959
960     public void testValidityInnerInterfaceTags()
961     {
962         evaluate("/** This is a description. */\n" +
963                  "interface Outer {\n" +
964                  " /** This is a description.\n" +
965                  " * @author me\n" +
966                  " * @version 1.10\n" +
967                  " * @see Spot#run() \n" +
968                  " * @since whenever\n" +
969                  " * @deprecated Use something better than this.\n" +
970                  " */\n" +
971                  " interface Inner {\n" +
972                  " }\n" +
973                  "}\n",
974                  new Violation[] {
975                  });
976
977         evaluate("/** This is a description. */\n" +
978                  "interface Outer {\n" +
979                  " /** This is a description.\n" +
980                  " * @author me\n" +
981                  " * @version 1.10\n" +
982                  " * @throws NullPointerException Although Java doesn't have pointers.\n" +
983                  " * @see Spot#run() \n" +
984                  " * @since whenever\n" +
985                  " * @deprecated Use something better than this.\n" +
986                  " */\n" +
987                  " interface Inner {\n" +
988                  " }\n" +
989                  "}\n",
990                  new Violation[] {
991                      new Violation("Tag not valid for interface", 6, 9, 6, 15)
992                  });
993     }
994
995     public void testValidityMethodTags()
996     {
997         evaluate("/** This is a description. */\n" +
998                  "class Test {\n" +
999                  " /** This is a description.\n" +
1000                 " * @see Spot#run() \n" +
1001                 " * @since whenever\n" +
1002                 " * @deprecated Use something better than this.\n" +
1003                 " */\n" +
1004                 " void f() {}\n" +
1005                 "}\n",
1006                 new Violation[] {
1007                 });
1008
1009        evaluate("/** This is a description. */\n" +
1010                 "class Test {\n" +
1011                 " /** This is a description.\n" +
1012                 " * @author me\n" +
1013                 " * @version 1.10\n" +
1014                 " * @see Spot#run() \n" +
1015                 " * @since whenever\n" +
1016                 " * @deprecated Use something better than this.\n" +
1017                 " */\n" +
1018                 " void f() {}\n" +
1019                 "}\n",
1020                 new Violation[] {
1021                     new Violation("Tag not valid for method", 4, 9, 4, 15),
1022                     new Violation("Tag not valid for method", 5, 9, 5, 16)
1023                 });
1024    }
1025
1026    public void testValidityCtorTags()
1027    {
1028        evaluate("/** This is a description. */\n" +
1029                 "class Test {\n" +
1030                 " /** This is a description.\n" +
1031                 " * @see Spot#run() \n" +
1032                 " * @since whenever\n" +
1033                 " * @deprecated Use something better than this.\n" +
1034                 " */\n" +
1035                 " Test() {}\n" +
1036                 "}\n",
1037                 new Violation[] {
1038                 });
1039
1040        evaluate("/** This is a description. */\n" +
1041                 "class Test {\n" +
1042                 " /** This is a description.\n" +
1043                 " * @author me\n" +
1044                 " * @version 1.10\n" +
1045                 " * @see Spot#run() \n" +
1046                 " * @since whenever\n" +
1047                 " * @deprecated Use something better than this.\n" +
1048                 " */\n" +
1049                 " Test() {}\n" +
1050                 "}\n",
1051                 new Violation[] {
1052                     new Violation("Tag not valid for constructor", 4, 9, 4, 15),
1053                     new Violation("Tag not valid for constructor", 5, 9, 5, 16)
1054                 });
1055
1056        evaluate("/** This is a description. */\n" +
1057                 "class Test {\n" +
1058                 " /** This is a description.\n" +
1059                 " * @author me\n" +
1060                 " * @version 1.10\n" +
1061                 " * @return Something\n" +
1062                 " * @see Spot#run() \n" +
1063                 " * @since whenever\n" +
1064                 " * @deprecated Use something better than this.\n" +
1065                 " */\n" +
1066                 " Test() {}\n" +
1067                 "}\n",
1068                 new Violation[] {
1069                     new Violation("Tag not valid for constructor", 4, 9, 4, 15),
1070                     new Violation("Tag not valid for constructor", 5, 9, 5, 16),
1071                     new Violation("Tag not valid for constructor", 6, 9, 6, 15)
1072                 });
1073    }
1074
1075    public void testValidityFieldTags()
1076    {
1077        evaluate("/** This is a description. */\n" +
1078                 "class Test {\n" +
1079                 " /** This is a description.\n" +
1080                 " * @see Spot#run() \n" +
1081                 " * @since whenever\n" +
1082                 " * @deprecated Use something better than this.\n" +
1083                 " */\n" +
1084                 " int f;\n" +
1085                 "}\n",
1086                 new Violation[] {
1087                 });
1088
1089        evaluate("/** This is a description. */\n" +
1090                 "class Test {\n" +
1091                 " /** This is a description.\n" +
1092                 " * @author me\n" +
1093                 " * @version 1.10\n" +
1094                 " * @see Spot#run() \n" +
1095                 " * @since whenever\n" +
1096                 " * @deprecated Use something better than this.\n" +
1097                 " */\n" +
1098                 " int f;\n" +
1099                 "}\n",
1100                 new Violation[] {
1101                     new Violation("Tag not valid for field", 4, 9, 4, 15),
1102                     new Violation("Tag not valid for field", 5, 9, 5, 16)
1103                 });
1104    }
1105
1106    // summary sentence length
1107

1108    public void testSummarySufficientLength()
1109    {
1110        evaluate("/** This is a description.\n" +
1111                 " */\n" +
1112                 "class Test {\n" +
1113                 "}\n",
1114                 new Violation[] {
1115                 });
1116    }
1117    
1118    public void testSummaryNoSummarySentence()
1119    {
1120        evaluate("/** \n" +
1121                 " */\n" +
1122                 "class Test {\n" +
1123                 "}\n",
1124                 new Violation[] {
1125                     new Violation(ItemDocAnalyzer.MSG_NO_SUMMARY_SENTENCE, 1, 1, 2, 4)
1126                 });
1127    }
1128    
1129    public void testSummaryNoEndingPeriod()
1130    {
1131        evaluate("/** \n" +
1132                 " * This doesn't have an ending period\n" +
1133                 " */\n" +
1134                 "class Test {\n" +
1135                 "}\n",
1136                 new Violation[] {
1137                     new Violation(ItemDocAnalyzer.MSG_SUMMARY_SENTENCE_DOES_NOT_END_WITH_PERIOD, 2, 5, 2, 38)
1138                 });
1139    }
1140    
1141    public void testSummaryShortSentence()
1142    {
1143        evaluate("/** \n" +
1144                 " * Too short.\n" +
1145                 " */\n" +
1146                 "class Test {\n" +
1147                 "}\n",
1148                 new Violation[] {
1149                     new Violation(ItemDocAnalyzer.MSG_SUMMARY_SENTENCE_TOO_SHORT, 2, 5, 2, 14)
1150                 });
1151
1152        evaluate("/** \n" +
1153                 " * This one too.\n" +
1154                 " */\n" +
1155                 "class Test {\n" +
1156                 "}\n",
1157                 new Violation[] {
1158                     new Violation(ItemDocAnalyzer.MSG_SUMMARY_SENTENCE_TOO_SHORT, 2, 5, 2, 17)
1159                 });
1160
1161        evaluate("/** \n" +
1162                 " * This one too. And it has more text that follows,\n" +
1163                 " * but should not be marked in the offending sentence.\n" +
1164                 " */\n" +
1165                 "class Test {\n" +
1166                 "}\n",
1167                 new Violation[] {
1168                     new Violation(ItemDocAnalyzer.MSG_SUMMARY_SENTENCE_TOO_SHORT, 2, 5, 2, 17)
1169                 });
1170    }
1171
1172    // spelling
1173

1174    public void testSpellingOK()
1175    {
1176        evaluate("/** This is a description.\n" +
1177                 " */\n" +
1178                 "class Test {\n" +
1179                 "}\n",
1180                 new Violation[] {
1181                 });
1182    }
1183
1184    public void testSpellingOneMistake()
1185    {
1186        final String JavaDoc msg = (
1187            "Word 'descriptino' appears to be misspelled. " +
1188            "Closest matches: description, descriptions, descriptor, description's, descriptive, descriptors"
1189            );
1190        evaluate("/** This is a descriptino.\n" +
1191                 " */\n" +
1192                 "class Test {\n" +
1193                 "}\n",
1194                 new Violation[] {
1195                     new Violation(msg, 1, 15, 1, 25)
1196                 });
1197    }
1198
1199    public void testSpellingTwoMistakes()
1200    {
1201        final String JavaDoc msg0 = (
1202            "Word 'exampel' appears to be misspelled. " +
1203            "Closest matches: example, expel, enamel, exam, examen, exampled"
1204            );
1205
1206        final String JavaDoc msg1 = (
1207            "Word 'badd' appears to be misspelled. " +
1208            "Closest matches: bad, baddy, ba, ba, badder, baddie"
1209            );
1210
1211        evaluate("/** This is an exampel of\n" +
1212                 " * badd spelling.\n" +
1213                 " */\n" +
1214                 "class Test {\n" +
1215                 "}\n",
1216                 new Violation[] {
1217                     new Violation(msg0, 1, 16, 1, 22),
1218                     new Violation(msg1, 2, 5, 2, 8)
1219                 });
1220    }
1221
1222    public void testSpellingEgregiousMistake()
1223    {
1224        evaluate("/** This is an egreejish misspelling.\n" +
1225                 " */\n" +
1226                 "class Test {\n" +
1227                 "}\n",
1228                 new Violation[] {
1229                     new Violation("Word 'egreejish' appears to be misspelled. No close matches", 1, 16, 1, 24)
1230                 });
1231    }
1232
1233}
1234
Popular Tags