/** * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class * and superclasses after executing {@code statement}; all AfterClass methods are * always executed: exceptions thrown by previous steps are combined, if * necessary, with exceptions from AfterClass methods into a * {@link org.junit.runners.model.MultipleFailureException}. */ protected Statement withAfterClasses(Statement statement) { List<FrameworkMethod> afters = testClass .getAnnotatedMethods(AfterClass.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, null); }
@Override public void evaluate() throws Throwable { List<Throwable> errors = new ArrayList<Throwable>(); try { next.evaluate(); } catch (Throwable e) { errors.add(e); } finally { for (FrameworkMethod each : afters) { try { invokeMethod(each); } catch (Throwable e) { errors.add(e); } } } MultipleFailureException.assertEmpty(errors); }
private void finalizeIfNecessary(Object target) { finalizing = true; List<FrameworkMethod> afters = new TestClass(target.getClass()).getAnnotatedMethods(After.class); try { if (!afters.isEmpty()) { logger.debug("Running @After methods"); try { new RunAfters(new Statement() { @Override public void evaluate() { } }, afters, target).evaluate(); } catch (Throwable e) { Assert.assertThat(e, CoreMatchers.not(CoreMatchers.anything())); } } } finally { finalizing = false; } }
@Override public void evaluate() throws Throwable { // As the fNext field is set from ContiPerfRule using reflection, we need to set the underlying next field in // order the Statement to work Field next = this.getClass().getSuperclass().getDeclaredField("next"); next.setAccessible(true); next.set(this, fNext); super.evaluate(); }
/** * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class * and superclasses before executing {@code statement}; all AfterClass methods are * always executed: exceptions thrown by previous steps are combined, if * necessary, with exceptions from AfterClass methods into a * {@link MultipleFailureException}. */ protected Statement withAfterClasses(Statement statement) { List<FrameworkMethod> afters = fTestClass .getAnnotatedMethods(AfterClass.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, null); }
/** * Returns a {@link Statement}: run all non-overridden {@code @After} * methods on this class and superclasses before running {@code next}; all * After methods are always executed: exceptions thrown by previous steps * are combined, if necessary, with exceptions from After methods into a * {@link MultipleFailureException}. */ protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) { List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods( After.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, target); }
/** * Returns a {@link Statement}: run all non-overridden {@code @After} * methods on this class and superclasses before running {@code next}; all * After methods are always executed: exceptions thrown by previous steps * are combined, if necessary, with exceptions from After methods into a * {@link MultipleFailureException}. * * @deprecated Will be private soon: use Rules instead */ @Deprecated protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) { List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods( After.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, target); }
private Statement withAfters(Statement statement) { List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods(After.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, instance); }
/** * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class * and superclasses before executing {@code statement}; all AfterClass methods are * always executed: exceptions thrown by previous steps are combined, if * necessary, with exceptions from AfterClass methods into a * {@link MultipleFailureException}. */ protected Statement withAfterClasses(Statement statement) { List<FrameworkMethod> afters = fTestClass .getAnnotatedMethods(AfterClass.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, null); }
/** * Returns a {@link Statement}: run all non-overridden {@code @After} * methods on this class and superclasses before running {@code next}; all * After methods are always executed: exceptions thrown by previous steps * are combined, if necessary, with exceptions from After methods into a * {@link MultipleFailureException}. * * @deprecated Will be private soon: use Rules instead */ @Deprecated protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) { List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods( After.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, target); }
/** * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class * and superclasses before executing {@code statement}; all AfterClass methods are always * executed: exceptions thrown by previous steps are combined, if necessary, with exceptions * from AfterClass methods into a {@link MultipleFailureException}. * * @param statement statement * @return wrapped statement */ protected Statement withAfterProcess(Statement statement) { TestClass testClass = getTestClass(); List<FrameworkMethod> afters = testClass.getAnnotatedMethods(AfterProcess.class); afters.addAll(testClass.getAnnotatedMethods(AfterClass.class)); return afters.isEmpty() ? statement : new RunAfters(statement, afters, null); }
@Override protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) { return new RunAfters(statement, new ArrayList<FrameworkMethod>(), target); }
/** * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class * and superclasses before executing {@code statement}; all AfterClass methods are * always executed: exceptions thrown by previous steps are combined, if * necessary, with exceptions from AfterClass methods into a * {@link org.junit.runners.model.MultipleFailureException}. */ protected Statement withAfterClasses(Statement statement) { List<FrameworkMethod> afters = testClass .getAnnotatedMethods(AfterClass.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, null); }
/** * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class * and superclasses before executing {@code statement}; all AfterClass methods are * always executed: exceptions thrown by previous steps are combined, if * necessary, with exceptions from AfterClass methods into a * {@link MultipleFailureException}. */ protected Statement withAfterClasses(Statement statement) { List<FrameworkMethod> afters = fTestClass .getAnnotatedMethods(AfterClass.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, null); }
protected Statement withAfters(final Interaction interaction, final Object target, final Statement statement) { final List<FrameworkMethod> afters = testClass.getAnnotatedMethods(After.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, target); }
@SuppressWarnings("unchecked") @Override protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) { // We now to need to search in the class from the custom loader. //We also need to search with the annotation loaded by the custom class loader or otherwise // we don't find any method. List<FrameworkMethod> afters = testClassFromClassLoader .getAnnotatedMethods((Class<? extends Annotation>) afterFromClassLoader); return new RunAfters(statement, afters, target); }
@SuppressWarnings("unchecked") @Override protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) { // We now to need to search in the class from the custom loader. //We also need to search with the annotation loaded by the custom class loader or otherwise // we don't find any method. List<FrameworkMethod> afters = testClassFromClassLoader .getAnnotatedMethods((Class<? extends Annotation>) afterFromClassLoader); return new RunAfters(statement, afters, target); }
/** * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class and superclasses * before executing {@code statement}; all AfterClass methods are always executed: exceptions thrown by previous steps * are combined, if necessary, with exceptions from AfterClass methods into a * {@link org.junit.runners.model.MultipleFailureException}. */ protected Statement withAfterClasses(Statement statement) { List<FrameworkMethod> afters = testClass .getAnnotatedMethods(AfterClass.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, null); }
public Statement createStatement(final TestClass testClass, final Statement next, final Description description, final RunNotifier notifier) { final List<FrameworkMethod> afters = testClass.getAnnotatedMethods(AfterClass.class); return afters.isEmpty() ? next : new RunAfters(next, afters, null); } }
/** * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class * and superclasses after executing {@code statement}; all AfterClass methods are * always executed: exceptions thrown by previous steps are combined, if * necessary, with exceptions from AfterClass methods into a * {@link org.junit.runners.model.MultipleFailureException}. * * @see ParentRunner#withAfterClasses(org.junit.runners.model.Statement) */ public static Statement withAfterClasses(Statement statement, TestClass testClass) { List<FrameworkMethod> afters = testClass .getAnnotatedMethods(AfterClass.class); return afters.isEmpty() ? statement : new RunAfters(statement, afters, null); }