[SPR-6879] @DirtiesContext is now an @Inherited annotation.
This commit is contained in:
parent
ef227c5d01
commit
80b8fb8b83
|
|
@ -18,6 +18,7 @@ package org.springframework.test.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Inherited;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
@ -54,6 +55,7 @@ import java.lang.annotation.Target;
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
@Documented
|
@Documented
|
||||||
|
@Inherited
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target( { ElementType.TYPE, ElementType.METHOD })
|
@Target( { ElementType.TYPE, ElementType.METHOD })
|
||||||
public @interface DirtiesContext {
|
public @interface DirtiesContext {
|
||||||
|
|
|
||||||
|
|
@ -103,50 +103,71 @@ public class ClassLevelDirtiesContextTests {
|
||||||
@Test
|
@Test
|
||||||
public void verifyDirtiesContextBehavior() throws Exception {
|
public void verifyDirtiesContextBehavior() throws Exception {
|
||||||
|
|
||||||
runTestClassAndAssertStats(CleanTestCase.class, 1);
|
assertBehaviorForCleanTestCase();
|
||||||
assertCacheStats("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet());
|
|
||||||
|
|
||||||
runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase.class, 1);
|
runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase.class, 1);
|
||||||
assertCacheStats("after class-level @DirtiesContext with clean test method and default class mode", 0,
|
assertCacheStats("after class-level @DirtiesContext with clean test method and default class mode", 0,
|
||||||
cacheHits.incrementAndGet(), cacheMisses.get());
|
cacheHits.incrementAndGet(), cacheMisses.get());
|
||||||
|
assertBehaviorForCleanTestCase();
|
||||||
|
|
||||||
runTestClassAndAssertStats(CleanTestCase.class, 1);
|
runTestClassAndAssertStats(InheritedClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase.class, 1);
|
||||||
assertCacheStats("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet());
|
assertCacheStats("after inherited class-level @DirtiesContext with clean test method and default class mode",
|
||||||
|
0, cacheHits.incrementAndGet(), cacheMisses.get());
|
||||||
|
assertBehaviorForCleanTestCase();
|
||||||
|
|
||||||
runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase.class, 1);
|
runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase.class, 1);
|
||||||
assertCacheStats("after class-level @DirtiesContext with clean test method and AFTER_CLASS mode", 0,
|
assertCacheStats("after class-level @DirtiesContext with clean test method and AFTER_CLASS mode", 0,
|
||||||
cacheHits.incrementAndGet(), cacheMisses.get());
|
cacheHits.incrementAndGet(), cacheMisses.get());
|
||||||
|
assertBehaviorForCleanTestCase();
|
||||||
|
|
||||||
runTestClassAndAssertStats(CleanTestCase.class, 1);
|
runTestClassAndAssertStats(InheritedClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase.class, 1);
|
||||||
assertCacheStats("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet());
|
assertCacheStats("after inherited class-level @DirtiesContext with clean test method and AFTER_CLASS mode", 0,
|
||||||
|
cacheHits.incrementAndGet(), cacheMisses.get());
|
||||||
|
assertBehaviorForCleanTestCase();
|
||||||
|
|
||||||
runTestClassAndAssertStats(ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase.class, 3);
|
runTestClassAndAssertStats(ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase.class, 3);
|
||||||
assertCacheStats("after class-level @DirtiesContext with clean test method and AFTER_EACH_TEST_METHOD mode", 0,
|
assertCacheStats("after class-level @DirtiesContext with clean test method and AFTER_EACH_TEST_METHOD mode", 0,
|
||||||
cacheHits.incrementAndGet(), cacheMisses.addAndGet(2));
|
cacheHits.incrementAndGet(), cacheMisses.addAndGet(2));
|
||||||
|
assertBehaviorForCleanTestCase();
|
||||||
|
|
||||||
runTestClassAndAssertStats(CleanTestCase.class, 1);
|
runTestClassAndAssertStats(InheritedClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase.class, 3);
|
||||||
assertCacheStats("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet());
|
assertCacheStats(
|
||||||
|
"after inherited class-level @DirtiesContext with clean test method and AFTER_EACH_TEST_METHOD mode", 0,
|
||||||
|
cacheHits.incrementAndGet(), cacheMisses.addAndGet(2));
|
||||||
|
assertBehaviorForCleanTestCase();
|
||||||
|
|
||||||
runTestClassAndAssertStats(ClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
runTestClassAndAssertStats(ClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
||||||
assertCacheStats("after class-level @DirtiesContext with dirty test method", 0, cacheHits.incrementAndGet(),
|
assertCacheStats("after class-level @DirtiesContext with dirty test method", 0, cacheHits.incrementAndGet(),
|
||||||
cacheMisses.get());
|
cacheMisses.get());
|
||||||
|
|
||||||
runTestClassAndAssertStats(ClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
runTestClassAndAssertStats(ClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
||||||
assertCacheStats("after class-level @DirtiesContext with dirty test method", 0, cacheHits.get(),
|
assertCacheStats("after class-level @DirtiesContext with dirty test method", 0, cacheHits.get(),
|
||||||
cacheMisses.incrementAndGet());
|
cacheMisses.incrementAndGet());
|
||||||
|
|
||||||
runTestClassAndAssertStats(ClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
runTestClassAndAssertStats(ClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
||||||
assertCacheStats("after class-level @DirtiesContext with dirty test method", 0, cacheHits.get(),
|
assertCacheStats("after class-level @DirtiesContext with dirty test method", 0, cacheHits.get(),
|
||||||
cacheMisses.incrementAndGet());
|
cacheMisses.incrementAndGet());
|
||||||
|
assertBehaviorForCleanTestCase();
|
||||||
|
|
||||||
runTestClassAndAssertStats(CleanTestCase.class, 1);
|
runTestClassAndAssertStats(InheritedClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
||||||
assertCacheStats("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet());
|
assertCacheStats("after inherited class-level @DirtiesContext with dirty test method", 0,
|
||||||
|
cacheHits.incrementAndGet(), cacheMisses.get());
|
||||||
|
runTestClassAndAssertStats(InheritedClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
||||||
|
assertCacheStats("after inherited class-level @DirtiesContext with dirty test method", 0, cacheHits.get(),
|
||||||
|
cacheMisses.incrementAndGet());
|
||||||
|
runTestClassAndAssertStats(InheritedClassLevelDirtiesContextWithDirtyMethodsTestCase.class, 1);
|
||||||
|
assertCacheStats("after inherited class-level @DirtiesContext with dirty test method", 0, cacheHits.get(),
|
||||||
|
cacheMisses.incrementAndGet());
|
||||||
|
assertBehaviorForCleanTestCase();
|
||||||
|
|
||||||
runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase.class, 1);
|
runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase.class, 1);
|
||||||
assertCacheStats("after class-level @DirtiesContext with clean test method and AFTER_CLASS mode", 0,
|
assertCacheStats("after class-level @DirtiesContext with clean test method and AFTER_CLASS mode", 0,
|
||||||
cacheHits.incrementAndGet(), cacheMisses.get());
|
cacheHits.incrementAndGet(), cacheMisses.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertBehaviorForCleanTestCase() {
|
||||||
|
runTestClassAndAssertStats(CleanTestCase.class, 1);
|
||||||
|
assertCacheStats("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet());
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void verifyFinalCacheState() {
|
public static void verifyFinalCacheState() {
|
||||||
assertCacheStats("AfterClass", 0, cacheHits.get(), cacheMisses.get());
|
assertCacheStats("AfterClass", 0, cacheHits.get(), cacheMisses.get());
|
||||||
|
|
@ -180,7 +201,7 @@ public class ClassLevelDirtiesContextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public static final class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends BaseTestCase {
|
public static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends BaseTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void verifyContextWasAutowired() {
|
public void verifyContextWasAutowired() {
|
||||||
|
|
@ -188,8 +209,12 @@ public class ClassLevelDirtiesContextTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class InheritedClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends
|
||||||
|
ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase {
|
||||||
|
}
|
||||||
|
|
||||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||||
public static final class ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends BaseTestCase {
|
public static class ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends BaseTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void verifyContextWasAutowired() {
|
public void verifyContextWasAutowired() {
|
||||||
|
|
@ -197,8 +222,12 @@ public class ClassLevelDirtiesContextTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class InheritedClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends
|
||||||
|
ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase {
|
||||||
|
}
|
||||||
|
|
||||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
public static final class ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends BaseTestCase {
|
public static class ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends BaseTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void verifyContextWasAutowired1() {
|
public void verifyContextWasAutowired1() {
|
||||||
|
|
@ -216,8 +245,12 @@ public class ClassLevelDirtiesContextTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class InheritedClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends
|
||||||
|
ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase {
|
||||||
|
}
|
||||||
|
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public static final class ClassLevelDirtiesContextWithDirtyMethodsTestCase extends BaseTestCase {
|
public static class ClassLevelDirtiesContextWithDirtyMethodsTestCase extends BaseTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
|
|
@ -226,4 +259,8 @@ public class ClassLevelDirtiesContextTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class InheritedClassLevelDirtiesContextWithDirtyMethodsTestCase extends
|
||||||
|
ClassLevelDirtiesContextWithDirtyMethodsTestCase {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue