blob: c4f9747abe5834f5286e3528f977fa82910bafaa (
plain)
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
|
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(7)")); // int unusedLocal
assertThat(errors, hasItem("unused(10)")); // int unusedPrivate
assertThat(errors, hasItem("unused(13)")); // int unusedLocalInLambda
assertThat(errors, hasItem("unused(16)")); // int unusedMethod() { ... }
assertThat(errors, hasItem("unused(22)")); // private Unused(int i) { }
assertThat(errors, hasItem("unused(24)")); // private class UnusedClass { }
assertThat(errors, not(hasItem("unused(6)"))); // test(int unusedParam)
assertThat(errors, not(hasItem("unused(12)"))); // unusedLambdaParam -> {};
assertThat(errors, not(hasItem("unused(20)"))); // private Unused() { }
}
// TODO warn on type.equals(otherType)
// TODO warn on map.get(wrongKeyType)
}
|