/
MyDetectorTest.java
40 lines (31 loc) · 1.35 KB
/
MyDetectorTest.java
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
package ${package};
import static edu.umd.cs.findbugs.test.SpotBugsRule.containsExactly;
import static org.junit.Assert.assertThat;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.Rule;
import org.junit.Test;
import edu.umd.cs.findbugs.BugCollection;
import edu.umd.cs.findbugs.test.SpotBugsRule;
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher;
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder;
public class MyDetectorTest {
@Rule
public SpotBugsRule spotbugs = new SpotBugsRule();
@Test
public void testGoodCase() {
Path path = Paths.get("target/test-classes", "${package}".replace('.', '/'), "GoodCase.class");
BugCollection bugCollection = spotbugs.performAnalysis(path);
BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder()
.bugType("MY_BUG").build();
assertThat(bugCollection, containsExactly(bugTypeMatcher, 0));
}
@Test
public void testBadCase() {
Path path = Paths.get("target/test-classes", "${package}".replace('.', '/'), "BadCase.class");
BugCollection bugCollection = spotbugs.performAnalysis(path);
BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder()
.bugType("MY_BUG").build();
assertThat(bugCollection, containsExactly(bugTypeMatcher, 1));
}
}