use of org.junit.runner.manipulation.NoTestsRemainException in project bnd by bndtools.
the class Activator method addTest.
@SuppressWarnings("unchecked")
private void addTest(TestSuite suite, Class<?> clazz, final String method) {
if (TestCase.class.isAssignableFrom(clazz)) {
if (hasJunit4Annotations(clazz)) {
error("The test class %s extends %s and it uses JUnit 4 annotations. This means that the annotations will be ignored.", clazz.getName(), TestCase.class.getName());
}
trace("using JUnit 3");
if (method != null) {
suite.addTest(TestSuite.createTest(clazz, method));
return;
}
suite.addTestSuite((Class<? extends TestCase>) clazz);
return;
}
trace("using JUnit 4");
JUnit4TestAdapter adapter = new JUnit4TestAdapter(clazz);
if (method != null) {
trace("method specified " + clazz + ":" + method);
final Pattern glob = Pattern.compile(method.replaceAll("\\*", ".*").replaceAll("\\?", ".?"));
try {
adapter.filter(new org.junit.runner.manipulation.Filter() {
@Override
public String describe() {
return "Method filter for " + method;
}
@Override
public boolean shouldRun(Description description) {
if (glob.matcher(description.getMethodName()).lookingAt()) {
trace("accepted " + description.getMethodName());
return true;
}
trace("rejected " + description.getMethodName());
return false;
}
});
} catch (NoTestsRemainException e) {
return;
}
}
suite.addTest(adapter);
}
Aggregations