KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.incava.doctorj;
2
3 import junit.framework.TestCase;
4 import org.incava.analysis.Violation;
5
6
7 public class TestFieldDocAnalyzer extends Tester
8 {
9     public TestFieldDocAnalyzer(String JavaDoc name)
10     {
11         super(name);
12     }
13
14     public void testSerialFieldOK()
15     {
16         evaluate("/** This is a description. */\n" +
17                  "class Test {\n" +
18                  " /** This is a description.\n" +
19                  " * @serialField one int What one is." +
20                  " */\n" +
21                  " ObjectStreamField[] serialPersistentFields = { \n" +
22                  " new ObjectStreamField(\"one\", Integer.TYPE) \n" +
23                  " };\n" +
24                  "}\n",
25                  new Violation[] {
26                  });
27     }
28
29     public void testSerialFieldNoDoc()
30     {
31         evaluate("/** This is a description. */\n" +
32                  "class Test {\n" +
33                  " /** This is a description.\n" +
34                  " * @serialField" +
35                  " */\n" +
36                  " ObjectStreamField[] serialPersistentFields = { \n" +
37                  " new ObjectStreamField(\"one\", Integer.TYPE) \n" +
38                  " };\n" +
39                  "}\n",
40                  new Violation[] {
41                      new Violation(FieldDocAnalyzer.MSG_SERIALFIELD_WITHOUT_NAME_TYPE_AND_DESCRIPTION, 4, 9, 4, 20)
42                  });
43
44         evaluate("/** This is a description. */\n" +
45                  "class Test {\n" +
46                  " /** This is a description.\n" +
47                  " * @serialField " +
48                  " */\n" +
49                  " ObjectStreamField[] serialPersistentFields = { \n" +
50                  " new ObjectStreamField(\"one\", Integer.TYPE) \n" +
51                  " };\n" +
52                  "}\n",
53                  new Violation[] {
54                      new Violation(FieldDocAnalyzer.MSG_SERIALFIELD_WITHOUT_NAME_TYPE_AND_DESCRIPTION, 4, 9, 4, 20)
55                  });
56     }
57
58     public void testSerialFieldNoDescription()
59     {
60         evaluate("/** This is a description. */\n" +
61                  "class Test {\n" +
62                  " /** This is a description.\n" +
63                  " * @serialField one int " +
64                  " */\n" +
65                  " ObjectStreamField[] serialPersistentFields = { \n" +
66                  " new ObjectStreamField(\"one\", Integer.TYPE) \n" +
67                  " };\n" +
68                  "}\n",
69                  new Violation[] {
70                      new Violation(FieldDocAnalyzer.MSG_SERIALFIELD_WITHOUT_DESCRIPTION, 4, 22, 4, 29)
71                  });
72     }
73
74     public void testSerialFieldNoTypeNorDescription()
75     {
76         evaluate("/** This is a description. */\n" +
77                  "class Test {\n" +
78                  " /** This is a description.\n" +
79                  " * @serialField one " +
80                  " */\n" +
81                  " ObjectStreamField[] serialPersistentFields = { \n" +
82                  " new ObjectStreamField(\"one\", Integer.TYPE) \n" +
83                  " };\n" +
84                  "}\n",
85                  new Violation[] {
86                      new Violation(FieldDocAnalyzer.MSG_SERIALFIELD_WITHOUT_TYPE_AND_DESCRIPTION, 4, 22, 4, 25)
87                  });
88     }
89     
90 }
91
Popular Tags