summaryrefslogtreecommitdiff
path: root/src/test/java/org/javacs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/javacs')
-rw-r--r--src/test/java/org/javacs/LanguageServerFixture.java8
-rw-r--r--src/test/java/org/javacs/WarningsTest.java36
2 files changed, 44 insertions, 0 deletions
diff --git a/src/test/java/org/javacs/LanguageServerFixture.java b/src/test/java/org/javacs/LanguageServerFixture.java
index f2da3b7..f9052a0 100644
--- a/src/test/java/org/javacs/LanguageServerFixture.java
+++ b/src/test/java/org/javacs/LanguageServerFixture.java
@@ -19,18 +19,26 @@ class LanguageServerFixture {
return getJavaLanguageServer(DEFAULT_WORKSPACE_ROOT, diagnostic -> LOG.info(diagnostic.message));
}
+ static JavaLanguageServer getJavaLanguageServer(Consumer<Diagnostic> onError) {
+ return getJavaLanguageServer(DEFAULT_WORKSPACE_ROOT, onError);
+ }
+
static JavaLanguageServer getJavaLanguageServer(Path workspaceRoot, Consumer<Diagnostic> onError) {
return getJavaLanguageServer(
workspaceRoot,
new LanguageClient() {
+ @Override
public void publishDiagnostics(PublishDiagnosticsParams params) {
params.diagnostics.forEach(onError);
}
+ @Override
public void showMessage(ShowMessageParams params) {}
+ @Override
public void registerCapability(String method, JsonElement options) {}
+ @Override
public void customNotification(String method, JsonElement params) {}
});
}
diff --git a/src/test/java/org/javacs/WarningsTest.java b/src/test/java/org/javacs/WarningsTest.java
new file mode 100644
index 0000000..692e985
--- /dev/null
+++ b/src/test/java/org/javacs/WarningsTest.java
@@ -0,0 +1,36 @@
+package org.javacs;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+import org.javacs.lsp.Diagnostic;
+import org.junit.Before;
+import org.junit.Test;
+
+public class WarningsTest {
+ protected static final Logger LOG = Logger.getLogger("main");
+
+ private static List<String> errors = new ArrayList<>();
+
+ protected static final JavaLanguageServer server =
+ LanguageServerFixture.getJavaLanguageServer(WarningsTest::onError);
+
+ private static void onError(Diagnostic error) {
+ var string = String.format("%s(%d)", error.code, error.range.start.line + 1);
+ errors.add(string);
+ }
+
+ @Before
+ public void setup() {
+ errors.clear();
+ }
+
+ @Test
+ public void unusedLocal() {
+ server.reportErrors(List.of(FindResource.uri("org/javacs/warn/Unused.java")));
+ assertThat(errors, hasItem("unused(5)"));
+ }
+}