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