001: /**
002: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
003: */package test.net.sourceforge.pmd.ast;
004:
005: import static org.junit.Assert.assertFalse;
006: import static org.junit.Assert.assertTrue;
007: import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
008: import net.sourceforge.pmd.ast.AccessNode;
009:
010: import org.junit.Test;
011:
012: import test.net.sourceforge.pmd.testframework.ParserTst;
013:
014: import java.util.Set;
015:
016: public class AccessNodeTest extends ParserTst {
017:
018: @Test
019: public void testModifiersOnClassDecl() throws Throwable {
020: Set ops = getNodes(ASTClassOrInterfaceDeclaration.class, TEST1);
021: assertTrue(((ASTClassOrInterfaceDeclaration) (ops.iterator()
022: .next())).isPublic());
023: }
024:
025: private static final String TEST1 = "public class Foo {}";
026:
027: @Test
028: public void testStatic() {
029: AccessNode node = new AccessNode(1);
030: assertFalse("Node should default to not static.", node
031: .isStatic());
032: node.setStatic();
033: assertTrue("Node set to static, not static.", node.isStatic());
034: }
035:
036: @Test
037: public void testPublic() {
038: AccessNode node = new AccessNode(1);
039: assertFalse("Node should default to not public.", node
040: .isPublic());
041: node.setPublic();
042: assertTrue("Node set to public, not public.", node.isPublic());
043: }
044:
045: @Test
046: public void testProtected() {
047: AccessNode node = new AccessNode(1);
048: assertFalse("Node should default to not protected.", node
049: .isProtected());
050: node.setProtected();
051: assertTrue("Node set to protected, not protected.", node
052: .isProtected());
053: }
054:
055: @Test
056: public void testPrivate() {
057: AccessNode node = new AccessNode(1);
058: assertFalse("Node should default to not private.", node
059: .isPrivate());
060: node.setPrivate();
061: assertTrue("Node set to private, not private.", node
062: .isPrivate());
063: }
064:
065: @Test
066: public void testFinal() {
067: AccessNode node = new AccessNode(1);
068: assertFalse("Node should default to not final.", node.isFinal());
069: node.setFinal();
070: assertTrue("Node set to final, not final.", node.isFinal());
071: }
072:
073: @Test
074: public void testSynchronized() {
075: AccessNode node = new AccessNode(1);
076: assertFalse("Node should default to not synchronized.", node
077: .isSynchronized());
078: node.setSynchronized();
079: assertTrue("Node set to synchronized, not synchronized.", node
080: .isSynchronized());
081: }
082:
083: @Test
084: public void testVolatile() {
085: AccessNode node = new AccessNode(1);
086: assertFalse("Node should default to not volatile.", node
087: .isVolatile());
088: node.setVolatile();
089: assertTrue("Node set to volatile, not volatile.", node
090: .isVolatile());
091: }
092:
093: @Test
094: public void testTransient() {
095: AccessNode node = new AccessNode(1);
096: assertFalse("Node should default to not transient.", node
097: .isTransient());
098: node.setTransient();
099: assertTrue("Node set to transient, not transient.", node
100: .isTransient());
101: }
102:
103: @Test
104: public void testNative() {
105: AccessNode node = new AccessNode(1);
106: assertFalse("Node should default to not native.", node
107: .isNative());
108: node.setNative();
109: assertTrue("Node set to native, not native.", node.isNative());
110: }
111:
112: @Test
113: public void testAbstract() {
114: AccessNode node = new AccessNode(1);
115: assertFalse("Node should default to not abstract.", node
116: .isAbstract());
117: node.setAbstract();
118: assertTrue("Node set to abstract, not abstract.", node
119: .isAbstract());
120: }
121:
122: @Test
123: public void testStrict() {
124: AccessNode node = new AccessNode(1);
125: assertFalse("Node should default to not strict.", node
126: .isStrictfp());
127: node.setStrictfp();
128: assertTrue("Node set to strict, not strict.", node.isStrictfp());
129: }
130:
131: @Test
132: public void testPackagePrivate() {
133: AccessNode node = new AccessNode(1);
134: assertTrue("Node should default to package private.", node
135: .isPackagePrivate());
136: node.setPrivate();
137: assertFalse("Node set to private, still package private.", node
138: .isPackagePrivate());
139: node = new AccessNode(1);
140: node.setPublic();
141: assertFalse("Node set to public, still package private.", node
142: .isPackagePrivate());
143: node = new AccessNode(1);
144: node.setProtected();
145: assertFalse("Node set to protected, still package private.",
146: node.isPackagePrivate());
147: }
148:
149: public static junit.framework.Test suite() {
150: return new junit.framework.JUnit4TestAdapter(
151: AccessNodeTest.class);
152: }
153: }
|