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