use of org.junit.runner.manipulation.Filterable in project gradle by gradle.
the class JUnitTestClassExecuter method runTestClass.
private void runTestClass(String testClassName) throws ClassNotFoundException {
final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
List<Filter> filters = new ArrayList<Filter>();
if (options.hasCategoryConfiguration()) {
verifyJUnitCategorySupport();
Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {
public Class<?> transform(final String original) {
try {
return applicationClassLoader.loadClass(original);
} catch (ClassNotFoundException e) {
throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
}
}
};
filters.add(new CategoryFilter(CollectionUtils.collect(options.getIncludeCategories(), transformer), CollectionUtils.collect(options.getExcludeCategories(), transformer)));
}
Request request = Request.aClass(testClass);
Runner runner = request.getRunner();
if (!options.getIncludedTests().isEmpty()) {
TestSelectionMatcher matcher = new TestSelectionMatcher(options.getIncludedTests());
// matches the filter, run the entire suite instead of filtering away its contents.
if (!runner.getDescription().isSuite() || !matcher.matchesTest(testClassName, null)) {
filters.add(new MethodNameFilter(matcher));
}
}
if (runner instanceof Filterable) {
Filterable filterable = (Filterable) runner;
for (Filter filter : filters) {
try {
filterable.filter(filter);
} catch (NoTestsRemainException e) {
// Ignore
return;
}
}
} else if (allTestsFiltered(runner, filters)) {
return;
}
RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
runner.run(notifier);
}
use of org.junit.runner.manipulation.Filterable in project junit4 by junit-team.
the class JUnit38ClassRunner method filter.
public void filter(Filter filter) throws NoTestsRemainException {
if (getTest() instanceof Filterable) {
Filterable adapter = (Filterable) getTest();
adapter.filter(filter);
} else if (getTest() instanceof TestSuite) {
TestSuite suite = (TestSuite) getTest();
TestSuite filtered = new TestSuite(suite.getName());
int n = suite.testCount();
for (int i = 0; i < n; i++) {
Test test = suite.testAt(i);
if (filter.shouldRun(makeDescription(test))) {
filtered.addTest(test);
}
}
setTest(filtered);
if (filtered.testCount() == 0) {
throw new NoTestsRemainException();
}
}
}
use of org.junit.runner.manipulation.Filterable in project junit4 by junit-team.
the class SingleMethodTest method filteringAwayEverythingThrowsException.
@Test(expected = NoTestsRemainException.class)
public void filteringAwayEverythingThrowsException() throws NoTestsRemainException {
Filterable runner = (Filterable) Request.aClass(OneTimeSetup.class).getRunner();
runner.filter(new Filter() {
@Override
public boolean shouldRun(Description description) {
return false;
}
@Override
public String describe() {
return null;
}
});
}
use of org.junit.runner.manipulation.Filterable in project junit5 by junit-team.
the class TestClassRequestResolver method determineRunnerTestDescriptor.
private RunnerTestDescriptor determineRunnerTestDescriptor(Class<?> testClass, Runner runner, List<RunnerTestDescriptorAwareFilter> filters, UniqueId engineId) {
RunnerTestDescriptor runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, runner, engineId);
if (!filters.isEmpty()) {
if (runner instanceof Filterable) {
Filter filter = createOrFilter(filters, runnerTestDescriptor);
Runner filteredRunner = runnerTestDescriptor.toRequest().filterWith(filter).getRunner();
runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, filteredRunner, engineId);
} else {
Runner runnerToReport = (runner instanceof RunnerDecorator) ? ((RunnerDecorator) runner).getDecoratedRunner() : runner;
logger.warn(() -> //
"Runner " + runnerToReport.getClass().getName() + " (used on " + testClass.getName() + //
") does not support filtering" + " and will therefore be run completely.");
}
}
return runnerTestDescriptor;
}
use of org.junit.runner.manipulation.Filterable in project gradle by gradle.
the class JUnitTestClassExecutor method runTestClass.
private void runTestClass(String testClassName) throws ClassNotFoundException {
final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
if (isNestedClassInsideEnclosedRunner(testClass)) {
return;
}
List<Filter> filters = new ArrayList<Filter>();
if (options.hasCategoryConfiguration()) {
verifyJUnitCategorySupport();
filters.add(new CategoryFilter(options.getIncludeCategories(), options.getExcludeCategories(), applicationClassLoader));
}
Request request = Request.aClass(testClass);
Runner runner = request.getRunner();
if (!options.getIncludedTests().isEmpty() || !options.getIncludedTestsCommandLine().isEmpty() || !options.getExcludedTests().isEmpty()) {
TestSelectionMatcher matcher = new TestSelectionMatcher(options.getIncludedTests(), options.getExcludedTests(), options.getIncludedTestsCommandLine());
// matches the filter, run the entire suite instead of filtering away its contents.
if (!runner.getDescription().isSuite() || !matcher.matchesTest(testClassName, null)) {
filters.add(new MethodNameFilter(matcher));
}
}
if (runner instanceof Filterable) {
Filterable filterable = (Filterable) runner;
for (Filter filter : filters) {
try {
filterable.filter(filter);
} catch (NoTestsRemainException e) {
// Ignore
return;
}
}
} else if (allTestsFiltered(runner, filters)) {
return;
}
RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
runner.run(notifier);
}
Aggregations