/** * Create a suite for {@code classes}, building Runners with {@code builder}. * Throws an InitializationError if Runner construction fails */ public Runner getSuite(final RunnerBuilder builder, Class<?>[] classes) throws InitializationError { return new Suite(new RunnerBuilder() { @Override public Runner runnerForClass(Class<?> testClass) throws Throwable { return getRunner(builder, testClass); } }, classes); }
@Override protected void runChild(Runner runner, RunNotifier notifier) { // This is ugly but, for now, ORM class loading is inconsistent. // It sometimes use ClassLoaderService which takes into account AvailableSettings.CLASSLOADERS, and sometimes // ReflectHelper#classForName() which uses the TCCL. // See https://hibernate.atlassian.net/browse/HHH-13136 for more information. ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( ( (ParentRunner<?>) runner ).getTestClass().getJavaClass().getClassLoader() ); super.runChild( runner, notifier ); } finally { Thread.currentThread().setContextClassLoader( originalClassLoader ); } }
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
@Override public void run(RunNotifier notifier) { Class<?> testClass = getTestClass().getJavaClass(); try { manager.beforeClass(stagedReactor, testClass); super.run(notifier); } // CHECKSTYLE:SKIP : catch all wanted catch (Throwable e) { // rethrowing the exception does not help, we have to use the notifier here Description description = Description.createSuiteDescription(testClass); notifier.fireTestFailure(new Failure(description, e)); } finally { manager.afterClass(stagedReactor, testClass); } }
/** * Called reflectively on classes annotated with <code>@RunWith(Suite.class)</code> * * @param klass the root class * @param builder builds runners for classes in the suite */ public Suite(Class<?> klass, RunnerBuilder builder) throws InitializationError { this(builder, klass, getAnnotatedClasses(klass)); }
public class Main { public static void main(String[] args) { Suite suite = new Suite(10); suite.displayRoom(); } }
@Override protected List<Runner> getChildren() { return super.getChildren(); //To change body of overridden methods use File | Settings | File Templates. } }
@Override protected Statement withAfterClasses(final Statement statement) { final Statement wrappedStatement = new Statement() { @Override public void evaluate() throws Throwable { statement.evaluate(); // release resources in GraphProviders that implement AutoCloseable final GraphProvider gp = GraphManager.getGraphProvider(); if (gp instanceof AutoCloseable) ((AutoCloseable) gp).close(); } }; return super.withAfterClasses(wrappedStatement); }
/** * Run. It is only overwritten for better testing support. * * @param notifier * the notifier * @see org.junit.runners.ParentRunner#run(org.junit.runner.notification.RunNotifier) */ @Override public void run(final RunNotifier notifier) { super.run(notifier); }
/** * Called reflectively on classes annotated with <code>@RunWith(Suite.class)</code> * * @param klass the root class * @param builder builds runners for classes in the suite */ public Suite(Class<?> klass, RunnerBuilder builder) throws InitializationError { this(builder, klass, getAnnotatedClasses(klass)); }
@Override protected List<Runner> getChildren() { return super.getChildren(); //To change body of overridden methods use File | Settings | File Templates. } }
@Override protected Statement withAfterClasses(final Statement statement) { final Statement wrappedStatement = new Statement() { @Override public void evaluate() throws Throwable { statement.evaluate(); // release resources in GraphProviders that implement AutoCloseable final GraphProvider gp = GraphManager.getGraphProvider(); if (gp instanceof AutoCloseable) ((AutoCloseable) gp).close(); } }; return super.withAfterClasses(wrappedStatement); }
@Override public void run(RunNotifier runnotifier) { super.run(runnotifier); }
/** * Returns an empty suite. */ public static Runner emptySuite() { try { return new Suite((Class<?>) null, new Class<?>[0]); } catch (InitializationError e) { throw new RuntimeException("This shouldn't be possible"); } }
/** */ @Override protected void runChild(Runner runner, RunNotifier ntf) { cntr.getAndIncrement(); super.runChild(runner, ntf); } }
/** * Called reflectively on classes annotated with <code>@RunWith(Suite.class)</code> * * @param klass the root class * @param builder builds runners for classes in the suite */ public Suite(Class<?> klass, RunnerBuilder builder) throws InitializationError { this(builder, klass, getAnnotatedClasses(klass)); }
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
@Override protected List<Runner> getChildren() { return super.getChildren(); }
@Override protected Statement withAfterClasses(Statement statement) { Statement junitAfterClasses = super.withAfterClasses(statement); return new RunAfterTestClassCallbacks(junitAfterClasses, testContextManager); }
@Override public void run(final RunNotifier notifier) { cucumberScenarioOutline.formatOutlineScenario(jUnitReporter); super.run(notifier); } }