private void filterIfRequired(final ResultCollector rc, final Runner runner) { if (this.filter.hasSome()) { if (!(runner instanceof Filterable)) { LOG.warning("Not able to filter " + runner.getDescription() + ". Mutation may have prevented JUnit from constructing test"); return; } final Filterable f = (Filterable) runner; try { f.filter(this.filter.value()); } catch (final NoTestsRemainException e1) { rc.notifySkipped(this.getDescription()); return; } } }
@Override public List<TestUnit> findTestUnits(final Class<?> clazz) { final Runner runner = AdaptedJUnitTestUnit.createRunner(clazz); if (isExcluded(runner) || isNotARunnableTest(runner, clazz.getName()) || !isIncluded(clazz)) { return Collections.emptyList(); } if (Filterable.class.isAssignableFrom(runner.getClass()) && !shouldTreatAsOneUnit(clazz, runner)) { List<TestUnit> filteredUnits = splitIntoFilteredUnits(runner.getDescription()); return filterUnitsByMethod(filteredUnits); } else { return Collections.<TestUnit> singletonList(new AdaptedJUnitTestUnit( clazz, Option.<Filter> none())); } }
private void runEnabledTests(RunNotifier nested) { if (enabledTests.isEmpty()) { return; } Runner runner; try { runner = createExecutionRunner(); } catch (Throwable t) { runner = new CannotExecuteRunner(getDisplayName(), target, t); } try { if (!disabledTests.isEmpty()) { ((Filterable) runner).filter(new Filter() { @Override public boolean shouldRun(Description description) { return !disabledTests.contains(description); } @Override public String describe() { return "disabled tests"; } }); } } catch (NoTestsRemainException e) { return; } runner.run(nested); }
public Filter getFilter() { return new Filter() { @Override public boolean shouldRun(Description description) { return Boolean.TRUE.equals(context.get(description)); } @Override public String describe() { return "RTest Filter"; } @Override public void apply(Object child) throws NoTestsRemainException { if(child instanceof Filterable) { Filterable filterableChild = (Filterable) child; filterableChild.filter(this); } } }; //return Filter.matchMethodDescription(desiredDescription); /*return new Filter() { @Override public boolean shouldRun(Description description) { return (toRun.contains(description)); } @Override public String describe() { return "RTest methods filter"; } };*/ }
@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; } }); }