Introduce DirtiesContextBeforeModesTestExecutionListener
SPR-12429 introduced various `BEFORE_*` modes in `@DirtiesContext`. To support these new modes, `DirtiesContextTestExecutionListener` (DCTEL) was updated to support both `BEFORE_*` and `AFTER_*` modes. However, there is a problem with having DCTEL support `BEFORE_*` modes since it is typically configured to execute after the `DependencyInjectionTestExecutionListener` (DITEL), and this leads to several undesired side effects: - The test's `ApplicationContext` is closed by DCTEL *after* dependencies have been injected into the test instance. - Injected dependencies may therefore attempt to interact with an `ApplicationContext` that is no longer _active_. - If a test has its `ApplicationContext` injected as a dependency, interaction with the context will likely fail since the context has been closed. - Any `TestExecutionListeners` registered after DCTEL will get a _new_ `ApplicationContext` if they invoke `getApplicationContext()` on the `TestContext`. This commit fixes these issues by introducing a new `DirtiesContextBeforeModesTestExecutionListener` (DCBMTEL) that is registered by default before DITEL. The previous support for `BEFORE_*` modes has been moved from DCTEL to DCBMTEL. In addition, an `AbstractDirtiesContextTestExecutionListener` has been extracted from DCTEL in order to avoid code duplication. Issue: SPR-13180
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.test.context;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -28,11 +27,13 @@ import org.springframework.core.annotation.AnnotationConfigurationException;
|
||||
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
|
||||
import org.springframework.test.context.support.AbstractTestExecutionListener;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.test.context.web.ServletTestExecutionListener;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
|
||||
|
||||
@@ -40,7 +41,7 @@ import static org.springframework.test.context.TestExecutionListeners.MergeMode.
|
||||
* Unit tests for the {@link TestExecutionListeners @TestExecutionListeners}
|
||||
* annotation, which verify:
|
||||
* <ul>
|
||||
* <li>Proper registering of {@link TestExecutionListener listeners} in
|
||||
* <li>Proper registering of {@linkplain TestExecutionListener listeners} in
|
||||
* conjunction with a {@link TestContextManager}</li>
|
||||
* <li><em>Inherited</em> functionality proposed in
|
||||
* <a href="https://jira.spring.io/browse/SPR-3896" target="_blank">SPR-3896</a></li>
|
||||
@@ -51,26 +52,12 @@ import static org.springframework.test.context.TestExecutionListeners.MergeMode.
|
||||
*/
|
||||
public class TestExecutionListenersTests {
|
||||
|
||||
private List<Class<?>> classes(TestContextManager testContextManager) {
|
||||
return testContextManager.getTestExecutionListeners().stream().map(listener -> listener.getClass()).collect(
|
||||
Collectors.toList());
|
||||
}
|
||||
|
||||
private List<String> names(List<Class<?>> classes) {
|
||||
return classes.stream().map(clazz -> clazz.getSimpleName()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void assertRegisteredListeners(Class<?> testClass, List<Class<?>> expected) {
|
||||
TestContextManager testContextManager = new TestContextManager(testClass);
|
||||
assertEquals("TELs registered for " + testClass.getSimpleName(), names(expected),
|
||||
names(classes(testContextManager)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultListeners() {
|
||||
List<Class<?>> expected = asList(ServletTestExecutionListener.class,
|
||||
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class);
|
||||
DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,
|
||||
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class,
|
||||
SqlScriptsTestExecutionListener.class);
|
||||
assertRegisteredListeners(DefaultListenersTestCase.class, expected);
|
||||
}
|
||||
|
||||
@@ -80,8 +67,9 @@ public class TestExecutionListenersTests {
|
||||
@Test
|
||||
public void defaultListenersMergedWithCustomListenerPrepended() {
|
||||
List<Class<?>> expected = asList(QuuxTestExecutionListener.class, ServletTestExecutionListener.class,
|
||||
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class);
|
||||
DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,
|
||||
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class,
|
||||
SqlScriptsTestExecutionListener.class);
|
||||
assertRegisteredListeners(MergedDefaultListenersWithCustomListenerPrependedTestCase.class, expected);
|
||||
}
|
||||
|
||||
@@ -91,9 +79,9 @@ public class TestExecutionListenersTests {
|
||||
@Test
|
||||
public void defaultListenersMergedWithCustomListenerAppended() {
|
||||
List<Class<?>> expected = asList(ServletTestExecutionListener.class,
|
||||
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class,
|
||||
BazTestExecutionListener.class);
|
||||
DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,
|
||||
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class,
|
||||
SqlScriptsTestExecutionListener.class, BazTestExecutionListener.class);
|
||||
assertRegisteredListeners(MergedDefaultListenersWithCustomListenerAppendedTestCase.class, expected);
|
||||
}
|
||||
|
||||
@@ -103,9 +91,9 @@ public class TestExecutionListenersTests {
|
||||
@Test
|
||||
public void defaultListenersMergedWithCustomListenerInserted() {
|
||||
List<Class<?>> expected = asList(ServletTestExecutionListener.class,
|
||||
DependencyInjectionTestExecutionListener.class, BarTestExecutionListener.class,
|
||||
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class,
|
||||
SqlScriptsTestExecutionListener.class);
|
||||
DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,
|
||||
BarTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class);
|
||||
assertRegisteredListeners(MergedDefaultListenersWithCustomListenerInsertedTestCase.class, expected);
|
||||
}
|
||||
|
||||
@@ -124,66 +112,47 @@ public class TestExecutionListenersTests {
|
||||
|
||||
@Test
|
||||
public void customListeners() {
|
||||
TestContextManager testContextManager = new TestContextManager(ExplicitListenersTestCase.class);
|
||||
assertEquals("Num registered TELs for ExplicitListenersTestCase.", 3,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(ExplicitListenersTestCase.class, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonInheritedListeners() {
|
||||
TestContextManager testContextManager = new TestContextManager(NonInheritedListenersTestCase.class);
|
||||
assertEquals("Num registered TELs for NonInheritedListenersTestCase.", 1,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(NonInheritedListenersTestCase.class, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inheritedListeners() {
|
||||
TestContextManager testContextManager = new TestContextManager(InheritedListenersTestCase.class);
|
||||
assertEquals("Num registered TELs for InheritedListenersTestCase.", 4,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(InheritedListenersTestCase.class, 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customListenersRegisteredViaMetaAnnotation() {
|
||||
TestContextManager testContextManager = new TestContextManager(MetaTestCase.class);
|
||||
assertEquals("Num registered TELs for MetaTestCase.", 3, testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(MetaTestCase.class, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonInheritedListenersRegisteredViaMetaAnnotation() {
|
||||
TestContextManager testContextManager = new TestContextManager(MetaNonInheritedListenersTestCase.class);
|
||||
assertEquals("Num registered TELs for MetaNonInheritedListenersTestCase.", 1,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(MetaNonInheritedListenersTestCase.class, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inheritedListenersRegisteredViaMetaAnnotation() {
|
||||
TestContextManager testContextManager = new TestContextManager(MetaInheritedListenersTestCase.class);
|
||||
assertEquals("Num registered TELs for MetaInheritedListenersTestCase.", 4,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(MetaInheritedListenersTestCase.class, 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customListenersRegisteredViaMetaAnnotationWithOverrides() {
|
||||
TestContextManager testContextManager = new TestContextManager(MetaWithOverridesTestCase.class);
|
||||
assertEquals("Num registered TELs for MetaWithOverridesTestCase.", 3,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(MetaWithOverridesTestCase.class, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customsListenersRegisteredViaMetaAnnotationWithInheritedListenersWithOverrides() {
|
||||
TestContextManager testContextManager = new TestContextManager(
|
||||
MetaInheritedListenersWithOverridesTestCase.class);
|
||||
assertEquals("Num registered TELs for MetaInheritedListenersWithOverridesTestCase.", 5,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(MetaInheritedListenersWithOverridesTestCase.class, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customListenersRegisteredViaMetaAnnotationWithNonInheritedListenersWithOverrides() {
|
||||
TestContextManager testContextManager = new TestContextManager(
|
||||
MetaNonInheritedListenersWithOverridesTestCase.class);
|
||||
assertEquals("Num registered TELs for MetaNonInheritedListenersWithOverridesTestCase.", 8,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertNumRegisteredListeners(MetaNonInheritedListenersWithOverridesTestCase.class, 8);
|
||||
}
|
||||
|
||||
@Test(expected = AnnotationConfigurationException.class)
|
||||
@@ -192,6 +161,27 @@ public class TestExecutionListenersTests {
|
||||
}
|
||||
|
||||
|
||||
private List<Class<?>> classes(TestContextManager testContextManager) {
|
||||
return testContextManager.getTestExecutionListeners().stream().map(Object::getClass).collect(toList());
|
||||
}
|
||||
|
||||
private List<String> names(List<Class<?>> classes) {
|
||||
return classes.stream().map(Class::getSimpleName).collect(toList());
|
||||
}
|
||||
|
||||
private void assertRegisteredListeners(Class<?> testClass, List<Class<?>> expected) {
|
||||
TestContextManager testContextManager = new TestContextManager(testClass);
|
||||
assertEquals("TELs registered for " + testClass.getSimpleName(), names(expected),
|
||||
names(classes(testContextManager)));
|
||||
}
|
||||
|
||||
private void assertNumRegisteredListeners(Class<?> testClass, int expected) {
|
||||
TestContextManager testContextManager = new TestContextManager(testClass);
|
||||
assertEquals("Num registered TELs for " + testClass, expected,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
static class DefaultListenersTestCase {
|
||||
|
||||
111
spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java
vendored
Normal file
111
spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.context.cache;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.test.annotation.DirtiesContext.MethodMode.*;
|
||||
|
||||
/**
|
||||
* Integration test which verifies correct interaction between the
|
||||
* {@link DirtiesContextBeforeModesTestExecutionListener},
|
||||
* {@link DependencyInjectionTestExecutionListener}, and
|
||||
* {@link DirtiesContextTestExecutionListener} when
|
||||
* {@link DirtiesContext @DirtiesContext} is used at the method level.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.2
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class MethodLevelDirtiesContextTests {
|
||||
|
||||
private static final AtomicInteger contextCount = new AtomicInteger();
|
||||
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
Integer count() {
|
||||
return contextCount.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
private Integer count;
|
||||
|
||||
|
||||
@Test
|
||||
// test## prefix required for @FixMethodOrder.
|
||||
public void test01() throws Exception {
|
||||
performAssertions(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = BEFORE_METHOD)
|
||||
// test## prefix required for @FixMethodOrder.
|
||||
public void test02_dirtyContextBeforeTestMethod() throws Exception {
|
||||
performAssertions(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
// test## prefix required for @FixMethodOrder.
|
||||
public void test03_dirtyContextAferTestMethod() throws Exception {
|
||||
performAssertions(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
// test## prefix required for @FixMethodOrder.
|
||||
public void test04() throws Exception {
|
||||
performAssertions(3);
|
||||
}
|
||||
|
||||
private void performAssertions(int expectedContextCreationCount) throws Exception {
|
||||
assertNotNull("context must not be null", this.context);
|
||||
assertTrue("context must be active", this.context.isActive());
|
||||
|
||||
assertNotNull("count must not be null", this.count);
|
||||
assertEquals("count: ", expectedContextCreationCount, this.count.intValue());
|
||||
|
||||
assertEquals("context creation count: ", expectedContextCreationCount, contextCount.get());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,22 +27,24 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
|
||||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.TestExecutionListener;
|
||||
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.*;
|
||||
import static org.springframework.test.annotation.DirtiesContext.HierarchyMode.*;
|
||||
import static org.springframework.test.annotation.DirtiesContext.MethodMode.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DirtiesContextTestExecutionListener}.
|
||||
* Unit tests for {@link DirtiesContextBeforeModesTestExecutionListener}.
|
||||
* and {@link DirtiesContextTestExecutionListener}
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.0
|
||||
*/
|
||||
public class DirtiesContextTestExecutionListenerTests {
|
||||
|
||||
private final DirtiesContextTestExecutionListener listener = new DirtiesContextTestExecutionListener();
|
||||
private final TestExecutionListener beforeListener = new DirtiesContextBeforeModesTestExecutionListener();
|
||||
private final TestExecutionListener afterListener = new DirtiesContextTestExecutionListener();
|
||||
private final TestContext testContext = mock(TestContext.class);
|
||||
|
||||
|
||||
@@ -52,9 +54,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(
|
||||
clazz.getDeclaredMethod("dirtiesContextDeclaredLocallyWithBeforeMethodMode"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
listener.afterTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -64,9 +68,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(
|
||||
clazz.getDeclaredMethod("dirtiesContextDeclaredLocallyWithAfterMethodMode"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
listener.afterTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -77,9 +83,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(
|
||||
clazz.getDeclaredMethod("dirtiesContextDeclaredViaMetaAnnotationWithAfterMethodMode"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
listener.afterTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -88,9 +96,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
Class<?> clazz = DirtiesContextDeclaredLocallyBeforeEachTestMethod.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
listener.afterTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -99,9 +109,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
Class<?> clazz = DirtiesContextDeclaredLocallyAfterEachTestMethod.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
listener.afterTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -111,9 +123,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterEachTestMethod.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
listener.afterTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -122,8 +136,10 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
Class<?> clazz = DirtiesContextDeclaredLocallyBeforeClass.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
listener.afterTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
}
|
||||
|
||||
@@ -132,8 +148,10 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
Class<?> clazz = DirtiesContextDeclaredLocallyAfterClass.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
listener.afterTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
}
|
||||
|
||||
@@ -142,8 +160,10 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterClass.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
listener.afterTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
}
|
||||
|
||||
@@ -152,9 +172,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
Class<?> clazz = DirtiesContextViaMetaAnnotationWithOverrides.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
|
||||
listener.beforeTestMethod(testContext);
|
||||
beforeListener.beforeTestMethod(testContext);
|
||||
afterListener.beforeTestMethod(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
listener.afterTestMethod(testContext);
|
||||
afterListener.afterTestMethod(testContext);
|
||||
beforeListener.afterTestMethod(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(CURRENT_LEVEL);
|
||||
}
|
||||
|
||||
@@ -164,8 +186,10 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnMethod() throws Exception {
|
||||
Class<?> clazz = getClass();
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
listener.afterTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
}
|
||||
|
||||
@@ -173,8 +197,10 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeEachTestMethod() throws Exception {
|
||||
Class<?> clazz = DirtiesContextDeclaredLocallyBeforeEachTestMethod.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
listener.afterTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
}
|
||||
|
||||
@@ -182,8 +208,10 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterEachTestMethod() throws Exception {
|
||||
Class<?> clazz = DirtiesContextDeclaredLocallyAfterEachTestMethod.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
listener.afterTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
}
|
||||
|
||||
@@ -192,8 +220,10 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
throws Exception {
|
||||
Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterEachTestMethod.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
listener.afterTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
}
|
||||
|
||||
@@ -201,9 +231,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeClass() throws Exception {
|
||||
Class<?> clazz = DirtiesContextDeclaredLocallyBeforeClass.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
listener.afterTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -211,9 +243,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception {
|
||||
Class<?> clazz = DirtiesContextDeclaredLocallyAfterClass.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
listener.afterTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -221,9 +255,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception {
|
||||
Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterClass.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
listener.afterTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
@@ -231,8 +267,10 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverrides() throws Exception {
|
||||
Class<?> clazz = DirtiesContextViaMetaAnnotationWithOverrides.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
listener.afterTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
}
|
||||
|
||||
@@ -241,9 +279,11 @@ public class DirtiesContextTestExecutionListenerTests {
|
||||
throws Exception {
|
||||
Class<?> clazz = DirtiesContextViaMetaAnnotationWithOverridenAttributes.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
listener.beforeTestClass(testContext);
|
||||
beforeListener.beforeTestClass(testContext);
|
||||
afterListener.beforeTestClass(testContext);
|
||||
verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
|
||||
listener.afterTestClass(testContext);
|
||||
afterListener.afterTestClass(testContext);
|
||||
beforeListener.afterTestClass(testContext);
|
||||
verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user