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 static org.junit.Assert.assertFalse;
7 import static org.junit.Assert.assertTrue;
8 import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
9 import net.sourceforge.pmd.ast.AccessNode;
10
11 import org.junit.Test;
12
13 import test.net.sourceforge.pmd.testframework.ParserTst;
14
15 import java.util.Set;
16
17 public class AccessNodeTest extends ParserTst {
18
19 @Test
20 public void testModifiersOnClassDecl() throws Throwable {
21 Set ops = getNodes(ASTClassOrInterfaceDeclaration.class, TEST1);
22 assertTrue(((ASTClassOrInterfaceDeclaration) (ops.iterator().next())).isPublic());
23 }
24
25 private static final String TEST1 =
26 "public class Foo {}";
27
28
29 @Test
30 public void testStatic() {
31 AccessNode node = new AccessNode(1);
32 assertFalse("Node should default to not static.", node.isStatic());
33 node.setStatic();
34 assertTrue("Node set to static, not static.", node.isStatic());
35 }
36
37 @Test
38 public void testPublic() {
39 AccessNode node = new AccessNode(1);
40 assertFalse("Node should default to not public.", node.isPublic());
41 node.setPublic();
42 assertTrue("Node set to public, not public.", node.isPublic());
43 }
44
45 @Test
46 public void testProtected() {
47 AccessNode node = new AccessNode(1);
48 assertFalse("Node should default to not protected.", node.isProtected());
49 node.setProtected();
50 assertTrue("Node set to protected, not protected.", node.isProtected());
51 }
52
53 @Test
54 public void testPrivate() {
55 AccessNode node = new AccessNode(1);
56 assertFalse("Node should default to not private.", node.isPrivate());
57 node.setPrivate();
58 assertTrue("Node set to private, not private.", node.isPrivate());
59 }
60
61 @Test
62 public void testFinal() {
63 AccessNode node = new AccessNode(1);
64 assertFalse("Node should default to not final.", node.isFinal());
65 node.setFinal();
66 assertTrue("Node set to final, not final.", node.isFinal());
67 }
68
69 @Test
70 public void testSynchronized() {
71 AccessNode node = new AccessNode(1);
72 assertFalse("Node should default to not synchronized.", node.isSynchronized());
73 node.setSynchronized();
74 assertTrue("Node set to synchronized, not synchronized.", node.isSynchronized());
75 }
76
77 @Test
78 public void testVolatile() {
79 AccessNode node = new AccessNode(1);
80 assertFalse("Node should default to not volatile.", node.isVolatile());
81 node.setVolatile();
82 assertTrue("Node set to volatile, not volatile.", node.isVolatile());
83 }
84
85 @Test
86 public void testTransient() {
87 AccessNode node = new AccessNode(1);
88 assertFalse("Node should default to not transient.", node.isTransient());
89 node.setTransient();
90 assertTrue("Node set to transient, not transient.", node.isTransient());
91 }
92
93 @Test
94 public void testNative() {
95 AccessNode node = new AccessNode(1);
96 assertFalse("Node should default to not native.", node.isNative());
97 node.setNative();
98 assertTrue("Node set to native, not native.", node.isNative());
99 }
100
101 @Test
102 public void testAbstract() {
103 AccessNode node = new AccessNode(1);
104 assertFalse("Node should default to not abstract.", node.isAbstract());
105 node.setAbstract();
106 assertTrue("Node set to abstract, not abstract.", node.isAbstract());
107 }
108
109 @Test
110 public void testStrict() {
111 AccessNode node = new AccessNode(1);
112 assertFalse("Node should default to not strict.", node.isStrictfp());
113 node.setStrictfp();
114 assertTrue("Node set to strict, not strict.", node.isStrictfp());
115 }
116
117 @Test
118 public void testPackagePrivate() {
119 AccessNode node = new AccessNode(1);
120 assertTrue("Node should default to package private.", node.isPackagePrivate());
121 node.setPrivate();
122 assertFalse("Node set to private, still package private.", node.isPackagePrivate());
123 node = new AccessNode(1);
124 node.setPublic();
125 assertFalse("Node set to public, still package private.", node.isPackagePrivate());
126 node = new AccessNode(1);
127 node.setProtected();
128 assertFalse("Node set to protected, still package private.", node.isPackagePrivate());
129 }
130
131 public static junit.framework.Test suite() {
132 return new junit.framework.JUnit4TestAdapter(AccessNodeTest.class);
133 }
134 }