@Test public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnMethod() throws Exception { Class<?> clazz = getClass(); BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); afterListener.beforeTestClass(testContext); afterListener.afterTestClass(testContext); beforeListener.afterTestClass(testContext); verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class)); }
@Test public void beforeAndAfterTestMethodForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception { Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterClass.class; BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean")); beforeListener.beforeTestMethod(testContext); afterListener.beforeTestMethod(testContext); afterListener.afterTestMethod(testContext); beforeListener.afterTestMethod(testContext); verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class)); }
testExecutionListener.prepareTestInstance(getTestContext());
/** * Hook for pre-processing a test class <em>before</em> execution of any * tests within the class. Should be called prior to any framework-specific * <em>before class methods</em> (e.g., methods annotated with JUnit 4's * {@link org.junit.BeforeClass @BeforeClass}). * <p>An attempt will be made to give each registered * {@link TestExecutionListener} a chance to pre-process the test class * execution. If a listener throws an exception, however, the remaining * registered listeners will <strong>not</strong> be called. * @throws Exception if a registered TestExecutionListener throws an * exception * @since 3.0 * @see #getTestExecutionListeners() */ public void beforeTestClass() throws Exception { Class<?> testClass = getTestContext().getTestClass(); if (logger.isTraceEnabled()) { logger.trace("beforeTestClass(): class [" + testClass.getName() + "]"); } getTestContext().updateState(null, null, null); for (TestExecutionListener testExecutionListener : getTestExecutionListeners()) { try { testExecutionListener.beforeTestClass(getTestContext()); } catch (Throwable ex) { logException(ex, "beforeTestClass", testExecutionListener, testClass); ReflectionUtils.rethrowException(ex); } } }
testExecutionListener.beforeTestMethod(getTestContext());
testExecutionListener.afterTestClass(getTestContext());
testExecutionListener.afterTestMethod(getTestContext());
testExecutionListener.beforeTestExecution(getTestContext());
testExecutionListener.afterTestExecution(getTestContext());
public void call(TestExecutionListener listener) throws Exception { listener.beforeTestClass(testContext); } });
public void call(TestExecutionListener listener) throws Exception { listener.beforeTestMethod(testContext); } });
@Override public void afterTestClass(TestContext testContext) throws Exception { delegate.afterTestClass(testContext); } }
public void call(TestExecutionListener listener) throws Exception { listener.afterTestMethod(testContext); } });
@Override public void beforeTestExecution(TestContext testContext) throws Exception { delegate.beforeTestExecution(testContext); }
@Override public void afterTestExecution(TestContext testContext) throws Exception { delegate.afterTestExecution(testContext); }
@Test public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception { Class<?> clazz = DirtiesContextDeclaredLocallyAfterClass.class; BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean")); beforeListener.beforeTestMethod(testContext); afterListener.beforeTestMethod(testContext); afterListener.afterTestMethod(testContext); beforeListener.afterTestMethod(testContext); verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class)); }
@Test public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterEachTestMethod() throws Exception { Class<?> clazz = DirtiesContextDeclaredLocallyAfterEachTestMethod.class; BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); afterListener.beforeTestClass(testContext); afterListener.afterTestClass(testContext); beforeListener.afterTestClass(testContext); verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class)); }
@Override public void beforeTestClass(TestContext testContext) throws Exception { delegate.beforeTestClass(testContext); }
@Override public void beforeTestMethod(TestContext testContext) throws Exception { delegate.beforeTestMethod(testContext); }
public void call(TestExecutionListener listener) throws Exception { listener.afterTestClass(testContext); } });