KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > net > sourceforge > pmd > ast > ASTImportDeclarationTest


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.PMD;
7 import net.sourceforge.pmd.TargetJDK1_5;
8 import net.sourceforge.pmd.ast.ASTImportDeclaration;
9 import net.sourceforge.pmd.ast.ParseException;
10 import test.net.sourceforge.pmd.testframework.ParserTst;
11
12 import java.util.Set JavaDoc;
13
14 public class ASTImportDeclarationTest extends ParserTst {
15
16     public void testImportOnDemand() throws Throwable JavaDoc {
17         Set JavaDoc ops = getNodes(ASTImportDeclaration.class, TEST1);
18         assertTrue(((ASTImportDeclaration) (ops.iterator().next())).isImportOnDemand());
19     }
20
21     public void testGetImportedNameNode() throws Throwable JavaDoc {
22         ASTImportDeclaration i = (ASTImportDeclaration) (getNodes(ASTImportDeclaration.class, TEST2).iterator().next());
23         assertEquals("foo.bar.Baz", i.getImportedName());
24     }
25
26     public void testStaticImport() throws Throwable JavaDoc {
27         Set JavaDoc ops = getNodes(new TargetJDK1_5(), ASTImportDeclaration.class, TEST3);
28         ASTImportDeclaration i = (ASTImportDeclaration) (ops.iterator().next());
29         assertTrue(i.isStatic());
30     }
31
32     public void testStaticImportFailsWithJDK14() throws Throwable JavaDoc {
33         try {
34             getNodes(ASTImportDeclaration.class, TEST3);
35             fail("Should have failed to parse a static import in JDK 1.4 mode");
36         } catch (ParseException pe) {
37             // cool
38
}
39     }
40
41     private static final String JavaDoc TEST1 =
42             "import foo.bar.*;" + PMD.EOL +
43             "public class Foo {}";
44
45     private static final String JavaDoc TEST2 =
46             "import foo.bar.Baz;" + PMD.EOL +
47             "public class Foo {}";
48
49     private static final String JavaDoc TEST3 =
50             "import static foo.bar.Baz;" + PMD.EOL +
51             "public class Foo {}";
52
53 }
54
Popular Tags