aboutsummaryrefslogtreecommitdiffstats
path: root/javaparser-testing/src/test/java/com/github/javaparser/ast/imports/ImportDeclarationTest.java
blob: eac28289e8f6c3d9222343bd90a86fcf8bdd5099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.github.javaparser.ast.imports;

import com.github.javaparser.JavaParser;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ImportDeclarationTest {
    @Test
    public void singleTypeImportDeclaration() {
        ImportDeclaration importDeclaration = JavaParser.parseImport("import a.b.c.X;");
        SingleTypeImportDeclaration i = (SingleTypeImportDeclaration) importDeclaration;
        assertEquals("a.b.c.X", i.getType().toString());
    }

    @Test
    public void typeImportOnDemandDeclaration() {
        ImportDeclaration importDeclaration = JavaParser.parseImport("import a.b.c.D.*;");
        TypeImportOnDemandDeclaration i = (TypeImportOnDemandDeclaration) importDeclaration;
        assertEquals("a.b.c.D", i.getName().toString());
        assertEquals("D", i.getName().getIdentifier());
    }

    @Test
    public void singleStaticImportDeclaration() {
        ImportDeclaration importDeclaration = JavaParser.parseImport("import static a.b.c.X.def;");
        SingleStaticImportDeclaration i = (SingleStaticImportDeclaration) importDeclaration;
        assertEquals("a.b.c.X", i.getType().toString());
        assertEquals("def", i.getStaticMember());
    }

    @Test
    public void staticImportOnDemandDeclaration() {
        ImportDeclaration importDeclaration = JavaParser.parseImport("import static a.b.c.X.*;");
        StaticImportOnDemandDeclaration i = (StaticImportOnDemandDeclaration) importDeclaration;
        assertEquals("X", i.getType().getNameAsString());
        assertEquals("c", i.getType().getScope().get().getNameAsString());
        assertEquals("b", i.getType().getScope().get().getScope().get().getNameAsString());
        assertEquals("a", i.getType().getScope().get().getScope().get().getScope().get().getNameAsString());
    }

}