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