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