KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.incava.doctorj;
2
3 import junit.framework.TestCase;
4 import org.incava.analysis.Violation;
5
6
7 public class TestMethodDocAnalyzer extends Tester
8 {
9     public TestMethodDocAnalyzer(String JavaDoc name)
10     {
11         super(name);
12     }
13
14     public void testReturnOK()
15     {
16         evaluate("/** This is a description. */\n" +
17                  "class Test {\n" +
18                  " /** This is a description.\n" +
19                  " * @return What this method returns.\n" +
20                  " */\n" +
21                  " int f() { return 1; }\n" +
22                  "}\n",
23                  new Violation[] {
24                  });
25     }
26
27     public void testReturnFromVoid()
28     {
29         evaluate("/** This is a description. */\n" +
30                  "class Test {\n" +
31                  " /** This is a description.\n" +
32                  " * @return \n" +
33                  " */\n" +
34                  " void f() {}\n" +
35                  "}\n",
36                  new Violation[] {
37                      new Violation(MethodDocAnalyzer.MSG_RETURN_FOR_VOID_METHOD, 4, 9, 4, 15)
38                  });
39     }
40
41     public void testReturnUndescribed()
42     {
43         evaluate("/** This is a description. */\n" +
44                  "class Test {\n" +
45                  " /** This is a description.\n" +
46                  " * @return \n" +
47                  " */\n" +
48                  " int f() { return 1; }\n" +
49                  "}\n",
50                  new Violation[] {
51                      new Violation(MethodDocAnalyzer.MSG_RETURN_WITHOUT_DESCRIPTION, 4, 9, 4, 15)
52                  });
53     }
54
55     public void testReturnTypeUsed()
56     {
57         evaluate("/** This is a description. */\n" +
58                  "class Test {\n" +
59                  " /** This is a description.\n" +
60                  " * @return int This returns an integer.\n" +
61                  " */\n" +
62                  " int f() { return 1; }\n" +
63                  "}\n",
64                  new Violation[] {
65                      new Violation(MethodDocAnalyzer.MSG_RETURN_TYPE_USED, 4, 17, 4, 19)
66                  });
67     }
68
69     public void testJava15OK()
70     {
71         evaluate("/** This is a description. */\n" +
72                  "class Test {\n" +
73                  " /**\n" +
74                  " * Clones an array within the specified bounds.\n" +
75                  " * This method assumes that a is an array.\n" +
76                  " * @param a This is the first parameter.\n" +
77                  " * @param from This is the second parameter.\n" +
78                  " * @param to This is the third parameter.\n" +
79                  " */\n" +
80                  " private static <T> T[] cloneSubarray(T[] a, int from, int to) {\n" +
81                  " int n = to - from;\n" +
82                  " T[] result = (T[])Array.newInstance(a.getClass().getComponentType(), n);\n" +
83                  " System.arraycopy(a, from, result, 0, n);\n" +
84                  " return result;\n" +
85                  " }\n" +
86                  "}\n",
87                  new Violation[] {
88                  },
89                  "1.5");
90         
91     }
92     
93 }
94
Popular Tags