diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java index 0b1ecee657..23e56c1c1c 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java @@ -386,6 +386,7 @@ public abstract class TestContextAnnotationUtils { } static void clearCaches() { + cachedEnclosingConfigurationModes.clear(); defaultEnclosingConfigurationMode = null; } diff --git a/spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java index 160cf4f3f3..3c2b7c0355 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestContextAnnotationUtilsTests.java @@ -69,17 +69,17 @@ class TestContextAnnotationUtilsTests { @Test void standardDefaultMode() { - assertThat(searchEnclosingClass(OuterTestCase1.class)).isFalse(); - assertThat(searchEnclosingClass(OuterTestCase1.NestedTestCase.class)).isTrue(); - assertThat(searchEnclosingClass(OuterTestCase1.NestedTestCase.DoubleNestedTestCase.class)).isTrue(); + assertThat(searchEnclosingClass(OuterTestCase.class)).isFalse(); + assertThat(searchEnclosingClass(OuterTestCase.NestedTestCase.class)).isTrue(); + assertThat(searchEnclosingClass(OuterTestCase.NestedTestCase.DoubleNestedTestCase.class)).isTrue(); } @Test void overriddenDefaultMode() { setGlobalFlag("\t" + OVERRIDE.name().toLowerCase() + " "); - assertThat(searchEnclosingClass(OuterTestCase2.class)).isFalse(); - assertThat(searchEnclosingClass(OuterTestCase2.NestedTestCase.class)).isFalse(); - assertThat(searchEnclosingClass(OuterTestCase2.NestedTestCase.DoubleNestedTestCase.class)).isFalse(); + assertThat(searchEnclosingClass(OuterTestCase.class)).isFalse(); + assertThat(searchEnclosingClass(OuterTestCase.NestedTestCase.class)).isFalse(); + assertThat(searchEnclosingClass(OuterTestCase.NestedTestCase.DoubleNestedTestCase.class)).isFalse(); } private void setGlobalFlag(String flag) { @@ -675,16 +675,7 @@ class TestContextAnnotationUtilsTests { static class MetaAnnotatedAndSuperAnnotatedContextConfigClass extends AnnotatedContextConfigClass { } - // We need two variants of "OuterTestCase", since the results for searchEnclosingClass() get cached. - static class OuterTestCase1 { - class NestedTestCase { - class DoubleNestedTestCase { - } - } - } - - // We need two variants of "OuterTestCase", since the results for searchEnclosingClass() get cached. - static class OuterTestCase2 { + static class OuterTestCase { class NestedTestCase { class DoubleNestedTestCase { }