01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package test.net.sourceforge.pmd.ast;
04:
05: import static org.junit.Assert.assertEquals;
06: import static org.junit.Assert.assertTrue;
07:
08: import java.util.Set;
09:
10: import net.sourceforge.pmd.PMD;
11: import net.sourceforge.pmd.TargetJDK1_4;
12: import net.sourceforge.pmd.ast.ASTImportDeclaration;
13: import net.sourceforge.pmd.ast.ParseException;
14:
15: import org.junit.Test;
16:
17: import test.net.sourceforge.pmd.testframework.ParserTst;
18:
19: public class ASTImportDeclarationTest extends ParserTst {
20:
21: @Test
22: public void testImportOnDemand() throws Throwable {
23: Set<ASTImportDeclaration> ops = getNodes(
24: ASTImportDeclaration.class, TEST1);
25: assertTrue(ops.iterator().next().isImportOnDemand());
26: }
27:
28: @Test
29: public void testGetImportedNameNode() throws Throwable {
30: ASTImportDeclaration i = getNodes(ASTImportDeclaration.class,
31: TEST2).iterator().next();
32: assertEquals("foo.bar.Baz", i.getImportedName());
33: }
34:
35: @Test
36: public void testStaticImport() throws Throwable {
37: Set<ASTImportDeclaration> ops = getNodes(
38: ASTImportDeclaration.class, TEST3);
39: ASTImportDeclaration i = ops.iterator().next();
40: assertTrue(i.isStatic());
41: }
42:
43: @Test(expected=ParseException.class)
44: public void testStaticImportFailsWithJDK14() throws Throwable {
45: getNodes(new TargetJDK1_4(), ASTImportDeclaration.class, TEST3);
46: }
47:
48: private static final String TEST1 = "import foo.bar.*;" + PMD.EOL
49: + "public class Foo {}";
50:
51: private static final String TEST2 = "import foo.bar.Baz;" + PMD.EOL
52: + "public class Foo {}";
53:
54: private static final String TEST3 = "import static foo.bar.Baz;"
55: + PMD.EOL + "public class Foo {}";
56:
57: public static junit.framework.Test suite() {
58: return new junit.framework.JUnit4TestAdapter(
59: ASTImportDeclarationTest.class);
60: }
61: }
|