diff --git a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc index bbb97297e97..97bdec9d487 100644 --- a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc +++ b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc @@ -16,7 +16,7 @@ by default, exactly in the following order: Micrometer's `ObservationRegistry`. * `DirtiesContextTestExecutionListener`: Handles the `@DirtiesContext` annotation for "`after`" modes. -* `CommonCacheTestExecutionListener`: Clears resource caches in the test's +* `CommonCachesTestExecutionListener`: Clears resource caches in the test's `ApplicationContext` if necessary. * `TransactionalTestExecutionListener`: Provides transactional test execution with default rollback semantics. diff --git a/spring-test/src/main/java/org/springframework/test/context/support/CommonCacheTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/support/CommonCachesTestExecutionListener.java similarity index 89% rename from spring-test/src/main/java/org/springframework/test/context/support/CommonCacheTestExecutionListener.java rename to spring-test/src/main/java/org/springframework/test/context/support/CommonCachesTestExecutionListener.java index 5a47d225b72..34436b929ea 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/CommonCacheTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/CommonCachesTestExecutionListener.java @@ -21,8 +21,8 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.test.context.TestContext; /** - * {@code TestExecutionListener} which makes sure that caches are cleared once - * they are no longer required. + * {@code TestExecutionListener} which makes sure that common caches are cleared + * once they are no longer required. * *
Clears the resource caches of the {@link ApplicationContext} since they are * only required during the bean initialization phase. Runs after @@ -33,7 +33,7 @@ import org.springframework.test.context.TestContext; * @author Stephane Nicoll * @since 6.2 */ -public class CommonCacheTestExecutionListener extends AbstractTestExecutionListener { +public class CommonCachesTestExecutionListener extends AbstractTestExecutionListener { /** * Returns {@code 3005}. diff --git a/spring-test/src/main/resources/META-INF/spring.factories b/spring-test/src/main/resources/META-INF/spring.factories index deb80310e2f..ffae3b0b81e 100644 --- a/spring-test/src/main/resources/META-INF/spring.factories +++ b/spring-test/src/main/resources/META-INF/spring.factories @@ -8,7 +8,7 @@ org.springframework.test.context.TestExecutionListener = \ org.springframework.test.context.support.DependencyInjectionTestExecutionListener,\ org.springframework.test.context.observation.MicrometerObservationRegistryTestExecutionListener,\ org.springframework.test.context.support.DirtiesContextTestExecutionListener,\ - org.springframework.test.context.support.CommonCacheTestExecutionListener,\ + org.springframework.test.context.support.CommonCachesTestExecutionListener,\ org.springframework.test.context.transaction.TransactionalTestExecutionListener,\ org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener,\ org.springframework.test.context.event.EventPublishingTestExecutionListener,\ diff --git a/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java b/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java index eba96c3c2c0..ad36a45b28a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java @@ -32,7 +32,7 @@ import org.springframework.test.context.event.ApplicationEventsTestExecutionList import org.springframework.test.context.event.EventPublishingTestExecutionListener; import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener; import org.springframework.test.context.support.AbstractTestExecutionListener; -import org.springframework.test.context.support.CommonCacheTestExecutionListener; +import org.springframework.test.context.support.CommonCachesTestExecutionListener; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener; import org.springframework.test.context.support.DirtiesContextTestExecutionListener; @@ -73,7 +73,7 @@ class TestExecutionListenersTests { DependencyInjectionTestExecutionListener.class,// micrometerListenerClass,// DirtiesContextTestExecutionListener.class,// - CommonCacheTestExecutionListener.class, // + CommonCachesTestExecutionListener.class, // TransactionalTestExecutionListener.class,// SqlScriptsTestExecutionListener.class,// EventPublishingTestExecutionListener.class,// @@ -96,7 +96,7 @@ class TestExecutionListenersTests { DependencyInjectionTestExecutionListener.class,// micrometerListenerClass,// DirtiesContextTestExecutionListener.class,// - CommonCacheTestExecutionListener.class, // + CommonCachesTestExecutionListener.class, // TransactionalTestExecutionListener.class,// SqlScriptsTestExecutionListener.class,// EventPublishingTestExecutionListener.class,// @@ -118,7 +118,7 @@ class TestExecutionListenersTests { DependencyInjectionTestExecutionListener.class,// micrometerListenerClass,// DirtiesContextTestExecutionListener.class,// - CommonCacheTestExecutionListener.class, // + CommonCachesTestExecutionListener.class, // TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class,// EventPublishingTestExecutionListener.class,// @@ -142,7 +142,7 @@ class TestExecutionListenersTests { BarTestExecutionListener.class,// micrometerListenerClass,// DirtiesContextTestExecutionListener.class,// - CommonCacheTestExecutionListener.class, // + CommonCachesTestExecutionListener.class, // TransactionalTestExecutionListener.class,// SqlScriptsTestExecutionListener.class,// EventPublishingTestExecutionListener.class,// diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionCommonCacheTests.java b/spring-test/src/test/java/org/springframework/test/context/support/CommonCachesTestExecutionListenerIntegrationTests.java similarity index 91% rename from spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionCommonCacheTests.java rename to spring-test/src/test/java/org/springframework/test/context/support/CommonCachesTestExecutionListenerIntegrationTests.java index e0533bed267..7a4bbbebb4c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionCommonCacheTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/CommonCachesTestExecutionListenerIntegrationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.cache; +package org.springframework.test.context.support; import org.junit.jupiter.api.ClassOrderer; import org.junit.jupiter.api.Nested; @@ -31,6 +31,7 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.core.io.ResourceLoader; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import org.springframework.test.context.support.samples.SampleComponent; import static org.assertj.core.api.Assertions.assertThat; @@ -44,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @SpringJUnitConfig @TestClassOrder(ClassOrderer.OrderAnnotation.class) -class SpringExtensionCommonCacheTests { +class CommonCachesTestExecutionListenerIntegrationTests { @Autowired AbstractApplicationContext applicationContext; @@ -81,7 +82,7 @@ class SpringExtensionCommonCacheTests { String dummyBean(ResourceLoader resourceLoader) { ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true); scanner.setResourceLoader(resourceLoader); - scanner.findCandidateComponents(TestConfiguration.class.getPackageName()); + scanner.findCandidateComponents(SampleComponent.class.getPackageName()); return "Dummy"; } } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/CommonCacheTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/support/CommonCachesTestExecutionListenerTests.java similarity index 89% rename from spring-test/src/test/java/org/springframework/test/context/support/CommonCacheTestExecutionListenerTests.java rename to spring-test/src/test/java/org/springframework/test/context/support/CommonCachesTestExecutionListenerTests.java index c4b109f806e..49ba9afa233 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/CommonCacheTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/CommonCachesTestExecutionListenerTests.java @@ -27,13 +27,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; /** - * Tests for {@link CommonCacheTestExecutionListener}. + * Tests for {@link CommonCachesTestExecutionListener}. * * @author Stephane Nicoll */ -class CommonCacheTestExecutionListenerTests { +class CommonCachesTestExecutionListenerTests { - private final CommonCacheTestExecutionListener listener = new CommonCacheTestExecutionListener(); + private final CommonCachesTestExecutionListener listener = new CommonCachesTestExecutionListener(); @Test void afterTestClassWhenContextIsAvailable() throws Exception { diff --git a/spring-test/src/test/java/org/springframework/test/context/support/samples/SampleComponent.java b/spring-test/src/test/java/org/springframework/test/context/support/samples/SampleComponent.java new file mode 100644 index 00000000000..9dc3cdce24a --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/support/samples/SampleComponent.java @@ -0,0 +1,26 @@ +/* + * Copyright 2002-2024 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 + * + * https://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.support.samples; + +import org.springframework.stereotype.Component; + +/** + * Intended to be picked up by component scanning in tests in the support package. + */ +@Component +public class SampleComponent { +}