summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2019-01-08 19:22:45 -0800
committerGeorge Fraser <george@fivetran.com>2019-01-08 19:22:45 -0800
commit727bd8341afc689c842385a234647b8f7b22de21 (patch)
tree73230e098d2a6e72fc72901f4363b46530433f15 /src/test
parent46e72551e73f1de2417102fd3d7fbc358a42cfa6 (diff)
downloadjava-language-server-727bd8341afc689c842385a234647b8f7b22de21.zip
Eliminate SourcePath, docpath isn't quite working
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/javacs/BenchmarkPruner.java10
-rw-r--r--src/test/java/org/javacs/CompletionsBase.java3
-rw-r--r--src/test/java/org/javacs/CompletionsTest.java13
-rw-r--r--src/test/java/org/javacs/FileStoreTest.java23
-rw-r--r--src/test/java/org/javacs/FindResource.java2
-rw-r--r--src/test/java/org/javacs/JavaCompilerServiceTest.java35
-rw-r--r--src/test/java/org/javacs/ParserTest.java4
-rw-r--r--src/test/java/org/javacs/SourceFileManagerTest.java8
8 files changed, 42 insertions, 56 deletions
diff --git a/src/test/java/org/javacs/BenchmarkPruner.java b/src/test/java/org/javacs/BenchmarkPruner.java
index 1daf169..9ad432a 100644
--- a/src/test/java/org/javacs/BenchmarkPruner.java
+++ b/src/test/java/org/javacs/BenchmarkPruner.java
@@ -2,7 +2,6 @@ package org.javacs;
import java.io.IOException;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
@@ -14,7 +13,6 @@ import org.openjdk.jmh.annotations.*;
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
public class BenchmarkPruner {
- private static Path sourceRoot = Paths.get("src/main/java").normalize();
private static List<SourceFileObject> files = files(false);
private static List<SourceFileObject> pruned = files(true);
@@ -39,13 +37,7 @@ public class BenchmarkPruner {
}
private static JavaCompilerService createCompiler() {
- return new JavaCompilerService(
- Collections.singleton(sourceRoot),
- () -> {
- throw new RuntimeException("Unimplemented");
- },
- Collections.emptySet(),
- Collections.emptySet());
+ return new JavaCompilerService(Collections.emptySet(), Collections.emptySet());
}
@Benchmark
diff --git a/src/test/java/org/javacs/CompletionsBase.java b/src/test/java/org/javacs/CompletionsBase.java
index 1a6b161..e7ca7b9 100644
--- a/src/test/java/org/javacs/CompletionsBase.java
+++ b/src/test/java/org/javacs/CompletionsBase.java
@@ -2,14 +2,11 @@ package org.javacs;
import com.google.gson.Gson;
import java.util.*;
-import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.javacs.lsp.*;
public class CompletionsBase {
- protected static final Logger LOG = Logger.getLogger("main");
-
protected static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer();
protected Set<String> insertTemplate(String file, int row, int column) {
diff --git a/src/test/java/org/javacs/CompletionsTest.java b/src/test/java/org/javacs/CompletionsTest.java
index 5a53130..f036079 100644
--- a/src/test/java/org/javacs/CompletionsTest.java
+++ b/src/test/java/org/javacs/CompletionsTest.java
@@ -9,7 +9,6 @@ import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.stream.Collectors;
import org.javacs.lsp.*;
-import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -17,11 +16,6 @@ public class CompletionsTest extends CompletionsBase {
// TODO rename Autocomplete Complete because Autocomplete is long and ugly
- @Before
- public void setup() {
- FileStore.reset();
- }
-
@Test
public void staticMember() {
var file = "/org/javacs/example/AutocompleteStaticMember.java";
@@ -869,6 +863,13 @@ public class CompletionsTest extends CompletionsBase {
assertThat(suggestions, hasItem(containsString("NewlyCreatedFile")));
} finally {
Files.delete(file);
+ // Send a 'file deleted' notification
+ var deleted = new FileEvent();
+ deleted.uri = file.toUri();
+ deleted.type = FileChangeType.Deleted;
+ var changes = new DidChangeWatchedFilesParams();
+ changes.changes = List.of(deleted);
+ server.didChangeWatchedFiles(changes);
}
}
}
diff --git a/src/test/java/org/javacs/FileStoreTest.java b/src/test/java/org/javacs/FileStoreTest.java
new file mode 100644
index 0000000..3a6a87f
--- /dev/null
+++ b/src/test/java/org/javacs/FileStoreTest.java
@@ -0,0 +1,23 @@
+package org.javacs;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FileStoreTest {
+
+ @Before
+ public void setWorkspaceRoot() {
+ FileStore.setWorkspaceRoots(Set.of(LanguageServerFixture.DEFAULT_WORKSPACE_ROOT));
+ }
+
+ @Test
+ public void packageName() {
+ assertThat(
+ FileStore.suggestedPackageName(FindResource.path("/org/javacs/example/Goto.java")),
+ equalTo("org.javacs.example"));
+ }
+}
diff --git a/src/test/java/org/javacs/FindResource.java b/src/test/java/org/javacs/FindResource.java
index 6e6860e..55c00fa 100644
--- a/src/test/java/org/javacs/FindResource.java
+++ b/src/test/java/org/javacs/FindResource.java
@@ -29,6 +29,6 @@ public class FindResource {
public static Path path(String resourcePath) {
if (resourcePath.startsWith("/")) resourcePath = resourcePath.substring(1);
- return Paths.get("./src/test/test-project/workspace/src").resolve(resourcePath).normalize();
+ return Paths.get("./src/test/test-project/workspace/src").resolve(resourcePath).toAbsolutePath().normalize();
}
}
diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java
index a0618da..dde1569 100644
--- a/src/test/java/org/javacs/JavaCompilerServiceTest.java
+++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java
@@ -11,7 +11,6 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Set;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import javax.lang.model.element.Element;
@@ -25,31 +24,12 @@ public class JavaCompilerServiceTest {
Main.setRootFormat();
}
- private JavaCompilerService compiler =
- new JavaCompilerService(
- Collections.singleton(simpleProjectSrc()),
- JavaCompilerServiceTest::allJavaFiles,
- Collections.emptySet(),
- Collections.emptySet());
-
- static Path mavenProjectSrc() {
- return Paths.get("src/test/test-project/workspace/src").normalize();
- }
+ private JavaCompilerService compiler = new JavaCompilerService(Collections.emptySet(), Collections.emptySet());
static Path simpleProjectSrc() {
return Paths.get("src/test/test-project/simple").normalize();
}
- static Set<Path> allJavaFiles() {
- try {
- return Files.walk(simpleProjectSrc())
- .filter(f -> f.getFileName().toString().endsWith(".java"))
- .collect(Collectors.toSet());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
static String contents(String resourceFile) {
var root = JavaCompilerServiceTest.simpleProjectSrc();
var file = root.resolve(resourceFile);
@@ -302,17 +282,4 @@ public class JavaCompilerServiceTest {
assertTrue(CompileFocus.matchesPartialName("foobar", "foo"));
assertFalse(CompileFocus.matchesPartialName("foo", "foobar"));
}
-
- @Test
- public void packageName() {
- var compiler =
- new JavaCompilerService(
- Collections.singleton(mavenProjectSrc()),
- JavaCompilerServiceTest::allJavaFiles,
- Collections.emptySet(),
- Collections.emptySet());
- assertThat(
- compiler.pathBasedPackageName(FindResource.path("/org/javacs/example/Goto.java")),
- equalTo("org.javacs.example"));
- }
}
diff --git a/src/test/java/org/javacs/ParserTest.java b/src/test/java/org/javacs/ParserTest.java
index 92663a9..d5ec681 100644
--- a/src/test/java/org/javacs/ParserTest.java
+++ b/src/test/java/org/javacs/ParserTest.java
@@ -58,8 +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 sourcePath = new SourcePath(Collections.singleton(dir));
- var existing = Parser.existingImports(sourcePath.allJavaFiles());
+ FileStore.setWorkspaceRoots(Collections.singleton(dir));
+ var existing = Parser.existingImports(FileStore.all());
assertThat(existing.classes, hasItems("java.util.List"));
assertThat(existing.packages, hasItems("java.util", "java.io"));
}
diff --git a/src/test/java/org/javacs/SourceFileManagerTest.java b/src/test/java/org/javacs/SourceFileManagerTest.java
index ab40c5e..523b6a4 100644
--- a/src/test/java/org/javacs/SourceFileManagerTest.java
+++ b/src/test/java/org/javacs/SourceFileManagerTest.java
@@ -9,6 +9,7 @@ import java.nio.file.Path;
import java.util.*;
import java.util.logging.Logger;
import javax.tools.*;
+import org.junit.Before;
import org.junit.Test;
public class SourceFileManagerTest {
@@ -18,7 +19,7 @@ public class SourceFileManagerTest {
final StandardJavaFileManager standardFileManager = createDelegateFileManager();
private static SourceFileManager createSourceFileManager() {
- var fileManager = new SourceFileManager(Set.of(src));
+ var fileManager = new SourceFileManager();
try {
fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, List.of(src));
fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, List.of(classes));
@@ -42,6 +43,11 @@ public class SourceFileManagerTest {
return fileManager;
}
+ @Before
+ public void setWorkspaceRoot() {
+ FileStore.setWorkspaceRoots(Set.of(LanguageServerFixture.DEFAULT_WORKSPACE_ROOT));
+ }
+
@Test
public void binaryNameOfPackagePrivateClass() throws IOException {
var standardJava =