View Javadoc

    1   /*
    2    * Created on Jan 19, 2005
    3    *
    4    * $Id$
    5    */
    6   package net.sourceforge.pmd.ast;
    7
    8   import static org.junit.Assert.assertEquals;
    9   import static org.junit.Assert.assertNull;
    10  import net.sourceforge.pmd.PMD;
    11  import net.sourceforge.pmd.lang.java.ast.ASTThrowStatement;
    12  import net.sourceforge.pmd.testframework.ParserTst;
    13
    14  import org.junit.Test;
    15
    16
    17  /**
    18   * @author mgriffa
    19   */
    20  public class ASTThrowStatementTest extends ParserTst {
    21
    22      @Test
    23      public final void testGetFirstASTNameImageNull() throws Throwable {
    24          ASTThrowStatement t = getNodes(ASTThrowStatement.class, NULL_NAME).iterator().next();
    25          assertNull(t.getFirstClassOrInterfaceTypeImage());
    26      }
    27
    28      @Test
    29      public final void testGetFirstASTNameImageNew() throws Throwable {
    30          ASTThrowStatement t = getNodes(ASTThrowStatement.class, OK_NAME).iterator().next();
    31          assertEquals("FooException", t.getFirstClassOrInterfaceTypeImage());
    32      }
    33
    34      private static final String NULL_NAME =
    35              "public class Test {" + PMD.EOL +
    36              "  void bar() {" + PMD.EOL +
    37              "   throw e;" + PMD.EOL +
    38              "  }" + PMD.EOL +
    39              "}";
    40
    41      private static final String OK_NAME =
    42              "public class Test {" + PMD.EOL +
    43              "  void bar() {" + PMD.EOL +
    44              "   throw new FooException();" + PMD.EOL +
    45              "  }" + PMD.EOL +
    46              "}";
    47
    48      public static junit.framework.Test suite() {
    49          return new junit.framework.JUnit4TestAdapter(ASTThrowStatementTest.class);
    50      }
    51  }