summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-27 12:27:25 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-27 12:27:25 -0800
commit62d4cd468264783efb95c3687188bd12d395f7cf (patch)
tree2d8fca91eae3edcca7befb222a888e167506e6a3 /src/test/java
parent6d08a795f5f39e35dfdb502ae86f1b9af51d1f0e (diff)
downloadjava-language-server-62d4cd468264783efb95c3687188bd12d395f7cf.zip
Constructor refs almost work
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/javacs/CodeLensTest.java22
-rw-r--r--src/test/java/org/javacs/FindReferencesTest.java19
2 files changed, 35 insertions, 6 deletions
diff --git a/src/test/java/org/javacs/CodeLensTest.java b/src/test/java/org/javacs/CodeLensTest.java
index 553e3e5..d086018 100644
--- a/src/test/java/org/javacs/CodeLensTest.java
+++ b/src/test/java/org/javacs/CodeLensTest.java
@@ -52,10 +52,17 @@ public class CodeLensTest {
return commands;
}
+ private List<String> titles(List<? extends CodeLens> lenses) {
+ var titles = new ArrayList<String>();
+ for (var lens : lenses) {
+ titles.add(lens.getCommand().getTitle());
+ }
+ return titles;
+ }
+
@Test
- public void codeLens() {
- var file = "/org/javacs/example/HasTest.java";
- var lenses = lenses(file);
+ public void testMethods() {
+ var lenses = lenses("/org/javacs/example/HasTest.java");
assertThat(lenses, not(empty()));
var commands = commands(lenses);
@@ -63,4 +70,13 @@ public class CodeLensTest {
assertThat(commands, hasItem(containsString("HasTest, testMethod")));
assertThat(commands, hasItem(containsString("HasTest, otherTestMethod")));
}
+
+ @Test
+ public void constructorReferences() {
+ var lenses = lenses("/org/javacs/example/ConstructorRefs.java");
+ assertThat(lenses, not(empty()));
+
+ var titles = titles(lenses);
+ assertThat(titles, hasItem(containsString("1 references")));
+ }
}
diff --git a/src/test/java/org/javacs/FindReferencesTest.java b/src/test/java/org/javacs/FindReferencesTest.java
index 50b8ea5..4cf0d2a 100644
--- a/src/test/java/org/javacs/FindReferencesTest.java
+++ b/src/test/java/org/javacs/FindReferencesTest.java
@@ -3,10 +3,11 @@ package org.javacs;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
+import java.net.URI;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
-import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.ReferenceParams;
import org.eclipse.lsp4j.TextDocumentIdentifier;
@@ -17,7 +18,7 @@ public class FindReferencesTest {
private static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer();
- protected List<? extends Location> items(String file, int row, int column) {
+ protected List<String> items(String file, int row, int column) {
var uri = FindResource.uri(file);
var params = new ReferenceParams();
@@ -26,7 +27,14 @@ public class FindReferencesTest {
params.setPosition(new Position(row - 1, column - 1));
try {
- return server.getTextDocumentService().references(params).get();
+ var locations = server.getTextDocumentService().references(params).get();
+ var strings = new ArrayList<String>();
+ for (var l : locations) {
+ var fileName = Parser.fileName(URI.create(l.getUri()));
+ var line = l.getRange().getStart().getLine();
+ strings.add(String.format("%s(%d)", fileName, line + 1));
+ }
+ return strings;
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
@@ -36,4 +44,9 @@ public class FindReferencesTest {
public void findAllReferences() {
assertThat(items("/org/javacs/example/GotoOther.java", 6, 30), not(empty()));
}
+
+ @Test
+ public void findConstructorReferences() {
+ assertThat(items("/org/javacs/example/ConstructorRefs.java", 4, 10), contains("ConstructorRefs.java(9)"));
+ }
}