private void registerOptOuts(final Class<? extends Graph> graphClass, final Optional<GraphProvider.Descriptor> graphProviderDescriptor, final TraversalEngine.Type traversalEngineType) throws InitializationError { final Graph.OptOut[] optOuts = graphClass.getAnnotationsByType(Graph.OptOut.class); if (optOuts != null && optOuts.length > 0) { // validate annotation - test class and reason must be set if (!Arrays.stream(optOuts).allMatch(ignore -> ignore.test() != null && ignore.reason() != null && !ignore.reason().isEmpty())) throw new InitializationError("Check @IgnoreTest annotations - all must have a 'test' and 'reason' set"); try { filter(new OptOutTestFilter(optOuts, graphProviderDescriptor, traversalEngineType)); } catch (NoTestsRemainException ex) { throw new InitializationError(ex); } } }
@Override public void filter(final Filter raw) throws NoTestsRemainException { super.filter(new Filter() { @Override public boolean shouldRun(Description description) { String testDisplay = StringUtils.substringBefore(description.getDisplayName(), " "); if (testDisplay != description.getDisplayName()) { description = Description.createTestDescription(description.getTestClass(), testDisplay); } return raw.shouldRun(description); } @Override public String describe() { return raw.describe(); } }); }
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; } } }
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"; } };*/ }
private void addFilter(Filter filter) { try { filter(filter); } catch (NoTestsRemainException ex) { System.out.println("No tests remain exception: " + ex); } }
/** * Initializes the test filter. * * @param parentRunner * the {@link ParentRunner} to initialize, must not be {@code null} */ public static void initializeFilter(final ParentRunner<?> parentRunner) { try { parentRunner.filter(INSTANCE); } catch (NoTestsRemainException e) { // we ignore the case where no children are left } }
private void filterByCategory(Class category) throws InitializationError { if (category != null) { try { final Categories.CategoryFilter categoryFilter = Categories.CategoryFilter.include(category); filter(categoryFilter); } catch (NoTestsRemainException e) { throw new RuntimeException(e); } } }
private void applyMethodFilter() throws InitializationError { for (Runner r : getChildren()) { try { if (r instanceof ParentRunner<?>) { ((ParentRunner<?>) r).filter(methodFilter); } } catch (NoTestsRemainException e) { throw new InitializationError(e); } } }
public PowerMockJUnit4LegacyRunnerDelegateImpl(Class<?> klass, String[] methodsToRun, PowerMockTestListener[] listeners) throws InitializationError, NoTestsRemainException { super(klass, new PowerMockJUnit4LegacyTestClassMethodsRunner(klass, listeners == null ? new PowerMockTestListener[0] : listeners)); filter(new PowerMockJUnit4LegacyFilter(methodsToRun)); testCount = methodsToRun.length; }
@Override public Runner getRunner() { try { Runner runner = mRequest.getRunner(); mFilter.apply(runner); return runner; } catch (NoTestsRemainException e) { // don't treat filtering out all tests as an error return new BlankRunner(); } }
public static Result execute(final Class<?> classOfspecToRun, final String methodName) throws InitializationError, NoTestsRemainException { final Result testResult = new Result(); Sputnik spockRunner = new Sputnik(classOfspecToRun); if(methodName != null && !methodName.equals("")) { SpockSpecificationFilter filter = new SpockSpecificationFilter(spockRunner, methodName); spockRunner.filter(filter); } runTest(spockRunner, testResult); return testResult; }
public Categories(Class<?> klass, RunnerBuilder builder) throws InitializationError { super(klass, builder); try { Set<Class<?>> included= getIncludedCategory(klass); Set<Class<?>> excluded= getExcludedCategory(klass); boolean isAnyIncluded= isAnyIncluded(klass); boolean isAnyExcluded= isAnyExcluded(klass); filter(CategoryFilter.categoryFilter(isAnyIncluded, included, isAnyExcluded, excluded)); } catch (NoTestsRemainException e) { throw new InitializationError(e); } assertNoCategorizedDescendentsOfUncategorizeableParents(getDescription()); }
@Override public Runner getRunner() { try { Runner runner = fRequest.getRunner(); fFilter.apply(runner); return runner; } catch (NoTestsRemainException e) { return new ErrorReportingRunner(Filter.class, new Exception(String .format("No tests found matching %s from %s", fFilter .describe(), fRequest.toString()))); } }
@Test public void categoryFilterLeavesOnlyMatchingMethods() throws InitializationError, NoTestsRemainException { CategoryFilter filter = CategoryFilter.include(SlowTests.class); BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(A.class); filter.apply(runner); assertEquals(1, runner.testCount()); }
@Test public void categoryFilterRejectsIncompatibleCategory() throws InitializationError, NoTestsRemainException { CategoryFilter filter = CategoryFilter.include(SlowTests.class); BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner( OneFastOneSlow.class); filter.apply(runner); assertEquals(1, runner.testCount()); }
@Test public void testSuiteFiltering() throws Exception { Runner runner = Request.aClass(ExampleSuite.class).getRunner(); Filter filter = notThisMethodName("test1"); try { filter.apply(runner); } catch (NoTestsRemainException e) { return; } fail("Expected 'NoTestsRemainException' due to complete filtering"); }
@Test public void testSuiteFilteringWithUnmodifyableChildList() throws Exception { Runner runner = Request.aClass(ExampleSuiteWithUnmodifyableChildList.class) .getRunner(); Filter filter = notThisMethodName("test1"); try { filter.apply(runner); } catch (NoTestsRemainException e) { return; } fail("Expected 'NoTestsRemainException' due to complete filtering"); }
@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; } }); }
/** * Constructor. * * @param testClass * The test class. * @throws NoTestsRemainException * When no tests are to be run in this test class. */ public TCKRunner(final Class<?> testClass) throws NoTestsRemainException { super(testClass); filter(new Filter() { @Override public boolean shouldRun(Description description) { try { UsbAssume.assumeTckTestsEnabled(); return true; } catch (AssumptionViolatedException e) { return false; } } @Override public String describe() { return "TCK tests only when enabled"; } }); }
public Categories(Class<?> klass, RunnerBuilder builder) throws InitializationError { super(klass, builder); try { filter(new CategoryFilter(getIncludedCategory(klass), getExcludedCategory(klass))); } catch (NoTestsRemainException e) { throw new InitializationError(e); } assertNoCategorizedDescendentsOfUncategorizeableParents(getDescription()); }
public SingleMethodRunner(Class<?> klass) throws InitializationError { super(klass); try { this.children = computeChildren(); } catch (RuntimeException | ClassNotFoundException | NoTestsRemainException e) { throw new InitializationError(e); } }
private List<Runner> computeChildren() throws InitializationError, ClassNotFoundException, NoTestsRemainException { String testMethodPattern = System .getProperty(TEST_METHOD_PROPERTY_NAME); if (testMethodPattern == null) { return Collections.emptyList(); } return Collections .singletonList(junitRunnerFor(new TestMethodReference( testMethodPattern))); }
/** * Constructs a new {@code SpringJUnit4ClassRunner} and initializes a * {@link org.springframework.test.context.TestContextManager} to provide Spring testing functionality to * standard JUnit tests. * * @param clazz the test class to be run * @see #createTestContextManager(Class) */ public LdapConditionallyFilteredTestRunner(Class<?> clazz) throws InitializationError { super(clazz); String noadtest = System.getProperty("adtest"); if (noadtest != null) { try { filter(Categories.CategoryFilter.exclude(NoAdTest.class)); } catch (NoTestsRemainException e) { // Nothing to do here. } } }