diff options
author | George Fraser <george@fivetran.com> | 2018-12-30 14:16:41 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2018-12-30 14:16:41 -0800 |
commit | f58c515babe59c527897793c2e410882aa233b2e (patch) | |
tree | 16ce2d833c81f5c991c7530fbd94758192f02fc5 /src/test/java | |
parent | 9b3e6f044d3a37b4d27734ddee9e7bf1aa1f9c7b (diff) | |
download | java-language-server-f58c515babe59c527897793c2e410882aa233b2e.zip |
Keep track of workspace java files
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/javacs/JavaCompilerServiceTest.java | 19 | ||||
-rw-r--r-- | src/test/java/org/javacs/ParserFixImportsTest.java | 14 | ||||
-rw-r--r-- | src/test/java/org/javacs/ParserTest.java | 5 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java index 7b8d20c..8011789 100644 --- a/src/test/java/org/javacs/JavaCompilerServiceTest.java +++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java @@ -8,12 +8,14 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Set; import java.util.logging.Logger; import java.util.stream.Collectors; import javax.lang.model.element.Element; @@ -28,7 +30,10 @@ public class JavaCompilerServiceTest { private JavaCompilerService compiler = new JavaCompilerService( - Collections.singleton(resourcesDir()), Collections.emptySet(), Collections.emptySet()); + Collections.singleton(resourcesDir()), + JavaCompilerServiceTest::allJavaFiles, + Collections.emptySet(), + Collections.emptySet()); static Path resourcesDir() { try { @@ -38,6 +43,16 @@ public class JavaCompilerServiceTest { } } + static Set<Path> allJavaFiles() { + try { + return Files.walk(resourcesDir()) + .filter(f -> f.getFileName().toString().endsWith(".java")) + .collect(Collectors.toSet()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + private String contents(String resourceFile) { try (var in = JavaCompilerServiceTest.class.getResourceAsStream(resourceFile)) { return new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n")); @@ -233,7 +248,7 @@ public class JavaCompilerServiceTest { var to = compiler.compileFocus(resourceUri(file), contents(file), 6, 13).element(); var possible = compiler.potentialReferences(to); assertThat( - "GotoDefinition.java can have refernces to itself", + "GotoDefinition.java can have references to itself", possible, hasItem(hasToString(endsWith("/GotoDefinition.java")))); diff --git a/src/test/java/org/javacs/ParserFixImportsTest.java b/src/test/java/org/javacs/ParserFixImportsTest.java index eddd105..e935962 100644 --- a/src/test/java/org/javacs/ParserFixImportsTest.java +++ b/src/test/java/org/javacs/ParserFixImportsTest.java @@ -3,13 +3,21 @@ package org.javacs; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import java.util.Collections; +import java.io.IOException; +import java.nio.file.Files; +import java.util.stream.Collectors; import org.junit.Test; public class ParserFixImportsTest { @Test - public void findExistingImports() { - var find = Parser.existingImports(Collections.singleton(JavaCompilerServiceTest.resourcesDir())); + public void findExistingImports() throws IOException { + var allJavaFiles = + Files.walk(JavaCompilerServiceTest.resourcesDir()) + .filter(f -> f.getFileName().toString().endsWith(".java")) + .collect(Collectors.toSet()); + assertThat(allJavaFiles, not(empty())); + + var find = Parser.existingImports(allJavaFiles); assertThat(find.classes, hasItem("java.util.List")); assertThat(find.packages, hasItem("java.util")); } diff --git a/src/test/java/org/javacs/ParserTest.java b/src/test/java/org/javacs/ParserTest.java index 8d1419d..93ac5ed 100644 --- a/src/test/java/org/javacs/ParserTest.java +++ b/src/test/java/org/javacs/ParserTest.java @@ -4,7 +4,7 @@ import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import java.nio.file.Paths; -import java.util.Set; +import java.util.Collections; import org.junit.Test; public class ParserTest { @@ -58,7 +58,8 @@ public class ParserTest { public void findExistingImports() { var rel = Paths.get("src", "org", "javacs", "doimport"); var dir = LanguageServerFixture.DEFAULT_WORKSPACE_ROOT.resolve(rel); - var existing = Parser.existingImports(Set.of(dir)); + var sourcePath = new SourcePath(Collections.singleton(dir)); + var existing = Parser.existingImports(sourcePath.allJavaFiles()); assertThat(existing.classes, hasItems("java.util.List")); assertThat(existing.packages, hasItems("java.util", "java.io")); } |