edu.umd.cs.findbugs.test.SpotBugsExtension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of test-harness-jupiter Show documentation
Show all versions of test-harness-jupiter Show documentation
A test harness library for SpotBugs plugin developers to test on JUnit 5
package edu.umd.cs.findbugs.test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;
/**
* A JUnit extension for SpotBugs plugin.
* It provides {@link SpotBugsRunner} instance as parameter of test method.
* Sample code:
* @ExtendWith(SpotBugsExtension.class)
public class SampleTest {
@Test
public void test(SpotBugsRunner spotbugs) {
BugCollection bugs = spotbugs.performAnalysis(Paths.get("target/test-classes/pkg/GoodCase.class"));
...
}
}
*/
public class SpotBugsExtension implements ParameterResolver {
@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
return parameterContext.getParameter().getType().equals(SpotBugsRunner.class);
}
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
return new SpotBugsRunner();
}
}