/** * 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); } } }
@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 beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeEachTestMethod() throws Exception { Class<?> clazz = DirtiesContextDeclaredLocallyBeforeEachTestMethod.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)); }
@Test public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterEachTestMethod() throws Exception { Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterEachTestMethod.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)); }
@Test public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverrides() throws Exception { Class<?> clazz = DirtiesContextViaMetaAnnotationWithOverrides.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)); }
@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)); }
@Test public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeClass() throws Exception { Class<?> clazz = DirtiesContextDeclaredLocallyBeforeClass.class; BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); afterListener.beforeTestClass(testContext); verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE); afterListener.afterTestClass(testContext); beforeListener.afterTestClass(testContext); verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE); }
@Test public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception { Class<?> clazz = DirtiesContextDeclaredLocallyAfterClass.class; BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); afterListener.beforeTestClass(testContext); verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class)); afterListener.afterTestClass(testContext); beforeListener.afterTestClass(testContext); verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE); }
@Test public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception { Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterClass.class; BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); afterListener.beforeTestClass(testContext); verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class)); afterListener.afterTestClass(testContext); beforeListener.afterTestClass(testContext); verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE); }
@Test public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverridenAttributes() throws Exception { Class<?> clazz = DirtiesContextViaMetaAnnotationWithOverridenAttributes.class; BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); afterListener.beforeTestClass(testContext); verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class)); afterListener.afterTestClass(testContext); beforeListener.afterTestClass(testContext); verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE); }
public void call(TestExecutionListener listener) throws Exception { listener.beforeTestClass(testContext); } });
@Override public void beforeTestClass(TestContext testContext) throws Exception { delegate.beforeTestClass(testContext); }
@Override public void beforeTestClass(TestContext testContext) throws Exception { delegate.beforeTestClass(testContext); }
public void call(TestExecutionListener listener) throws Exception { listener.beforeTestClass(testContext); } });
testExecutionListener.beforeTestClass(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); } } }