/** * Delegates to the configured {@link TestContextManager} to call * {@linkplain TestContextManager#afterTestClass() 'after test class'} callbacks. * @throws Exception if a registered TestExecutionListener throws an exception */ @AfterClass(alwaysRun = true) protected void springTestContextAfterTestClass() throws Exception { this.testContextManager.afterTestClass(); }
/** * Evaluate the next {@link Statement} in the execution chain (typically an instance of * {@link org.junit.internal.runners.statements.RunAfters RunAfters}), catching any * exceptions thrown, and then invoke {@link TestContextManager#afterTestClass()}. * <p>If the invocation of {@code afterTestClass()} throws an exception, it will also * be tracked. Multiple exceptions will be combined into a {@link MultipleFailureException}. */ @Override public void evaluate() throws Throwable { List<Throwable> errors = new ArrayList<>(); try { this.next.evaluate(); } catch (Throwable ex) { errors.add(ex); } try { this.testContextManager.afterTestClass(); } catch (Throwable ex) { errors.add(ex); } MultipleFailureException.assertEmpty(errors); }
/** * Delegates to {@link TestContextManager#afterTestClass}. */ @Override public void afterAll(ExtensionContext context) throws Exception { try { getTestContextManager(context).afterTestClass(); } finally { getStore(context).remove(context.getRequiredTestClass()); } }
@Test public void afterTestClass() throws Exception { test("afterTestClass", FailingAfterTestClassTestCase.class, (tcm, c, m) -> tcm.afterTestClass()); }
@Test public void invokeTestContextManagerFromConcurrentThreads() { TestContextManager tcm = new TestContextManager(TestCase.class); // Run the actual test several times in order to increase the chance of threads // stepping on each others' toes by overwriting the same mutable state in the // TestContext. IntStream.range(1, 20).forEach(i -> { actualMethods.clear(); // Execute TestExecutionListener in parallel, thereby simulating parallel // test method execution. stream(TestCase.class.getDeclaredMethods()).parallel().forEach(testMethod -> { try { tcm.beforeTestClass(); tcm.beforeTestMethod(testInstance, testMethod); // no need to invoke the actual test method tcm.afterTestMethod(testInstance, testMethod, null); tcm.afterTestClass(); } catch (Exception ex) { throw new RuntimeException(ex); } }); assertThat(actualMethods, equalTo(expectedMethods)); }); assertEquals(0, tcm.getTestContext().attributeNames().length); }
@Override public void runBare() throws Throwable { testContextManager.prepareTestInstance(this); // this will initialize all dependencies try { super.runBare(); } finally { testContextManager.afterTestClass(); applicationContext.close(); clearTestContextCache(testContextManager); applicationContext = null; processEngine = null; testContextManager = null; CachedIntrospectionResults.clearClassLoader(getClass().getClassLoader()); } }
/** * Delegates to the configured {@link TestContextManager} to call * {@link TestContextManager#afterTestClass() 'after test class'} callbacks. * * @throws Exception if a registered TestExecutionListener throws an * exception */ @AfterClass(alwaysRun = true) protected void springTestContextAfterTestClass() throws Exception { this.testContextManager.afterTestClass(); }
/** * Delegates to the configured {@link TestContextManager} to call * {@linkplain TestContextManager#afterTestClass() 'after test class'} callbacks. * @throws Exception if a registered TestExecutionListener throws an exception */ @AfterClass(alwaysRun = true) protected void springTestContextAfterTestClass() throws Exception { this.testContextManager.afterTestClass(); }
/** * Evaluate the next {@link Statement} in the execution chain (typically an instance of * {@link org.junit.internal.runners.statements.RunAfters RunAfters}), catching any * exceptions thrown, and then invoke {@link TestContextManager#afterTestClass()}. * <p>If the invocation of {@code afterTestClass()} throws an exception, it will also * be tracked. Multiple exceptions will be combined into a {@link MultipleFailureException}. */ @Override public void evaluate() throws Throwable { List<Throwable> errors = new ArrayList<Throwable>(); try { this.next.evaluate(); } catch (Throwable ex) { errors.add(ex); } try { this.testContextManager.afterTestClass(); } catch (Throwable ex) { errors.add(ex); } MultipleFailureException.assertEmpty(errors); }
/** * Evaluate the next {@link Statement} in the execution chain (typically an instance of * {@link org.junit.internal.runners.statements.RunAfters RunAfters}), catching any * exceptions thrown, and then invoke {@link TestContextManager#afterTestClass()}. * <p>If the invocation of {@code afterTestClass()} throws an exception, it will also * be tracked. Multiple exceptions will be combined into a {@link MultipleFailureException}. */ @Override public void evaluate() throws Throwable { List<Throwable> errors = new ArrayList<>(); try { this.next.evaluate(); } catch (Throwable ex) { errors.add(ex); } try { this.testContextManager.afterTestClass(); } catch (Throwable ex) { errors.add(ex); } MultipleFailureException.assertEmpty(errors); }
/** * Delegates to {@link TestContextManager#afterTestClass}. */ @Override public void afterAll(ExtensionContext context) throws Exception { try { getTestContextManager(context).afterTestClass(); } finally { getStore(context).remove(context.getRequiredTestClass()); } }
/** * Delegates to {@link TestContextManager#afterTestClass}. */ @Override public void afterAll(ExtensionContext context) throws Exception { try { getTestContextManager(context).afterTestClass(); } finally { getStore(context).remove(context.getRequiredTestClass()); } }
/** * Delegates to {@link TestContextManager#afterTestClass}. */ @Override public void afterAll(ExtensionContext context) throws Exception { try { getTestContextManager(context).afterTestClass(); } finally { getStore(context).remove(context.getRequiredTestClass()); } }