KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > net > sourceforge > pmd > ast > FieldDeclTest


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package test.net.sourceforge.pmd.ast;
5
6 import net.sourceforge.pmd.ast.ASTFieldDeclaration;
7 import test.net.sourceforge.pmd.testframework.ParserTst;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.Set JavaDoc;
11
12 public class FieldDeclTest extends ParserTst {
13     public String JavaDoc makeAccessJavaCode(String JavaDoc access[]) {
14         String JavaDoc result = "public class Test { ";
15         for (int i = 0; i < access.length; i++) {
16             result += access[i] + " ";
17         }
18         return result + " int j; }";
19     }
20
21     public ASTFieldDeclaration getFieldDecl(String JavaDoc access[]) throws Throwable JavaDoc {
22         Set JavaDoc fields = getNodes(ASTFieldDeclaration.class, makeAccessJavaCode(access));
23
24         assertEquals("Wrong number of fields", 1, fields.size());
25         Iterator JavaDoc i = fields.iterator();
26         return (ASTFieldDeclaration) i.next();
27     }
28
29     public void testPublic() throws Throwable JavaDoc {
30         String JavaDoc access[] = {"public"};
31         ASTFieldDeclaration afd = getFieldDecl(access);
32         assertTrue("Expecting field to be public.", afd.isPublic());
33     }
34
35     public void testProtected() throws Throwable JavaDoc {
36         String JavaDoc access[] = {"protected"};
37         ASTFieldDeclaration afd = getFieldDecl(access);
38         assertTrue("Expecting field to be protected.", afd.isProtected());
39     }
40
41     public void testPrivate() throws Throwable JavaDoc {
42         String JavaDoc access[] = {"private"};
43         ASTFieldDeclaration afd = getFieldDecl(access);
44         assertTrue("Expecting field to be private.", afd.isPrivate());
45     }
46
47     public void testStatic() throws Throwable JavaDoc {
48         String JavaDoc access[] = {"private", "static"};
49         ASTFieldDeclaration afd = getFieldDecl(access);
50         assertTrue("Expecting field to be static.", afd.isStatic());
51         assertTrue("Expecting field to be private.", afd.isPrivate());
52     }
53
54     public void testFinal() throws Throwable JavaDoc {
55         String JavaDoc access[] = {"public", "final"};
56         ASTFieldDeclaration afd = getFieldDecl(access);
57         assertTrue("Expecting field to be final.", afd.isFinal());
58         assertTrue("Expecting field to be public.", afd.isPublic());
59     }
60
61     public void testTransient() throws Throwable JavaDoc {
62         String JavaDoc access[] = {"private", "transient"};
63         ASTFieldDeclaration afd = getFieldDecl(access);
64         assertTrue("Expecting field to be private.", afd.isPrivate());
65         assertTrue("Expecting field to be transient.", afd.isTransient());
66     }
67
68     public void testVolatile() throws Throwable JavaDoc {
69         String JavaDoc access[] = {"private", "volatile"};
70         ASTFieldDeclaration afd = getFieldDecl(access);
71         assertTrue("Expecting field to be volatile.", afd.isVolatile());
72         assertTrue("Expecting field to be private.", afd.isPrivate());
73     }
74 }
75
Popular Tags