public ConcurrentDependsOnClasspathSuite(Class<?> suiteClass, RunnerBuilder builder) throws InitializationError { super(suiteClass, builder); methodFilter = newMethodFilter(suiteClass.getAnnotation(MethodFilters.class)); int maximumPoolSize = isAnnotationPresent(suiteClass) && !runSerial() ? maximumPoolSize(suiteClass) : 1; if (maximumPoolSize < 1) { throw new IllegalArgumentException("maximumPoolSize < 1"); } scheduler = new ConcurrentDependsOnSuiteScheduler(maximumPoolSize, listener); setScheduler(scheduler); getChildren().stream().forEach(r -> shouldRun.add(getClassName(r))); getChildren().stream().forEach(r -> nameToRunner.put(getClassName(r), r)); verifyDependecyGraph(); getChildren().stream().filter(r -> r instanceof IgnoredClassRunner).forEach(r -> { failed.add(getClassName(r)); }); if (methodFilter != null) { applyMethodFilter(); } }
@Override protected IgnoredBuilder ignoredBuilder() { return new IgnoredBuilder() { @Override public Runner runnerForClass(Class<?> testClass) { if (testClass.getAnnotation(Ignore.class) != null || testClass.getAnnotation(IgnoredBySmokeTest.class) != null) return new IgnoredClassRunner(testClass); return null; } }; }
@Override protected void runChild(Runner runner, @SuppressWarnings("hiding") RunNotifier notifier) { if (shouldIgnore(runner)) { failed.add(getClassName(runner)); super.runChild( scheduler.newClassRunner(getClassName(runner), new IgnoredClassRunner(runner.getDescription().getTestClass()), methodFilter), notifier); runner.getDescription().getChildren().stream().forEach(t -> notifier.fireTestIgnored(t)); } else { super.runChild(scheduler.newClassRunner(getClassName(runner), runner, methodFilter), notifier); } }
private void verifyAllMethodExists(@SuppressWarnings("hiding") Runner r) { if (r instanceof IgnoredClassRunner) { return; } List<String> classMethods = r.getDescription().getChildren().stream().map(d -> d.getMethodName()).collect(Collectors.toList()); for (String m : filter.methods) { if (!classMethods.contains(m)) { System.err.println("method '" + m + "' is filtered by " + MethodFilter.class.getSimpleName() + " but does not exist in class '" + className + "'"); } } }
/** * Create the runner. * * @param klass The test class. * @throws InitializationError If the test class is malformed. */ public RunIfRunner(Class<?> klass) throws InitializationError { boolean ignoreClass = RunIfUtils.isIgnored(klass); // If the entire test class must be ignored, we instantiate an instance of IgnoredClassRunner // since this runner will not instantiate the test class, thus allowing the class to use // illegal API such as Java8 method on JDK7 (since it will never be evaluated). this.delegate = ignoreClass ? new IgnoredClassRunner(klass) : new RunIfBlockJunit4ClassRunner(klass); }
@SuppressWarnings("unused") // Invoked by reflection public NamedParameterizedRunner(Class<?> klass) throws Throwable { super(klass, Collections.<Runner>emptyList()); if (getTestClass().getJavaClass().getAnnotation(Ignore.class) != null) { runners = Collections.unmodifiableList(Arrays.asList((Runner)new IgnoredClassRunner(klass))); return; } List<Runner> localRunners = new LinkedList<>(); Collection<Parameterization> parameterizations = getParameterizations(); checkFailingParameterizations(parameterizations); final String override = System.getProperty(PARAMETERIZATION_OVERRIDE); final boolean overrideIsRegex = (override != null) && paramNameUsesRegex(override); if (override != null) { String msg = "Override is set to"; if (overrideIsRegex) { msg += " regex"; } msg += ":" + override; logger.debug(msg); } for (Parameterization param : parameterizations) { final boolean useThisParam; if (override == null) { useThisParam = true; } else if (overrideIsRegex) { useThisParam = paramNameMatchesRegex(param.getName(), override); } else { useThisParam = param.getName().equals(override); } if (useThisParam) { if (override != null) { logger.debug("Adding parameterization: " + param.getName()); } localRunners.add(new ReifiedParamRunner(getTestClass().getJavaClass(), param, override != null)); } } runners = Collections.unmodifiableList(localRunners); }