-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
SourceRootTest.java
54 lines (43 loc) · 2.17 KB
/
SourceRootTest.java
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
43
44
45
46
47
48
49
50
51
52
53
54
package com.github.javaparser.utils;
import com.github.javaparser.ParseProblemException;
import com.github.javaparser.ParseResult;
import com.github.javaparser.ParserConfiguration;
import com.github.javaparser.ast.CompilationUnit;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class SourceRootTest {
private final Path root = CodeGenerationUtils.mavenModuleRoot(SourceRootTest.class).resolve("src/test/resources/com/github/javaparser/utils/");
private final SourceRoot sourceRoot = new SourceRoot(root);
@Before
public void before() {
sourceRoot.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.BLEEDING_EDGE);
}
@Test
public void parseTestDirectory() throws IOException {
List<ParseResult<CompilationUnit>> parseResults = sourceRoot.tryToParse();
List<CompilationUnit> units = sourceRoot.getCompilationUnits();
assertEquals(2, units.size());
assertTrue(units.stream().allMatch(unit -> !unit.getTypes().isEmpty() || unit.getModule().isPresent()));
assertTrue(parseResults.stream().noneMatch(cu -> cu.getResult().get().getStorage().get().getPath().toString().contains("source.root")));
}
@Test(expected = IllegalArgumentException.class)
public void fileAsRootIsNotAllowed() {
Path path = CodeGenerationUtils.classLoaderRoot(SourceRootTest.class).resolve("com/github/javaparser/utils/Bla.java");
new SourceRoot(path);
}
@Test
public void dotsInRootDirectoryAreAllowed() throws IOException {
Path path = CodeGenerationUtils.mavenModuleRoot(SourceRootTest.class).resolve("src/test/resources/com/github/javaparser/utils/source.root");
new SourceRoot(path).tryToParse();
}
@Test(expected = ParseProblemException.class)
public void dotsInPackageAreNotAllowed() {
Path path = CodeGenerationUtils.mavenModuleRoot(SourceRootTest.class).resolve("src/test/resources/com/github/javaparser/utils");
new SourceRoot(path).parse("source.root", "Y.java");
}
}