diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr6128/AutowiredQualifierTests.java b/spring-test/src/test/java/org/springframework/test/context/AutowiredQualifierTests.java similarity index 64% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr6128/AutowiredQualifierTests.java rename to spring-test/src/test/java/org/springframework/test/context/AutowiredQualifierTests.java index 8436a50c95..5101960d4e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr6128/AutowiredQualifierTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/AutowiredQualifierTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,30 +14,26 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr6128; +package org.springframework.test.context; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** - * Integration tests to verify claims made in SPR-6128. + * Integration tests to verify claims made in + * gh-10796. * * @author Sam Brannen * @author Chris Beams * @since 3.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -public class AutowiredQualifierTests { +@SpringJUnitConfig +class AutowiredQualifierTests { @Autowired private String foo; @@ -48,7 +44,7 @@ public class AutowiredQualifierTests { @Test - public void test() { + void test() { assertThat(foo).isEqualTo("normal"); assertThat(customFoo).isEqualTo("custom"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java index 41388fc7da..57d6ad93f3 100644 --- a/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -20,9 +20,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import org.junit.runner.JUnitCore; -import org.junit.runner.Result; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.testkit.engine.EngineTestKit; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -32,9 +31,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; /** * Integration tests that verify proper behavior of {@link DirtiesContext @DirtiesContext} @@ -87,9 +87,11 @@ class ContextHierarchyDirtiesContextTests { private void runTestAndVerifyHierarchies(Class testClass, boolean isFooContextActive, boolean isBarContextActive, boolean isBazContextActive) { - JUnitCore jUnitCore = new JUnitCore(); - Result result = jUnitCore.run(testClass); - assertThat(result.wasSuccessful()).as("all tests passed").isTrue(); + EngineTestKit.engine("junit-jupiter") + .selectors(selectClass(testClass)) + .execute() + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1).failed(0)); assertThat(ContextHierarchyDirtiesContextTests.context).isNotNull(); @@ -111,7 +113,7 @@ class ContextHierarchyDirtiesContextTests { // ------------------------------------------------------------------------- - @RunWith(SpringRunner.class) + @ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration(name = "foo")) abstract static class FooTestCase implements ApplicationContextAware { @@ -170,10 +172,10 @@ class ContextHierarchyDirtiesContextTests { * context. */ @DirtiesContext - public static class ClassLevelDirtiesContextWithExhaustiveModeTestCase extends BazTestCase { + static class ClassLevelDirtiesContextWithExhaustiveModeTestCase extends BazTestCase { - @org.junit.Test - public void test() { + @Test + void test() { } } @@ -184,10 +186,10 @@ class ContextHierarchyDirtiesContextTests { * beginning from the current context hierarchy and down through all subhierarchies. */ @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL) - public static class ClassLevelDirtiesContextWithCurrentLevelModeTestCase extends BazTestCase { + static class ClassLevelDirtiesContextWithCurrentLevelModeTestCase extends BazTestCase { - @org.junit.Test - public void test() { + @Test + void test() { } } @@ -199,11 +201,11 @@ class ContextHierarchyDirtiesContextTests { * parent context, and then back down through all subhierarchies of the parent * context. */ - public static class MethodLevelDirtiesContextWithExhaustiveModeTestCase extends BazTestCase { + static class MethodLevelDirtiesContextWithExhaustiveModeTestCase extends BazTestCase { - @org.junit.Test + @Test @DirtiesContext - public void test() { + void test() { } } @@ -213,11 +215,11 @@ class ContextHierarchyDirtiesContextTests { *

After running this test class, the context cache should be cleared * beginning from the current context hierarchy and down through all subhierarchies. */ - public static class MethodLevelDirtiesContextWithCurrentLevelModeTestCase extends BazTestCase { + static class MethodLevelDirtiesContextWithCurrentLevelModeTestCase extends BazTestCase { - @org.junit.Test + @Test @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL) - public void test() { + void test() { } } diff --git a/spring-test/src/test/java/org/springframework/test/context/SpringTestContextFrameworkTestSuite.java b/spring-test/src/test/java/org/springframework/test/context/SpringTestContextFrameworkTestSuite.java index 4500d55668..cb4b809abf 100644 --- a/spring-test/src/test/java/org/springframework/test/context/SpringTestContextFrameworkTestSuite.java +++ b/spring-test/src/test/java/org/springframework/test/context/SpringTestContextFrameworkTestSuite.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2025 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. @@ -16,6 +16,8 @@ package org.springframework.test.context; +import org.junit.jupiter.api.ClassOrderer; +import org.junit.platform.suite.api.ConfigurationParameter; import org.junit.platform.suite.api.ExcludeTags; import org.junit.platform.suite.api.IncludeClassNamePatterns; import org.junit.platform.suite.api.SelectPackages; @@ -44,5 +46,9 @@ import org.junit.platform.suite.api.Suite; @SelectPackages("org.springframework.test.context") @IncludeClassNamePatterns(".*Tests?$") @ExcludeTags("failing-test-case") +@ConfigurationParameter( + key = ClassOrderer.DEFAULT_ORDER_PROPERTY_NAME, + value = "org.junit.jupiter.api.ClassOrderer$ClassName" + ) class SpringTestContextFrameworkTestSuite { } diff --git a/spring-test/src/test/java/org/springframework/test/context/annotation/AnnotationConfigTestSuite.java b/spring-test/src/test/java/org/springframework/test/context/annotation/AnnotationConfigTestSuite.java new file mode 100644 index 0000000000..8331b926dd --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/AnnotationConfigTestSuite.java @@ -0,0 +1,54 @@ +/* + * Copyright 2002-2025 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.annotation; + +import org.junit.jupiter.api.ClassOrderer; +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.IncludeClassNamePatterns; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.SelectPackages; +import org.junit.platform.suite.api.Suite; + +/** + * JUnit Platform based test suite annotation-driven configuration class + * support in the Spring TestContext Framework. + * + *

This suite is only intended to be used manually within an IDE. + * + *

Logging Configuration

+ * + *

In order for our log4j2 configuration to be used in an IDE, you must + * set the following system property before running any tests — for + * example, in Run Configurations in Eclipse. + * + *

+ * -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
+ * 
+ * + * @author Sam Brannen + * @since 3.1 + */ +@Suite +@IncludeEngines("junit-jupiter") +@SelectPackages("org.springframework.test.context.annotation") +@IncludeClassNamePatterns(".*Tests$") +@ConfigurationParameter( + key = ClassOrderer.DEFAULT_ORDER_PROPERTY_NAME, + value = "org.junit.jupiter.api.ClassOrderer$ClassName" +) +public class AnnotationConfigTestSuite { +} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingDefaultConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/BeanOverridingDefaultConfigClassesInheritedTests.java similarity index 82% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingDefaultConfigClassesInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/BeanOverridingDefaultConfigClassesInheritedTests.java index 9e0b2378dd..f518595c59 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingDefaultConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/BeanOverridingDefaultConfigClassesInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.context.annotation.Bean; @@ -36,13 +36,21 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ContextConfiguration -public class BeanOverridingDefaultConfigClassesInheritedTests extends DefaultConfigClassesBaseTests { +class BeanOverridingDefaultConfigClassesInheritedTests extends DefaultConfigClassesBaseTests { - @Configuration + @Test + @Override + void verifyEmployeeSetFromBaseContextConfig() { + assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); + assertThat(this.employee.getName()).as("The employee bean should have been overridden.").isEqualTo("Yoda"); + } + + + @Configuration(proxyBeanMethods = false) static class ContextConfiguration { @Bean - public Employee employee() { + Employee employee() { Employee employee = new Employee(); employee.setName("Yoda"); employee.setAge(900); @@ -51,12 +59,4 @@ public class BeanOverridingDefaultConfigClassesInheritedTests extends DefaultCon } } - - @Test - @Override - public void verifyEmployeeSetFromBaseContextConfig() { - assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); - assertThat(this.employee.getName()).as("The employee bean should have been overridden.").isEqualTo("Yoda"); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingExplicitConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/BeanOverridingExplicitConfigClassesInheritedTests.java similarity index 82% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingExplicitConfigClassesInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/BeanOverridingExplicitConfigClassesInheritedTests.java index 31fb3d0ecf..85224b4a42 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingExplicitConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/BeanOverridingExplicitConfigClassesInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ContextConfiguration; @@ -33,11 +33,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ContextConfiguration(classes = BeanOverridingDefaultConfigClassesInheritedTests.ContextConfiguration.class) -public class BeanOverridingExplicitConfigClassesInheritedTests extends ExplicitConfigClassesBaseTests { +class BeanOverridingExplicitConfigClassesInheritedTests extends ExplicitConfigClassesBaseTests { @Test @Override - public void verifyEmployeeSetFromBaseContextConfig() { + void verifyEmployeeSetFromBaseContextConfig() { assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); assertThat(this.employee.getName()).as("The employee bean should have been overridden.").isEqualTo("Yoda"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesBaseTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultConfigClassesBaseTests.java similarity index 73% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesBaseTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/DefaultConfigClassesBaseTests.java index 557e37eaee..73393f584e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesBaseTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultConfigClassesBaseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,17 +14,15 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.AnnotationConfigContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -39,15 +37,25 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 * @see DefaultLoaderDefaultConfigClassesBaseTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class DefaultConfigClassesBaseTests { +@SpringJUnitConfig(loader = AnnotationConfigContextLoader.class) +class DefaultConfigClassesBaseTests { - @Configuration + @Autowired + Employee employee; + + + @Test + void verifyEmployeeSetFromBaseContextConfig() { + assertThat(this.employee).as("The employee field should have been autowired.").isNotNull(); + assertThat(this.employee.getName()).isEqualTo("John Smith"); + } + + + @Configuration(proxyBeanMethods = false) static class ContextConfiguration { @Bean - public Employee employee() { + Employee employee() { Employee employee = new Employee(); employee.setName("John Smith"); employee.setAge(42); @@ -56,15 +64,4 @@ public class DefaultConfigClassesBaseTests { } } - - @Autowired - protected Employee employee; - - - @Test - public void verifyEmployeeSetFromBaseContextConfig() { - assertThat(this.employee).as("The employee field should have been autowired.").isNotNull(); - assertThat(this.employee.getName()).isEqualTo("John Smith"); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultConfigClassesInheritedTests.java similarity index 81% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/DefaultConfigClassesInheritedTests.java index 9604c8f520..2df5ca99a1 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultConfigClassesInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Pet; @@ -37,26 +37,26 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ContextConfiguration -public class DefaultConfigClassesInheritedTests extends DefaultConfigClassesBaseTests { - - @Configuration - static class ContextConfiguration { - - @Bean - public Pet pet() { - return new Pet("Fido"); - } - } - +class DefaultConfigClassesInheritedTests extends DefaultConfigClassesBaseTests { @Autowired - private Pet pet; + Pet pet; @Test - public void verifyPetSetFromExtendedContextConfig() { + void verifyPetSetFromExtendedContextConfig() { assertThat(this.pet).as("The pet should have been autowired.").isNotNull(); assertThat(this.pet.getName()).isEqualTo("Fido"); } + + @Configuration(proxyBeanMethods = false) + static class ContextConfiguration { + + @Bean + Pet pet() { + return new Pet("Fido"); + } + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.java similarity index 83% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.java index e530a99ee4..a19fa97448 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.context.annotation.Bean; @@ -35,14 +35,22 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ContextConfiguration -public class DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests extends +class DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests extends DefaultLoaderDefaultConfigClassesBaseTests { - @Configuration + @Test + @Override + void verifyEmployeeSetFromBaseContextConfig() { + assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); + assertThat(this.employee.getName()).as("The employee bean should have been overridden.").isEqualTo("Yoda"); + } + + + @Configuration(proxyBeanMethods = false) static class Config { @Bean - public Employee employee() { + Employee employee() { Employee employee = new Employee(); employee.setName("Yoda"); employee.setAge(900); @@ -51,12 +59,4 @@ public class DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests exten } } - - @Test - @Override - public void verifyEmployeeSetFromBaseContextConfig() { - assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); - assertThat(this.employee.getName()).as("The employee bean should have been overridden.").isEqualTo("Yoda"); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests.java similarity index 83% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests.java index 4be240ce7e..ac98527530 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.support.DelegatingSmartContextLoader; @@ -32,12 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ContextConfiguration(classes = DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.Config.class) -public class DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests extends +class DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests extends DefaultLoaderExplicitConfigClassesBaseTests { @Test @Override - public void verifyEmployeeSetFromBaseContextConfig() { + void verifyEmployeeSetFromBaseContextConfig() { assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); assertThat(this.employee.getName()).as("The employee bean should have been overridden.").isEqualTo("Yoda"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderDefaultConfigClassesBaseTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderDefaultConfigClassesBaseTests.java similarity index 74% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderDefaultConfigClassesBaseTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderDefaultConfigClassesBaseTests.java index b032b6e4bc..4b822712eb 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderDefaultConfigClassesBaseTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderDefaultConfigClassesBaseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,17 +14,15 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.DelegatingSmartContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -38,15 +36,25 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 * @see DefaultConfigClassesBaseTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class DefaultLoaderDefaultConfigClassesBaseTests { +@SpringJUnitConfig +class DefaultLoaderDefaultConfigClassesBaseTests { - @Configuration + @Autowired + Employee employee; + + + @Test + void verifyEmployeeSetFromBaseContextConfig() { + assertThat(this.employee).as("The employee field should have been autowired.").isNotNull(); + assertThat(this.employee.getName()).isEqualTo("John Smith"); + } + + + @Configuration(proxyBeanMethods = false) static class Config { @Bean - public Employee employee() { + Employee employee() { Employee employee = new Employee(); employee.setName("John Smith"); employee.setAge(42); @@ -55,15 +63,4 @@ public class DefaultLoaderDefaultConfigClassesBaseTests { } } - - @Autowired - protected Employee employee; - - - @Test - public void verifyEmployeeSetFromBaseContextConfig() { - assertThat(this.employee).as("The employee field should have been autowired.").isNotNull(); - assertThat(this.employee.getName()).isEqualTo("John Smith"); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderDefaultConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderDefaultConfigClassesInheritedTests.java similarity index 80% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderDefaultConfigClassesInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderDefaultConfigClassesInheritedTests.java index 780791bdc4..36ede3e9c4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderDefaultConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderDefaultConfigClassesInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Pet; @@ -36,26 +36,26 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ContextConfiguration -public class DefaultLoaderDefaultConfigClassesInheritedTests extends DefaultLoaderDefaultConfigClassesBaseTests { - - @Configuration - static class Config { - - @Bean - public Pet pet() { - return new Pet("Fido"); - } - } - +class DefaultLoaderDefaultConfigClassesInheritedTests extends DefaultLoaderDefaultConfigClassesBaseTests { @Autowired - private Pet pet; + Pet pet; @Test - public void verifyPetSetFromExtendedContextConfig() { + void verifyPetSetFromExtendedContextConfig() { assertThat(this.pet).as("The pet should have been autowired.").isNotNull(); assertThat(this.pet.getName()).isEqualTo("Fido"); } + + @Configuration(proxyBeanMethods = false) + static class Config { + + @Bean + Pet pet() { + return new Pet("Fido"); + } + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderExplicitConfigClassesBaseTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderExplicitConfigClassesBaseTests.java similarity index 67% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderExplicitConfigClassesBaseTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderExplicitConfigClassesBaseTests.java index aa0d8ab54a..4a88ec8709 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderExplicitConfigClassesBaseTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderExplicitConfigClassesBaseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,15 +14,13 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.DelegatingSmartContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -35,16 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = DefaultLoaderDefaultConfigClassesBaseTests.Config.class) -public class DefaultLoaderExplicitConfigClassesBaseTests { +@SpringJUnitConfig(DefaultLoaderDefaultConfigClassesBaseTests.Config.class) +class DefaultLoaderExplicitConfigClassesBaseTests { @Autowired - protected Employee employee; + Employee employee; @Test - public void verifyEmployeeSetFromBaseContextConfig() { + void verifyEmployeeSetFromBaseContextConfig() { assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); assertThat(this.employee.getName()).isEqualTo("John Smith"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderExplicitConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderExplicitConfigClassesInheritedTests.java similarity index 65% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderExplicitConfigClassesInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderExplicitConfigClassesInheritedTests.java index 3166a6e0b3..dbdcb4b67a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultLoaderExplicitConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/DefaultLoaderExplicitConfigClassesInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,15 +14,13 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Pet; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.DelegatingSmartContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -35,16 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = DefaultLoaderDefaultConfigClassesInheritedTests.Config.class) -public class DefaultLoaderExplicitConfigClassesInheritedTests extends DefaultLoaderExplicitConfigClassesBaseTests { +@SpringJUnitConfig(DefaultLoaderDefaultConfigClassesInheritedTests.Config.class) +class DefaultLoaderExplicitConfigClassesInheritedTests extends DefaultLoaderExplicitConfigClassesBaseTests { @Autowired - private Pet pet; + Pet pet; @Test - public void verifyPetSetFromExtendedContextConfig() { + void verifyPetSetFromExtendedContextConfig() { assertThat(this.pet).as("The pet should have been autowired.").isNotNull(); assertThat(this.pet.getName()).isEqualTo("Fido"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/ExplicitConfigClassesBaseTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/ExplicitConfigClassesBaseTests.java similarity index 67% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/ExplicitConfigClassesBaseTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/ExplicitConfigClassesBaseTests.java index 8660f67e95..6f7b834133 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/ExplicitConfigClassesBaseTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/ExplicitConfigClassesBaseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,15 +14,13 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.AnnotationConfigContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -36,16 +34,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = DefaultConfigClassesBaseTests.ContextConfiguration.class) -public class ExplicitConfigClassesBaseTests { +@SpringJUnitConfig(loader = AnnotationConfigContextLoader.class, classes = DefaultConfigClassesBaseTests.ContextConfiguration.class) +class ExplicitConfigClassesBaseTests { @Autowired - protected Employee employee; + Employee employee; @Test - public void verifyEmployeeSetFromBaseContextConfig() { + void verifyEmployeeSetFromBaseContextConfig() { assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); assertThat(this.employee.getName()).isEqualTo("John Smith"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/ExplicitConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/ExplicitConfigClassesInheritedTests.java similarity index 66% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/ExplicitConfigClassesInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/ExplicitConfigClassesInheritedTests.java index 3e48c6f6c3..fe8725bf72 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/ExplicitConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/ExplicitConfigClassesInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,15 +14,13 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Pet; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.AnnotationConfigContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -37,16 +35,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = DefaultConfigClassesInheritedTests.ContextConfiguration.class) -public class ExplicitConfigClassesInheritedTests extends ExplicitConfigClassesBaseTests { +@SpringJUnitConfig(loader = AnnotationConfigContextLoader.class, classes = DefaultConfigClassesInheritedTests.ContextConfiguration.class) +class ExplicitConfigClassesInheritedTests extends ExplicitConfigClassesBaseTests { @Autowired - private Pet pet; + Pet pet; @Test - public void verifyPetSetFromExtendedContextConfig() { + void verifyPetSetFromExtendedContextConfig() { assertThat(this.pet).as("The pet should have been autowired.").isNotNull(); assertThat(this.pet.getName()).isEqualTo("Fido"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/PojoAndStringConfig.java b/spring-test/src/test/java/org/springframework/test/context/annotation/PojoAndStringConfig.java similarity index 91% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/PojoAndStringConfig.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/PojoAndStringConfig.java index 8de202408e..daa0500317 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/PojoAndStringConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/PojoAndStringConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2025 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.annotation; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.beans.testfixture.beans.Pet; @@ -32,7 +32,7 @@ import org.springframework.context.annotation.Configuration; * @author Sam Brannen * @since 3.1 */ -@Configuration +@Configuration(proxyBeanMethods = false) public class PojoAndStringConfig { @Bean diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java similarity index 97% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java index 3da5148989..cf26e459eb 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests.java similarity index 73% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests.java index d48627f60f..8e81356769 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,13 +14,13 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -31,16 +31,17 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.0.3 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig -public class ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests { +class ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests { @Autowired private String foo; @Test - public void foo() { + void foo() { assertThat(foo).isEqualTo("Resolver Foo"); } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigWithOverridesTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigWithOverridesTests.java similarity index 83% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigWithOverridesTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigWithOverridesTests.java index 70be208501..c80efa75af 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigWithOverridesTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigWithOverridesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,17 +14,17 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.test.context.ActiveProfilesResolver; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -35,18 +35,19 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.0.3 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig(classes = LocalDevConfig.class, resolver = DevResolver.class) -public class ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigWithOverridesTests { +class ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigWithOverridesTests { @Autowired private String foo; @Test - public void foo() { + void foo() { assertThat(foo).isEqualTo("Local Dev Foo"); } + } @Configuration diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesMetaConfig.java similarity index 96% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesMetaConfig.java index e8fc3927cc..4d7ca9959b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesMetaConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesMetaConfigTests.java similarity index 74% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesMetaConfigTests.java index 469870028e..9d4f3df829 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesMetaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesMetaConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,16 +14,16 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -35,37 +35,38 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.0.3 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ConfigClassesAndProfilesMetaConfig(profiles = "dev") -public class ConfigClassesAndProfilesMetaConfigTests { +class ConfigClassesAndProfilesMetaConfigTests { - @Configuration + @Autowired + String foo; + + + @Test + void foo() { + assertThat(foo).isEqualTo("Local Dev Foo"); + } + + + @Configuration(proxyBeanMethods = false) @Profile("dev") static class DevConfig { @Bean - public String foo() { + String foo() { return "Local Dev Foo"; } } - @Configuration + @Configuration(proxyBeanMethods = false) @Profile("prod") static class ProductionConfig { @Bean - public String foo() { + String foo() { return "Local Production Foo"; } } - - @Autowired - private String foo; - - - @Test - public void foo() { - assertThat(foo).isEqualTo("Local Dev Foo"); - } } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java similarity index 96% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java index 44684649b2..615ad407e4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigTests.java similarity index 72% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigTests.java index f6a8bf102b..274c0de05a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,13 +14,13 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -31,16 +31,17 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.0 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ConfigClassesAndProfilesWithCustomDefaultsMetaConfig -public class ConfigClassesAndProfilesWithCustomDefaultsMetaConfigTests { +class ConfigClassesAndProfilesWithCustomDefaultsMetaConfigTests { @Autowired - private String foo; + String foo; @Test - public void foo() { + void foo() { assertThat(foo).isEqualTo("Dev Foo"); } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java similarity index 68% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java index 3da7e5ed85..96810f9bf0 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -14,17 +14,17 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.beans.testfixture.beans.Pet; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.junit4.annotation.PojoAndStringConfig; -import org.springframework.test.context.junit4.annotation.meta.ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.ProductionConfig; +import org.springframework.test.context.annotation.PojoAndStringConfig; +import org.springframework.test.context.annotation.meta.ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.ProductionConfig; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -35,35 +35,35 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.0 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ConfigClassesAndProfilesWithCustomDefaultsMetaConfig( classes = { PojoAndStringConfig.class, ProductionConfig.class }, profiles = "prod") -public class ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests { +class ConfigClassesAndProfilesWithCustomDefaultsMetaConfigWithOverridesTests { @Autowired - private String foo; + String foo; @Autowired - private Pet pet; + Pet pet; @Autowired - protected Employee employee; + Employee employee; @Test - public void verifyEmployee() { + void verifyEmployee() { assertThat(this.employee).as("The employee should have been autowired.").isNotNull(); assertThat(this.employee.getName()).isEqualTo("John Smith"); } @Test - public void verifyPet() { + void verifyPet() { assertThat(this.pet).as("The pet should have been autowired.").isNotNull(); assertThat(this.pet.getName()).isEqualTo("Fido"); } @Test - public void verifyFoo() { + void verifyFoo() { assertThat(this.foo).isEqualTo("Production Foo"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/MetaMetaConfig.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/MetaMetaConfig.java similarity index 95% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/MetaMetaConfig.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/MetaMetaConfig.java index be59c1119f..d762cb262d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/MetaMetaConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/MetaMetaConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/MetaMetaConfigDefaultsTests.java b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/MetaMetaConfigDefaultsTests.java similarity index 73% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/MetaMetaConfigDefaultsTests.java rename to spring-test/src/test/java/org/springframework/test/context/annotation/meta/MetaMetaConfigDefaultsTests.java index 65fe0c5da3..a273b89ac4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/MetaMetaConfigDefaultsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/annotation/meta/MetaMetaConfigDefaultsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,13 +14,13 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation.meta; +package org.springframework.test.context.annotation.meta; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -32,16 +32,17 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.0.3 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @MetaMetaConfig -public class MetaMetaConfigDefaultsTests { +class MetaMetaConfigDefaultsTests { @Autowired - private String foo; + String foo; @Test - public void foo() { + void foo() { assertThat(foo).isEqualTo("Production Foo"); } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java index f0663a50e2..033eb1b027 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -31,6 +31,7 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; 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.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.testng.TrackingTestNGTestListener; @@ -162,12 +163,18 @@ class ClassLevelDirtiesContextTestNGTests { // ------------------------------------------------------------------- - @TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class, - DirtiesContextTestExecutionListener.class }, inheritListeners = false) @ContextConfiguration + // Ensure that we do not include the EventPublishingTestExecutionListener + // since it will access the ApplicationContext for each method in the + // TestExecutionListener API, thus distorting our cache hit/miss results. + @TestExecutionListeners({ + DirtiesContextBeforeModesTestExecutionListener.class, + DependencyInjectionTestExecutionListener.class, + DirtiesContextTestExecutionListener.class + }) abstract static class BaseTestCase extends AbstractTestNGSpringContextTests { - @Configuration + @Configuration(proxyBeanMethods = false) static class Config { /* no beans */ } diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java index a5527be66e..1ed24d6a84 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -21,7 +21,8 @@ import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.testkit.engine.EngineTestKit; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -31,15 +32,14 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener; import org.springframework.test.context.support.DirtiesContextTestExecutionListener; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; import static org.springframework.test.context.cache.ContextCacheTestUtils.assertContextCacheStatistics; import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache; -import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters; /** * JUnit based integration test which verifies correct {@linkplain ContextCache @@ -131,15 +131,24 @@ class ClassLevelDirtiesContextTests { 0, cacheHits.incrementAndGet(), cacheMisses.get()); } - private void runTestClassAndAssertStats(Class testClass, int expectedTestCount) throws Exception { - runTestsAndAssertCounters(testClass, expectedTestCount, 0, expectedTestCount, 0, 0); - } - private void assertBehaviorForCleanTestCase() throws Exception { runTestClassAndAssertStats(CleanTestCase.class, 1); assertContextCacheStatistics("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet()); } + private void runTestClassAndAssertStats(Class testClass, int expectedTestCount) throws Exception { + EngineTestKit.engine("junit-jupiter") + .selectors(selectClass(testClass)) + .execute() + .testEvents() + .assertStatistics(stats -> stats + .started(expectedTestCount) + .finished(expectedTestCount) + .succeeded(expectedTestCount) + .failed(0) + .aborted(0)); + } + @AfterAll static void verifyFinalCacheState() { assertContextCacheStatistics("AfterClass", 0, cacheHits.get(), cacheMisses.get()); @@ -148,7 +157,7 @@ class ClassLevelDirtiesContextTests { // ------------------------------------------------------------------- - @RunWith(SpringRunner.class) + @ExtendWith(SpringExtension.class) @ContextConfiguration // Ensure that we do not include the EventPublishingTestExecutionListener // since it will access the ApplicationContext for each method in the @@ -160,7 +169,7 @@ class ClassLevelDirtiesContextTests { }) abstract static class BaseTestCase { - @Configuration + @Configuration(proxyBeanMethods = false) static class Config { /* no beans */ } @@ -175,75 +184,75 @@ class ClassLevelDirtiesContextTests { } } - public static final class CleanTestCase extends BaseTestCase { + static final class CleanTestCase extends BaseTestCase { - @org.junit.Test - public void verifyContextWasAutowired() { + @Test + void verifyContextWasAutowired() { assertApplicationContextWasAutowired(); } } @DirtiesContext - public static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends BaseTestCase { + static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends BaseTestCase { - @org.junit.Test - public void verifyContextWasAutowired() { + @Test + void verifyContextWasAutowired() { assertApplicationContextWasAutowired(); } } - public static class InheritedClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends + static class InheritedClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase { } @DirtiesContext(classMode = ClassMode.AFTER_CLASS) - public static class ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends BaseTestCase { + static class ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends BaseTestCase { - @org.junit.Test - public void verifyContextWasAutowired() { + @Test + void verifyContextWasAutowired() { assertApplicationContextWasAutowired(); } } - public static class InheritedClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends + static class InheritedClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase { } @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) - public static class ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends BaseTestCase { + static class ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends BaseTestCase { - @org.junit.Test - public void verifyContextWasAutowired1() { + @Test + void verifyContextWasAutowired1() { assertApplicationContextWasAutowired(); } - @org.junit.Test - public void verifyContextWasAutowired2() { + @Test + void verifyContextWasAutowired2() { assertApplicationContextWasAutowired(); } - @org.junit.Test - public void verifyContextWasAutowired3() { + @Test + void verifyContextWasAutowired3() { assertApplicationContextWasAutowired(); } } - public static class InheritedClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends + static class InheritedClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase { } @DirtiesContext - public static class ClassLevelDirtiesContextWithDirtyMethodsTestCase extends BaseTestCase { + static class ClassLevelDirtiesContextWithDirtyMethodsTestCase extends BaseTestCase { - @org.junit.Test + @Test @DirtiesContext - public void dirtyContext() { + void dirtyContext() { assertApplicationContextWasAutowired(); } } - public static class InheritedClassLevelDirtiesContextWithDirtyMethodsTestCase extends + static class InheritedClassLevelDirtiesContextWithDirtyMethodsTestCase extends ClassLevelDirtiesContextWithDirtyMethodsTestCase { } diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java index 72dbddc0ea..323d7eb6d3 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.annotation.DirtiesContext.MethodMode.BEFORE_METHOD; /** - * Integration test which verifies correct interaction between the + * Integration tests which verify correct interaction between the * {@link DirtiesContextBeforeModesTestExecutionListener}, * {@link DependencyInjectionTestExecutionListener}, and * {@link DirtiesContextTestExecutionListener} when diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionContextCacheTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionContextCacheTests.java index 1e67f03145..f32aea8948 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionContextCacheTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionContextCacheTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -37,10 +37,9 @@ import static org.springframework.test.context.cache.ContextCacheTestUtils.asser import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache; /** - * Unit tests which verify correct {@link ContextCache - * application context caching} in conjunction with the - * {@link SpringExtension} and the {@link DirtiesContext - * @DirtiesContext} annotation at the method level. + * JUnit based integration test which verifies correct {@linkplain ContextCache + * application context caching} in conjunction with the {@link SpringExtension} and + * {@link DirtiesContext @DirtiesContext} at the method level. * * @author Sam Brannen * @author Juergen Hoeller diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java index 92d1331bd6..4a2cbfa492 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2025 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. @@ -21,21 +21,22 @@ import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.testkit.engine.EngineTestKit; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener; import org.springframework.test.context.support.DirtiesContextTestExecutionListener; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; import static org.springframework.test.context.cache.ContextCacheTestUtils.assertContextCacheStatistics; import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache; -import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters; /** * @author Sam Brannen @@ -70,11 +71,14 @@ class DirtiesContextInterfaceTests { } private void runTestClassAndAssertStats(Class testClass, int expectedTestCount) throws Exception { - runTestsAndAssertCounters(testClass, expectedTestCount, 0, expectedTestCount, 0, 0); + EngineTestKit.engine("junit-jupiter") + .selectors(selectClass(testClass)) + .execute() + .testEvents() + .assertStatistics(stats -> stats.started(expectedTestCount).succeeded(expectedTestCount).failed(0)); } - - @RunWith(SpringRunner.class) + @ExtendWith(SpringExtension.class) // Ensure that we do not include the EventPublishingTestExecutionListener // since it will access the ApplicationContext for each method in the // TestExecutionListener API, thus distorting our cache hit/miss results. @@ -90,13 +94,13 @@ class DirtiesContextInterfaceTests { ApplicationContext applicationContext; - @org.junit.Test + @Test public void verifyContextWasAutowired() { assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull(); } - @Configuration + @Configuration(proxyBeanMethods = false) static class Config { /* no beans */ } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/hybrid/HybridContextLoader.java b/spring-test/src/test/java/org/springframework/test/context/hybrid/HybridContextLoader.java similarity index 98% rename from spring-test/src/test/java/org/springframework/test/context/junit4/hybrid/HybridContextLoader.java rename to spring-test/src/test/java/org/springframework/test/context/hybrid/HybridContextLoader.java index 9f8c06534c..9b2375fcdf 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/hybrid/HybridContextLoader.java +++ b/spring-test/src/test/java/org/springframework/test/context/hybrid/HybridContextLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.hybrid; +package org.springframework.test.context.hybrid; import org.springframework.beans.factory.support.BeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/hybrid/HybridContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/hybrid/HybridContextLoaderTests.java similarity index 76% rename from spring-test/src/test/java/org/springframework/test/context/junit4/hybrid/HybridContextLoaderTests.java rename to spring-test/src/test/java/org/springframework/test/context/hybrid/HybridContextLoaderTests.java index 1ef7a18c09..07b630c910 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/hybrid/HybridContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hybrid/HybridContextLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -14,17 +14,17 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.hybrid; +package org.springframework.test.context.hybrid; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.SmartContextLoader; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -37,37 +37,22 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.0.4 * @see HybridContextLoader */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = HybridContextLoader.class) -public class HybridContextLoaderTests { - - @Configuration - static class Config { - - @Bean - public String fooFromJava() { - return "Java"; - } - - @Bean - public String enigma() { - return "enigma from Java"; - } - } - +class HybridContextLoaderTests { @Autowired - private String fooFromXml; + String fooFromXml; @Autowired - private String fooFromJava; + String fooFromJava; @Autowired - private String enigma; + String enigma; @Test - public void verifyContentsOfHybridApplicationContext() { + void verifyContentsOfHybridApplicationContext() { assertThat(fooFromXml).isEqualTo("XML"); assertThat(fooFromJava).isEqualTo("Java"); @@ -78,4 +63,19 @@ public class HybridContextLoaderTests { assertThat(enigma).isEqualTo("enigma from XML"); } + + @Configuration(proxyBeanMethods = false) + static class Config { + + @Bean + String fooFromJava() { + return "Java"; + } + + @Bean + String enigma() { + return "enigma from Java"; + } + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr3896/BeanOverridingDefaultLocationsInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/inheritance/BeanOverridingDefaultLocationsInheritedTests.java similarity index 78% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr3896/BeanOverridingDefaultLocationsInheritedTests.java rename to spring-test/src/test/java/org/springframework/test/context/inheritance/BeanOverridingDefaultLocationsInheritedTests.java index f33a0c4fcb..0b72dea199 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr3896/BeanOverridingDefaultLocationsInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/inheritance/BeanOverridingDefaultLocationsInheritedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,16 +14,16 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr3896; +package org.springframework.test.context.inheritance; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; /** - * JUnit 4 based integration test for verifying support for the + * JUnit based integration test for verifying support for the * {@link ContextConfiguration#inheritLocations() inheritLocations} flag of * {@link ContextConfiguration @ContextConfiguration} indirectly proposed in This suite is only intended to be used manually within an IDE. + * + *

Logging Configuration

+ * + *

In order for our log4j2 configuration to be used in an IDE, you must + * set the following system property before running any tests — for + * example, in Run Configurations in Eclipse. + * + *

+ * -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
+ * 
+ * + * @author Sam Brannen + * @since 3.2 + */ +@Suite +@IncludeEngines("junit-jupiter") +@SelectPackages({ + "org.springframework.test.context.initializers.annotation", + "org.springframework.test.context.initializers.xml" +}) +@IncludeClassNamePatterns(".*Tests$") +@ExcludeTags("failing-test-case") +@ConfigurationParameter( + key = ClassOrderer.DEFAULT_ORDER_PROPERTY_NAME, + value = "org.junit.jupiter.api.ClassOrderer$ClassName" +) +public class AciTestSuite { +} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/aci/DevProfileInitializer.java b/spring-test/src/test/java/org/springframework/test/context/initializers/DevProfileInitializer.java similarity index 90% rename from spring-test/src/test/java/org/springframework/test/context/junit4/aci/DevProfileInitializer.java rename to spring-test/src/test/java/org/springframework/test/context/initializers/DevProfileInitializer.java index 16a4ce4ec5..04f866aee3 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/aci/DevProfileInitializer.java +++ b/spring-test/src/test/java/org/springframework/test/context/initializers/DevProfileInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2025 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.aci; +package org.springframework.test.context.initializers; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; @@ -29,4 +29,5 @@ public class DevProfileInitializer implements ApplicationContextInitializergh-13491
. + * + *

Work Around

+ *

By using a SpEL expression to generate a random {@code database-name} + * for the embedded database (see {@code datasource-config.xml}), we ensure + * that each {@code ApplicationContext} that imports the common configuration + * will create an embedded database with a unique name. + * + *

To reproduce the problem mentioned in gh-13491, delete the declaration + * of the {@code database-name} attribute of the embedded database in + * {@code datasource-config.xml} and run this suite. + * + *

Solution

+ *

As of Spring 4.2, a proper solution is possible thanks to gh-13491. + * {@link TestClass2A} and {@link TestClass2B} both import + * {@code datasource-config-with-auto-generated-db-name.xml} which makes + * use of the new {@code generate-name} attribute of {@code }. + * + * @author Sam Brannen + * @author Mickael Leduque + */ +class GeneratedDatabaseNamesTests { + + private static final String DATASOURCE_CONFIG_XML = + "classpath:/org/springframework/test/context/jdbc/datasource-config.xml"; + + private static final String DATASOURCE_CONFIG_WITH_AUTO_GENERATED_DB_NAME_XML = + "classpath:/org/springframework/test/context/jdbc/datasource-config-with-auto-generated-db-name.xml"; + + + @Test + void runTestsWithGeneratedDatabaseNames() { + EngineTestKit.engine("junit-jupiter") + .selectors( + selectClass(TestClass1A.class), + selectClass(TestClass1B.class), + selectClass(TestClass2A.class), + selectClass(TestClass2B.class) + ) + .execute() + .testEvents() + .assertStatistics(stats -> stats.started(4).succeeded(4).failed(0)); + } + + + @ExtendWith(SpringExtension.class) + abstract static class AbstractTestCase { + + @Resource + DataSource dataSource; + + @Test + void test() { + assertThat(dataSource).isNotNull(); + } + } + + @ContextConfiguration + static class TestClass1A extends AbstractTestCase { + + @Configuration + @ImportResource(DATASOURCE_CONFIG_XML) + static class Config { + } + } + + @ContextConfiguration + static class TestClass1B extends AbstractTestCase { + + @Configuration + @ImportResource(DATASOURCE_CONFIG_XML) + static class Config { + } + } + + /** + * @since 4.2 + */ + @ContextConfiguration + static class TestClass2A extends AbstractTestCase { + + @Configuration + @ImportResource(DATASOURCE_CONFIG_WITH_AUTO_GENERATED_DB_NAME_XML) + static class Config { + } + } + + /** + * @since 4.2 + */ + @ContextConfiguration + static class TestClass2B extends AbstractTestCase { + + @Configuration + @ImportResource(DATASOURCE_CONFIG_WITH_AUTO_GENERATED_DB_NAME_XML) + static class Config { + } + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/Jsr250LifecycleTests.java b/spring-test/src/test/java/org/springframework/test/context/jsr250/Jsr250LifecycleTests.java similarity index 80% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/Jsr250LifecycleTests.java rename to spring-test/src/test/java/org/springframework/test/context/jsr250/Jsr250LifecycleTests.java index cc2c82c966..28540848e4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/Jsr250LifecycleTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jsr250/Jsr250LifecycleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -14,23 +14,21 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr4868; +package org.springframework.test.context.jsr250; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import static org.assertj.core.api.Assertions.assertThat; @@ -61,58 +59,56 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @TestExecutionListeners(DependencyInjectionTestExecutionListener.class) -@ContextConfiguration -public class Jsr250LifecycleTests { +class Jsr250LifecycleTests { private final Log logger = LogFactory.getLog(Jsr250LifecycleTests.class); - - @Configuration - static class Config { - - @Bean - public LifecycleBean lifecycleBean() { - return new LifecycleBean(); - } - } - - @Autowired - private LifecycleBean lifecycleBean; + LifecycleBean lifecycleBean; @PostConstruct - public void beforeAllTests() { + void beforeAllTests() { logger.info("beforeAllTests()"); } @PreDestroy - public void afterTestSuite() { + void afterTestSuite() { logger.info("afterTestSuite()"); } - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { logger.info("setUp()"); } - @After - public void tearDown() { + @AfterEach + void tearDown() { logger.info("tearDown()"); } @Test - public void test1() { + void test1() { logger.info("test1()"); assertThat(lifecycleBean).isNotNull(); } @Test - public void test2() { + void test2() { logger.info("test2()"); assertThat(lifecycleBean).isNotNull(); } + + @Configuration(proxyBeanMethods = false) + static class Config { + + @Bean + LifecycleBean lifecycleBean() { + return new LifecycleBean(); + } + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/LifecycleBean.java b/spring-test/src/test/java/org/springframework/test/context/jsr250/LifecycleBean.java similarity index 94% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/LifecycleBean.java rename to spring-test/src/test/java/org/springframework/test/context/jsr250/LifecycleBean.java index fe452ee03f..e40a7a8c72 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/LifecycleBean.java +++ b/spring-test/src/test/java/org/springframework/test/context/jsr250/LifecycleBean.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr4868; +package org.springframework.test.context.jsr250; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.java similarity index 79% rename from spring-test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.java rename to spring-test/src/test/java/org/springframework/test/context/junit4/AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.java index cc368b2862..d87ca44a61 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2025 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. @@ -14,19 +14,19 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.annotation; +package org.springframework.test.context.junit4; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunnerAppCtxTests; +import org.springframework.test.context.annotation.PojoAndStringConfig; /** * Integration tests that verify support for configuration classes in * the Spring TestContext Framework. * - *

Furthermore, by extending {@link SpringJUnit4ClassRunnerAppCtxTests}, + *

Furthermore, by extending {@code SpringJUnit4ClassRunnerAppCtxTests}, * this class also verifies support for several basic features of the * Spring TestContext Framework. See JavaDoc in - * {@code SpringJUnit4ClassRunnerAppCtxTests} for details. + * {@link SpringJUnit4ClassRunnerAppCtxTests} for details. * *

Configuration will be loaded from {@link PojoAndStringConfig}. * diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java b/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java index 5302d1c0fb..e3bb2feef8 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -20,27 +20,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.springframework.test.context.junit4.annotation.AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests; -import org.springframework.test.context.junit4.annotation.BeanOverridingDefaultConfigClassesInheritedTests; -import org.springframework.test.context.junit4.annotation.BeanOverridingExplicitConfigClassesInheritedTests; -import org.springframework.test.context.junit4.annotation.DefaultConfigClassesBaseTests; -import org.springframework.test.context.junit4.annotation.DefaultConfigClassesInheritedTests; -import org.springframework.test.context.junit4.annotation.DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests; -import org.springframework.test.context.junit4.annotation.DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests; -import org.springframework.test.context.junit4.annotation.DefaultLoaderDefaultConfigClassesBaseTests; -import org.springframework.test.context.junit4.annotation.DefaultLoaderDefaultConfigClassesInheritedTests; -import org.springframework.test.context.junit4.annotation.DefaultLoaderExplicitConfigClassesBaseTests; -import org.springframework.test.context.junit4.annotation.DefaultLoaderExplicitConfigClassesInheritedTests; -import org.springframework.test.context.junit4.annotation.ExplicitConfigClassesBaseTests; -import org.springframework.test.context.junit4.annotation.ExplicitConfigClassesInheritedTests; -import org.springframework.test.context.junit4.orm.HibernateSessionFlushingTests; -import org.springframework.test.context.junit4.profile.annotation.DefaultProfileAnnotationConfigTests; -import org.springframework.test.context.junit4.profile.annotation.DevProfileAnnotationConfigTests; -import org.springframework.test.context.junit4.profile.annotation.DevProfileResolverAnnotationConfigTests; -import org.springframework.test.context.junit4.profile.xml.DefaultProfileXmlConfigTests; -import org.springframework.test.context.junit4.profile.xml.DevProfileResolverXmlConfigTests; -import org.springframework.test.context.junit4.profile.xml.DevProfileXmlConfigTests; - /** * JUnit test suite for tests involving {@link SpringRunner} and the * Spring TestContext Framework; only intended to be run manually as a @@ -64,24 +43,6 @@ StandardJUnit4FeaturesTests.class,// StandardJUnit4FeaturesSpringRunnerTests.class,// SpringJUnit47ClassRunnerRuleTests.class,// AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.class,// - DefaultConfigClassesBaseTests.class,// - DefaultConfigClassesInheritedTests.class,// - BeanOverridingDefaultConfigClassesInheritedTests.class,// - ExplicitConfigClassesBaseTests.class,// - ExplicitConfigClassesInheritedTests.class,// - BeanOverridingExplicitConfigClassesInheritedTests.class,// - DefaultLoaderDefaultConfigClassesBaseTests.class,// - DefaultLoaderDefaultConfigClassesInheritedTests.class,// - DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.class,// - DefaultLoaderExplicitConfigClassesBaseTests.class,// - DefaultLoaderExplicitConfigClassesInheritedTests.class,// - DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests.class,// - DefaultProfileAnnotationConfigTests.class,// - DevProfileAnnotationConfigTests.class,// - DevProfileResolverAnnotationConfigTests.class,// - DefaultProfileXmlConfigTests.class,// - DevProfileXmlConfigTests.class,// - DevProfileResolverXmlConfigTests.class,// ExpectedExceptionSpringRunnerTests.class,// TimedSpringRunnerTests.class,// RepeatedSpringRunnerTests.class,// @@ -102,8 +63,7 @@ StandardJUnit4FeaturesTests.class,// RollbackOverrideDefaultRollbackTrueTransactionalTests.class,// RollbackOverrideDefaultRollbackFalseTransactionalTests.class,// BeforeAndAfterTransactionAnnotationTests.class,// - TimedTransactionalSpringRunnerTests.class,// - HibernateSessionFlushingTests.class // + TimedTransactionalSpringRunnerTests.class// }) public class SpringJUnit4TestSuite { /* this test case consists entirely of tests loaded as a suite. */ diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/aci/AciTestSuite.java b/spring-test/src/test/java/org/springframework/test/context/junit4/aci/AciTestSuite.java deleted file mode 100644 index 30d70eefd4..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/aci/AciTestSuite.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2002-2012 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.junit4.aci; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.test.context.junit4.aci.annotation.InitializerWithoutConfigFilesOrClassesTests; -import org.springframework.test.context.junit4.aci.annotation.MergedInitializersAnnotationConfigTests; -import org.springframework.test.context.junit4.aci.annotation.MultipleInitializersAnnotationConfigTests; -import org.springframework.test.context.junit4.aci.annotation.OrderedInitializersAnnotationConfigTests; -import org.springframework.test.context.junit4.aci.annotation.OverriddenInitializersAnnotationConfigTests; -import org.springframework.test.context.junit4.aci.annotation.SingleInitializerAnnotationConfigTests; -import org.springframework.test.context.junit4.aci.xml.MultipleInitializersXmlConfigTests; - -/** - * Convenience test suite for integration tests that verify support for - * {@link ApplicationContextInitializer ApplicationContextInitializers} (ACIs) - * in the TestContext framework. - * - * @author Sam Brannen - * @since 3.2 - */ -@RunWith(Suite.class) -// Note: the following 'multi-line' layout is for enhanced code readability. -@SuiteClasses({// - MultipleInitializersXmlConfigTests.class,// - SingleInitializerAnnotationConfigTests.class,// - MultipleInitializersAnnotationConfigTests.class,// - MergedInitializersAnnotationConfigTests.class,// - OverriddenInitializersAnnotationConfigTests.class,// - OrderedInitializersAnnotationConfigTests.class,// - InitializerWithoutConfigFilesOrClassesTests.class // -}) -public class AciTestSuite { -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigTestSuite.java b/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigTestSuite.java deleted file mode 100644 index f5f16ea993..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/annotation/AnnotationConfigTestSuite.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2002-2011 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.junit4.annotation; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * JUnit test suite for annotation-driven configuration class - * support in the Spring TestContext Framework. - * - * @author Sam Brannen - * @since 3.1 - */ -@RunWith(Suite.class) -// Note: the following 'multi-line' layout is for enhanced code readability. -@SuiteClasses({// -AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests.class,// - DefaultConfigClassesBaseTests.class,// - DefaultConfigClassesInheritedTests.class,// - BeanOverridingDefaultConfigClassesInheritedTests.class,// - ExplicitConfigClassesBaseTests.class,// - ExplicitConfigClassesInheritedTests.class,// - BeanOverridingExplicitConfigClassesInheritedTests.class,// - DefaultLoaderDefaultConfigClassesBaseTests.class,// - DefaultLoaderDefaultConfigClassesInheritedTests.class,// - DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.class,// - DefaultLoaderExplicitConfigClassesBaseTests.class,// - DefaultLoaderExplicitConfigClassesInheritedTests.class,// - DefaultLoaderBeanOverridingExplicitConfigClassesInheritedTests.class // -}) -public class AnnotationConfigTestSuite { -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java index ee61b3ebef..a3e77dc2df 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -79,7 +79,6 @@ public class SpringJUnit4ConcurrencyTests { TimedTransactionalSpringRunnerTests.class, // Web and Scopes BasicAnnotationConfigWacSpringRuleTests.class, - // Spring MVC Test }; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/ProfileAnnotationConfigTestSuite.java b/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/ProfileAnnotationConfigTestSuite.java deleted file mode 100644 index 26d29dfa26..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/ProfileAnnotationConfigTestSuite.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2013 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.junit4.profile.annotation; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * JUnit test suite for bean definition profile support in the - * Spring TestContext Framework with annotation-based configuration. - * - * @author Sam Brannen - * @since 3.1 - */ -@RunWith(Suite.class) -// Note: the following 'multi-line' layout is for enhanced code readability. -@SuiteClasses({// -DefaultProfileAnnotationConfigTests.class,// - DevProfileAnnotationConfigTests.class,// - DevProfileResolverAnnotationConfigTests.class // -}) -public class ProfileAnnotationConfigTestSuite { -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/resolver/ClassNameActiveProfilesResolverTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/profile/resolver/ClassNameActiveProfilesResolverTests.java deleted file mode 100644 index 6c71af3fbd..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/resolver/ClassNameActiveProfilesResolverTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2002-2019 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.junit4.profile.resolver; - -import java.util.Arrays; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Michail Nikolaev - * @since 4.0 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@ActiveProfiles(resolver = ClassNameActiveProfilesResolver.class) -public class ClassNameActiveProfilesResolverTests { - - @Configuration - static class Config { - - } - - - @Autowired - private ApplicationContext applicationContext; - - - @Test - public void test() { - assertThat(Arrays.asList(applicationContext.getEnvironment().getActiveProfiles()).contains( - getClass().getSimpleName().toLowerCase())).isTrue(); - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/ProfileXmlConfigTestSuite.java b/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/ProfileXmlConfigTestSuite.java deleted file mode 100644 index 741327d7e1..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/ProfileXmlConfigTestSuite.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2013 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.junit4.profile.xml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * JUnit test suite for bean definition profile support in the - * Spring TestContext Framework with XML-based configuration. - * - * @author Sam Brannen - * @since 3.1 - */ -@RunWith(Suite.class) -// Note: the following 'multi-line' layout is for enhanced code readability. -@SuiteClasses({// -DefaultProfileXmlConfigTests.class,// - DevProfileXmlConfigTests.class,// - DevProfileResolverXmlConfigTests.class // -}) -public class ProfileXmlConfigTestSuite { -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/BasicAnnotationConfigWacSpringRuleTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/BasicAnnotationConfigWacSpringRuleTests.java index 8c2f26f8fd..326e5f5621 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/BasicAnnotationConfigWacSpringRuleTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/BasicAnnotationConfigWacSpringRuleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2025 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. @@ -18,23 +18,30 @@ package org.springframework.test.context.junit4.rules; import org.junit.ClassRule; import org.junit.Rule; +import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.springframework.test.context.web.BasicAnnotationConfigWacTests; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.web.AbstractBasicWacTests; +import org.springframework.test.context.web.ServletContextAwareBean; + +import static org.assertj.core.api.Assertions.assertThat; /** - * This class is an extension of {@link BasicAnnotationConfigWacTests} - * that has been modified to use {@link SpringClassRule} and - * {@link SpringMethodRule}. + * This class is a copy of {@link org.springframework.test.context.web.BasicAnnotationConfigWacTests} + * that has been modified to use the {@link JUnit4} runner combined with + * {@link SpringClassRule} and {@link SpringMethodRule}. * * @author Sam Brannen * @since 4.2 */ @RunWith(JUnit4.class) -public class BasicAnnotationConfigWacSpringRuleTests extends BasicAnnotationConfigWacTests { - - // All tests are in superclass. +@ContextConfiguration +public class BasicAnnotationConfigWacSpringRuleTests extends AbstractBasicWacTests { @ClassRule public static final SpringClassRule springClassRule = new SpringClassRule(); @@ -42,4 +49,46 @@ public class BasicAnnotationConfigWacSpringRuleTests extends BasicAnnotationConf @Rule public final SpringMethodRule springMethodRule = new SpringMethodRule(); + + @Autowired + ServletContextAwareBean servletContextAwareBean; + + + /** + * Have to override this method to annotate it with JUnit 4's {@code @Test} + * annotation. + */ + @Test + @Override + public void basicWacFeatures() throws Exception { + super.basicWacFeatures(); + } + + @Test + public void fooEnigmaAutowired() { + assertThat(foo).isEqualTo("enigma"); + } + + @Test + public void servletContextAwareBeanProcessed() { + assertThat(servletContextAwareBean).isNotNull(); + assertThat(servletContextAwareBean.getServletContext()).isNotNull(); + } + + + @Configuration(proxyBeanMethods = false) + static class Config { + + @Bean + String foo() { + return "enigma"; + } + + @Bean + ServletContextAwareBean servletContextAwareBean() { + return new ServletContextAwareBean(); + } + + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/integration/MockitoBeanAndSpringMethodRuleWithRepeatJUnit4IntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/MockitoBeanAndSpringMethodRuleWithRepeatJUnit4IntegrationTests.java similarity index 92% rename from spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/integration/MockitoBeanAndSpringMethodRuleWithRepeatJUnit4IntegrationTests.java rename to spring-test/src/test/java/org/springframework/test/context/junit4/rules/MockitoBeanAndSpringMethodRuleWithRepeatJUnit4IntegrationTests.java index 588e7ac010..15211ba521 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/integration/MockitoBeanAndSpringMethodRuleWithRepeatJUnit4IntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/MockitoBeanAndSpringMethodRuleWithRepeatJUnit4IntegrationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.bean.override.mockito.integration; +package org.springframework.test.context.junit4.rules; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -23,7 +23,6 @@ import org.junit.Test; import org.springframework.test.annotation.Repeat; import org.springframework.test.context.bean.override.mockito.MockitoBean; -import org.springframework.test.context.junit4.rules.SpringMethodRule; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr3896/Spr3896TestSuite.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr3896/Spr3896TestSuite.java deleted file mode 100644 index 994251e8d7..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr3896/Spr3896TestSuite.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2002-2019 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.junit4.spr3896; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * JUnit 4 based test suite for functionality proposed in SPR-3896. - * - * @author Sam Brannen - * @since 2.5 - */ -@RunWith(Suite.class) -// Note: the following 'multi-line' layout is for enhanced code readability. -@SuiteClasses({ - -DefaultLocationsBaseTests.class, - -DefaultLocationsInheritedTests.class, - -ExplicitLocationsBaseTests.class, - -ExplicitLocationsInheritedTests.class, - -BeanOverridingDefaultLocationsInheritedTests.class, - -BeanOverridingExplicitLocationsInheritedTests.class - -}) -public class Spr3896TestSuite { -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/Spr8849Tests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/Spr8849Tests.java deleted file mode 100644 index 707c726535..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/Spr8849Tests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.junit4.spr8849; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * Test suite to investigate claims raised in - * SPR-8849. - * - *

Work Around

- *

By using a SpEL expression to generate a random {@code database-name} - * for the embedded database (see {@code datasource-config.xml}), we ensure - * that each {@code ApplicationContext} that imports the common configuration - * will create an embedded database with a unique name. - * - *

To reproduce the problem mentioned in SPR-8849, delete the declaration - * of the {@code database-name} attribute of the embedded database in - * {@code datasource-config.xml} and run this suite. - * - *

Solution

- *

As of Spring 4.2, a proper solution is possible thanks to SPR-8849. - * {@link TestClass3} and {@link TestClass4} both import - * {@code datasource-config-with-auto-generated-db-name.xml} which makes - * use of the new {@code generate-name} attribute of {@code }. - * - * @author Sam Brannen - * @since 3.2 - */ -@RunWith(Suite.class) -@SuiteClasses({ TestClass1.class, TestClass2.class, TestClass3.class, TestClass4.class }) -public class Spr8849Tests { - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1.java deleted file mode 100644 index 9567ddd3b8..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2002-2019 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.junit4.spr8849; - -import javax.sql.DataSource; - -import jakarta.annotation.Resource; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This name of this class intentionally does not end with "Test" or "Tests" - * since it should only be run as part of the test suite: {@link Spr8849Tests}. - * - * @author Mickael Leduque - * @author Sam Brannen - * @since 3.2 - * @see Spr8849Tests - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class TestClass1 { - - @Configuration - @ImportResource("classpath:/org/springframework/test/context/junit4/spr8849/datasource-config.xml") - static class Config { - } - - - @Resource - DataSource dataSource; - - - @Test - public void dummyTest() { - assertThat(dataSource).isNotNull(); - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2.java deleted file mode 100644 index 0cca425504..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2002-2019 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.junit4.spr8849; - -import javax.sql.DataSource; - -import jakarta.annotation.Resource; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This name of this class intentionally does not end with "Test" or "Tests" - * since it should only be run as part of the test suite: {@link Spr8849Tests}. - * - * @author Mickael Leduque - * @author Sam Brannen - * @since 3.2 - * @see Spr8849Tests - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class TestClass2 { - - @Configuration - @ImportResource("classpath:/org/springframework/test/context/junit4/spr8849/datasource-config.xml") - static class Config { - } - - - @Resource - DataSource dataSource; - - - @Test - public void dummyTest() { - assertThat(dataSource).isNotNull(); - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass3.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass3.java deleted file mode 100644 index 1d978e8524..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass3.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2002-2019 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.junit4.spr8849; - -import javax.sql.DataSource; - -import jakarta.annotation.Resource; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This name of this class intentionally does not end with "Test" or "Tests" - * since it should only be run as part of the test suite: {@link Spr8849Tests}. - * - * @author Sam Brannen - * @since 4.2 - * @see Spr8849Tests - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class TestClass3 { - - @Configuration - @ImportResource("classpath:/org/springframework/test/context/junit4/spr8849/datasource-config-with-auto-generated-db-name.xml") - static class Config { - } - - - @Resource - DataSource dataSource; - - - @Test - public void dummyTest() { - assertThat(dataSource).isNotNull(); - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass4.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass4.java deleted file mode 100644 index 7a6a189549..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass4.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2002-2019 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.junit4.spr8849; - -import javax.sql.DataSource; - -import jakarta.annotation.Resource; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This name of this class intentionally does not end with "Test" or "Tests" - * since it should only be run as part of the test suite: {@link Spr8849Tests}. - * - * @author Sam Brannen - * @since 4.2 - * @see Spr8849Tests - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class TestClass4 { - - @Configuration - @ImportResource("classpath:/org/springframework/test/context/junit4/spr8849/datasource-config-with-auto-generated-db-name.xml") - static class Config { - } - - - @Resource - DataSource dataSource; - - - @Test - public void dummyTest() { - assertThat(dataSource).isNotNull(); - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/web/JUnit4SpringContextWebTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/web/JUnit4SpringContextWebTests.java similarity index 95% rename from spring-test/src/test/java/org/springframework/test/context/web/JUnit4SpringContextWebTests.java rename to spring-test/src/test/java/org/springframework/test/context/junit4/web/JUnit4SpringContextWebTests.java index b512ceefdf..170d7e39b4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/JUnit4SpringContextWebTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/web/JUnit4SpringContextWebTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.web; +package org.springframework.test.context.junit4.web; import java.io.File; @@ -30,6 +30,7 @@ import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockServletContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.request.ServletWebRequest; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AbstractTransactionalAnnotatedConfigClassTests.java b/spring-test/src/test/java/org/springframework/test/context/litemode/AbstractTransactionalAnnotatedConfigClassTests.java similarity index 81% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AbstractTransactionalAnnotatedConfigClassTests.java rename to spring-test/src/test/java/org/springframework/test/context/litemode/AbstractTransactionalAnnotatedConfigClassTests.java index 6489efd4a0..0a3b37ca62 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AbstractTransactionalAnnotatedConfigClassTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/litemode/AbstractTransactionalAnnotatedConfigClassTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -14,14 +14,13 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr9051; +package org.springframework.test.context.litemode; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; @@ -29,7 +28,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.transaction.annotation.Transactional; @@ -40,16 +39,16 @@ import static org.springframework.transaction.support.TransactionSynchronization /** * This set of tests (i.e., all concrete subclasses) investigates the claims made in - * SPR-9051 + * gh-13690. * with regard to transactional tests. * * @author Sam Brannen * @since 3.2 * @see org.springframework.test.context.testng.AnnotationConfigTransactionalTestNGSpringContextTests */ -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) -public abstract class AbstractTransactionalAnnotatedConfigClassTests { +abstract class AbstractTransactionalAnnotatedConfigClassTests { protected static final String JANE = "jane"; protected static final String SUE = "sue"; @@ -65,12 +64,12 @@ public abstract class AbstractTransactionalAnnotatedConfigClassTests { @Autowired - public void setTransactionManager(DataSourceTransactionManager transactionManager) { + void setTransactionManager(DataSourceTransactionManager transactionManager) { this.dataSourceFromTxManager = transactionManager.getDataSource(); } @Autowired - public void setDataSource(DataSource dataSource) { + void setDataSource(DataSource dataSource) { this.dataSourceViaInjection = dataSource; this.jdbcTemplate = new JdbcTemplate(dataSource); } @@ -96,38 +95,38 @@ public abstract class AbstractTransactionalAnnotatedConfigClassTests { } @Test - public void autowiringFromConfigClass() { + void autowiringFromConfigClass() { assertThat(employee).as("The employee should have been autowired.").isNotNull(); assertThat(employee.getName()).isEqualTo("John Smith"); } @BeforeTransaction - public void beforeTransaction() { + void beforeTransaction() { assertNumRowsInPersonTable(0, "before a transactional test method"); assertAddPerson(YODA); } - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { assertNumRowsInPersonTable((isActualTransactionActive() ? 1 : 0), "before a test method"); } @Test @Transactional - public void modifyTestDataWithinTransaction() { + void modifyTestDataWithinTransaction() { assertThatTransaction().isActive(); assertAddPerson(JANE); assertAddPerson(SUE); assertNumRowsInPersonTable(3, "in modifyTestDataWithinTransaction()"); } - @After - public void tearDown() { + @AfterEach + void tearDown() { assertNumRowsInPersonTable((isActualTransactionActive() ? 3 : 0), "after a test method"); } @AfterTransaction - public void afterTransaction() { + void afterTransaction() { assertThat(deletePerson(YODA)).as("Deleting yoda").isEqualTo(1); assertNumRowsInPersonTable(0, "after a transactional test method"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AnnotatedConfigClassesWithoutAtConfigurationTests.java b/spring-test/src/test/java/org/springframework/test/context/litemode/AnnotatedConfigClassesWithoutAtConfigurationTests.java similarity index 78% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AnnotatedConfigClassesWithoutAtConfigurationTests.java rename to spring-test/src/test/java/org/springframework/test/context/litemode/AnnotatedConfigClassesWithoutAtConfigurationTests.java index 523c6c06ea..39c510af42 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AnnotatedConfigClassesWithoutAtConfigurationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/litemode/AnnotatedConfigClassesWithoutAtConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -14,24 +14,22 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr9051; +package org.springframework.test.context.litemode; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * This set of tests refutes the claims made in - * SPR-9051. + * gh-13690. * *

The Claims: * @@ -48,9 +46,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Phillip Webb * @since 3.2 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = AnnotatedConfigClassesWithoutAtConfigurationTests.AnnotatedFactoryBeans.class) -public class AnnotatedConfigClassesWithoutAtConfigurationTests { +@SpringJUnitConfig(AnnotatedConfigClassesWithoutAtConfigurationTests.AnnotatedFactoryBeans.class) +class AnnotatedConfigClassesWithoutAtConfigurationTests { /** * This is intentionally not annotated with {@code @Configuration}. @@ -63,12 +60,12 @@ public class AnnotatedConfigClassesWithoutAtConfigurationTests { @Bean - public String enigma() { + String enigma() { return "enigma #" + enigmaCallCount.incrementAndGet(); } @Bean - public LifecycleBean lifecycleBean() { + LifecycleBean lifecycleBean() { // The following call to enigma() literally invokes the local // enigma() method, not a CGLIB proxied version, since these methods // are essentially factory bean methods. @@ -87,7 +84,7 @@ public class AnnotatedConfigClassesWithoutAtConfigurationTests { @Test - public void testSPR_9051() { + void testSPR_9051() { assertThat(enigma).isNotNull(); assertThat(lifecycleBean).isNotNull(); assertThat(lifecycleBean.isInitialized()).isTrue(); diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AtBeanLiteModeScopeTests.java b/spring-test/src/test/java/org/springframework/test/context/litemode/AtBeanLiteModeScopeTests.java similarity index 76% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AtBeanLiteModeScopeTests.java rename to spring-test/src/test/java/org/springframework/test/context/litemode/AtBeanLiteModeScopeTests.java index 811ae9d070..98557992be 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AtBeanLiteModeScopeTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/litemode/AtBeanLiteModeScopeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,18 +14,16 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr9051; +package org.springframework.test.context.litemode; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Scope; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -36,9 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = AtBeanLiteModeScopeTests.LiteBeans.class) -public class AtBeanLiteModeScopeTests { +@SpringJUnitConfig(AtBeanLiteModeScopeTests.LiteBeans.class) +class AtBeanLiteModeScopeTests { /** * This is intentionally not annotated with {@code @Configuration}. @@ -46,7 +43,7 @@ public class AtBeanLiteModeScopeTests { static class LiteBeans { @Bean - public LifecycleBean singleton() { + LifecycleBean singleton() { LifecycleBean bean = new LifecycleBean("singleton"); assertThat(bean.isInitialized()).isFalse(); return bean; @@ -54,7 +51,7 @@ public class AtBeanLiteModeScopeTests { @Bean @Scope("prototype") - public LifecycleBean prototype() { + LifecycleBean prototype() { LifecycleBean bean = new LifecycleBean("prototype"); assertThat(bean.isInitialized()).isFalse(); return bean; @@ -63,19 +60,19 @@ public class AtBeanLiteModeScopeTests { @Autowired - private ApplicationContext applicationContext; + ApplicationContext applicationContext; @Autowired @Qualifier("singleton") - private LifecycleBean injectedSingletonBean; + LifecycleBean injectedSingletonBean; @Autowired @Qualifier("prototype") - private LifecycleBean injectedPrototypeBean; + LifecycleBean injectedPrototypeBean; @Test - public void singletonLiteBean() { + void singletonLiteBean() { assertThat(injectedSingletonBean).isNotNull(); assertThat(injectedSingletonBean.isInitialized()).isTrue(); @@ -87,7 +84,7 @@ public class AtBeanLiteModeScopeTests { } @Test - public void prototypeLiteBean() { + void prototypeLiteBean() { assertThat(injectedPrototypeBean).isNotNull(); assertThat(injectedPrototypeBean.isInitialized()).isTrue(); diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/LifecycleBean.java b/spring-test/src/test/java/org/springframework/test/context/litemode/LifecycleBean.java similarity index 95% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/LifecycleBean.java rename to spring-test/src/test/java/org/springframework/test/context/litemode/LifecycleBean.java index 2a8c01156c..b5db347604 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/LifecycleBean.java +++ b/spring-test/src/test/java/org/springframework/test/context/litemode/LifecycleBean.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr9051; +package org.springframework.test.context.litemode; import jakarta.annotation.PostConstruct; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/TransactionalAnnotatedConfigClassWithAtConfigurationTests.java b/spring-test/src/test/java/org/springframework/test/context/litemode/TransactionalAnnotatedConfigClassWithAtConfigurationTests.java similarity index 78% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/TransactionalAnnotatedConfigClassWithAtConfigurationTests.java rename to spring-test/src/test/java/org/springframework/test/context/litemode/TransactionalAnnotatedConfigClassWithAtConfigurationTests.java index 3a8df08203..3cac87b000 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/TransactionalAnnotatedConfigClassWithAtConfigurationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/litemode/TransactionalAnnotatedConfigClassWithAtConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -14,11 +14,11 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr9051; +package org.springframework.test.context.litemode; import javax.sql.DataSource; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.context.annotation.Bean; @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @see TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests */ @ContextConfiguration -public class TransactionalAnnotatedConfigClassWithAtConfigurationTests extends +class TransactionalAnnotatedConfigClassWithAtConfigurationTests extends AbstractTransactionalAnnotatedConfigClassTests { /** @@ -52,7 +52,7 @@ public class TransactionalAnnotatedConfigClassWithAtConfigurationTests extends static class Config { @Bean - public Employee employee() { + Employee employee() { Employee employee = new Employee(); employee.setName("John Smith"); employee.setAge(42); @@ -61,24 +61,24 @@ public class TransactionalAnnotatedConfigClassWithAtConfigurationTests extends } @Bean - public PlatformTransactionManager transactionManager() { + PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } @Bean - public DataSource dataSource() { + DataSource dataSource() { return new EmbeddedDatabaseBuilder()// - .addScript("classpath:/org/springframework/test/jdbc/schema.sql")// - // Ensure that this in-memory database is only used by this class: - .setName(getClass().getName())// - .build(); + .addScript("classpath:/org/springframework/test/jdbc/schema.sql")// + // Ensure that this in-memory database is only used by this class: + .setName(getClass().getName())// + .build(); } } - @Before - public void compareDataSources() { + @BeforeEach + void compareDataSources() { // NOTE: the two DataSource instances ARE the same! assertThat(dataSourceViaInjection).isSameAs(dataSourceFromTxManager); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests.java b/spring-test/src/test/java/org/springframework/test/context/litemode/TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests.java similarity index 88% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests.java rename to spring-test/src/test/java/org/springframework/test/context/litemode/TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests.java index 7914ac6aff..d522bc9743 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/litemode/TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -14,11 +14,11 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr9051; +package org.springframework.test.context.litemode; import javax.sql.DataSource; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.context.annotation.Bean; @@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @see TransactionalAnnotatedConfigClassWithAtConfigurationTests */ @ContextConfiguration(classes = TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests.AnnotatedFactoryBeans.class) -public class TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests extends +class TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests extends AbstractTransactionalAnnotatedConfigClassTests { /** @@ -58,7 +58,7 @@ public class TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests exte static class AnnotatedFactoryBeans { @Bean - public Employee employee() { + Employee employee() { Employee employee = new Employee(); employee.setName("John Smith"); employee.setAge(42); @@ -67,7 +67,7 @@ public class TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests exte } @Bean - public PlatformTransactionManager transactionManager() { + PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } @@ -92,19 +92,19 @@ public class TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests exte * which is almost certainly not the desired or intended behavior. */ @Bean - public DataSource dataSource() { + DataSource dataSource() { return new EmbeddedDatabaseBuilder()// - .addScript("classpath:/org/springframework/test/jdbc/schema.sql")// - // Ensure that this in-memory database is only used by this class: - .setName(getClass().getName())// - .build(); + .addScript("classpath:/org/springframework/test/jdbc/schema.sql")// + // Ensure that this in-memory database is only used by this class: + .setName(getClass().getName())// + .build(); } } - @Before - public void compareDataSources() { + @BeforeEach + void compareDataSources() { // NOTE: the two DataSource instances are NOT the same! assertThat(dataSourceViaInjection).isNotSameAs(dataSourceFromTxManager); } @@ -119,7 +119,7 @@ public class TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests exte */ @AfterTransaction @Override - public void afterTransaction() { + void afterTransaction() { assertThat(deletePerson(YODA)).as("Deleting yoda").isEqualTo(1); // NOTE: We would actually expect that there are now ZERO entries in the diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/HibernateSessionFlushingTests.java similarity index 71% rename from spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java rename to spring-test/src/test/java/org/springframework/test/context/orm/hibernate/HibernateSessionFlushingTests.java index 54f2177dc9..239f8f910f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/HibernateSessionFlushingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -14,21 +14,24 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.orm; +package org.springframework.test.context.orm.hibernate; + +import javax.sql.DataSource; import jakarta.persistence.PersistenceException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.exception.ConstraintViolationException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; -import org.springframework.test.context.junit4.orm.domain.DriversLicense; -import org.springframework.test.context.junit4.orm.domain.Person; -import org.springframework.test.context.junit4.orm.service.PersonService; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import org.springframework.test.context.orm.hibernate.domain.DriversLicense; +import org.springframework.test.context.orm.hibernate.domain.Person; +import org.springframework.test.context.orm.hibernate.service.PersonService; +import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThat; @@ -43,23 +46,32 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT * @author Juergen Hoeller * @author Vlad Mihalcea * @since 3.0 - * @see org.springframework.test.context.junit.jupiter.orm.JpaEntityListenerTests + * @see org.springframework.test.context.orm.jpa.JpaEntityListenerTests */ -@ContextConfiguration -public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4SpringContextTests { +@SpringJUnitConfig +@Transactional +class HibernateSessionFlushingTests { private static final String SAM = "Sam"; private static final String JUERGEN = "Juergen"; - @Autowired - private PersonService personService; + JdbcTemplate jdbcTemplate; @Autowired - private SessionFactory sessionFactory; + SessionFactory sessionFactory; + + @Autowired + PersonService personService; - @Before - public void setup() { + @Autowired + void setDataSource(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + + @BeforeEach + void setup() { assertThatTransaction().isActive(); assertThat(personService).as("PersonService should have been autowired.").isNotNull(); assertThat(sessionFactory).as("SessionFactory should have been autowired.").isNotNull(); @@ -67,7 +79,7 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp @Test - public void findSam() { + void findSam() { Person sam = personService.findByName(SAM); assertThat(sam).as("Should be able to find Sam").isNotNull(); DriversLicense driversLicense = sam.getDriversLicense(); @@ -77,7 +89,7 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp @Test // SPR-16956 @Transactional(readOnly = true) - public void findSamWithReadOnlySession() { + void findSamWithReadOnlySession() { Person sam = personService.findByName(SAM); sam.setName("Vlad"); // By setting setDefaultReadOnly(true), the user can no longer modify any entity... @@ -88,7 +100,7 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp } @Test - public void saveJuergenWithDriversLicense() { + void saveJuergenWithDriversLicense() { DriversLicense driversLicense = new DriversLicense(2L, 2222L); Person juergen = new Person(JUERGEN, driversLicense); int numRows = countRowsInTable("person"); @@ -99,21 +111,21 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp } @Test - public void saveJuergenWithNullDriversLicense() { - assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(() -> - personService.save(new Person(JUERGEN))); + void saveJuergenWithNullDriversLicense() { + assertThatExceptionOfType(ConstraintViolationException.class) + .isThrownBy(() -> personService.save(new Person(JUERGEN))); } @Test // no expected exception! - public void updateSamWithNullDriversLicenseWithoutSessionFlush() { + void updateSamWithNullDriversLicenseWithoutSessionFlush() { updateSamWithNullDriversLicense(); // False positive, since an exception will be thrown once the session is // finally flushed (i.e., in production code) } @Test - public void updateSamWithNullDriversLicenseWithSessionFlush() { + void updateSamWithNullDriversLicenseWithSessionFlush() { updateSamWithNullDriversLicense(); assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(() -> { // Manual flush is required to avoid false positive in test @@ -134,4 +146,8 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp personService.save(sam); } + private int countRowsInTable(String tableName) { + return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/domain/DriversLicense.java b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/domain/DriversLicense.java similarity index 94% rename from spring-test/src/test/java/org/springframework/test/context/junit4/orm/domain/DriversLicense.java rename to spring-test/src/test/java/org/springframework/test/context/orm/hibernate/domain/DriversLicense.java index 8f3d9df059..905ab6c2fb 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/domain/DriversLicense.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/domain/DriversLicense.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.orm.domain; +package org.springframework.test.context.orm.hibernate.domain; /** * DriversLicense POJO. diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/domain/Person.java b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/domain/Person.java similarity index 96% rename from spring-test/src/test/java/org/springframework/test/context/junit4/orm/domain/Person.java rename to spring-test/src/test/java/org/springframework/test/context/orm/hibernate/domain/Person.java index e0348fd1bc..0168c6719a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/domain/Person.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/domain/Person.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.orm.domain; +package org.springframework.test.context.orm.hibernate.domain; /** * Person POJO. diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/repository/hibernate/HibernatePersonRepository.java b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/repository/HibernatePersonRepository.java similarity index 65% rename from spring-test/src/test/java/org/springframework/test/context/junit4/orm/repository/hibernate/HibernatePersonRepository.java rename to spring-test/src/test/java/org/springframework/test/context/orm/hibernate/repository/HibernatePersonRepository.java index 317ec5a5fd..66f9cb03dd 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/repository/hibernate/HibernatePersonRepository.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/repository/HibernatePersonRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2025 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. @@ -14,14 +14,12 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.orm.repository.hibernate; +package org.springframework.test.context.orm.hibernate.repository; import org.hibernate.SessionFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; -import org.springframework.test.context.junit4.orm.domain.Person; -import org.springframework.test.context.junit4.orm.repository.PersonRepository; +import org.springframework.test.context.orm.hibernate.domain.Person; /** * Hibernate implementation of the {@link PersonRepository} API. @@ -30,12 +28,11 @@ import org.springframework.test.context.junit4.orm.repository.PersonRepository; * @since 3.0 */ @Repository -public class HibernatePersonRepository implements PersonRepository { +class HibernatePersonRepository implements PersonRepository { private final SessionFactory sessionFactory; - @Autowired public HibernatePersonRepository(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @@ -48,8 +45,10 @@ public class HibernatePersonRepository implements PersonRepository { @Override public Person findByName(String name) { - return (Person) this.sessionFactory.getCurrentSession().createQuery( - "from Person person where person.name = :name").setParameter("name", name).getSingleResult(); + return (Person) this.sessionFactory.getCurrentSession() + .createQuery("from Person person where person.name = :name") + .setParameter("name", name) + .getSingleResult(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/repository/PersonRepository.java b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/repository/PersonRepository.java similarity index 85% rename from spring-test/src/test/java/org/springframework/test/context/junit4/orm/repository/PersonRepository.java rename to spring-test/src/test/java/org/springframework/test/context/orm/hibernate/repository/PersonRepository.java index b75f511f93..7dfc668081 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/repository/PersonRepository.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/repository/PersonRepository.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.orm.repository; +package org.springframework.test.context.orm.hibernate.repository; -import org.springframework.test.context.junit4.orm.domain.Person; +import org.springframework.test.context.orm.hibernate.domain.Person; /** * Person Repository API. diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/service/PersonService.java b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/service/PersonService.java similarity index 85% rename from spring-test/src/test/java/org/springframework/test/context/junit4/orm/service/PersonService.java rename to spring-test/src/test/java/org/springframework/test/context/orm/hibernate/service/PersonService.java index d42b03602e..3334fce555 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/service/PersonService.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/service/PersonService.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.orm.service; +package org.springframework.test.context.orm.hibernate.service; -import org.springframework.test.context.junit4.orm.domain.Person; +import org.springframework.test.context.orm.hibernate.domain.Person; /** * Person Service API. diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/service/impl/StandardPersonService.java b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/service/StandardPersonService.java similarity index 72% rename from spring-test/src/test/java/org/springframework/test/context/junit4/orm/service/impl/StandardPersonService.java rename to spring-test/src/test/java/org/springframework/test/context/orm/hibernate/service/StandardPersonService.java index 2e98308a19..da9df33b85 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/service/impl/StandardPersonService.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/hibernate/service/StandardPersonService.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2025 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. @@ -14,13 +14,11 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.orm.service.impl; +package org.springframework.test.context.orm.hibernate.service; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.test.context.junit4.orm.domain.Person; -import org.springframework.test.context.junit4.orm.repository.PersonRepository; -import org.springframework.test.context.junit4.orm.service.PersonService; +import org.springframework.test.context.orm.hibernate.domain.Person; +import org.springframework.test.context.orm.hibernate.repository.PersonRepository; import org.springframework.transaction.annotation.Transactional; /** @@ -31,12 +29,11 @@ import org.springframework.transaction.annotation.Transactional; */ @Service @Transactional(readOnly = true) -public class StandardPersonService implements PersonService { +class StandardPersonService implements PersonService { private final PersonRepository personRepository; - @Autowired public StandardPersonService(PersonRepository personRepository) { this.personRepository = personRepository; } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/JpaEntityListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/JpaEntityListenerTests.java similarity index 92% rename from spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/JpaEntityListenerTests.java rename to spring-test/src/test/java/org/springframework/test/context/orm/jpa/JpaEntityListenerTests.java index 0056da8df6..2b6eb5adea 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/JpaEntityListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/JpaEntityListenerTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit.jupiter.orm; +package org.springframework.test.context.orm.jpa; import java.util.List; @@ -37,10 +37,10 @@ import org.springframework.orm.jpa.vendor.Database; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.springframework.test.context.junit.jupiter.orm.domain.JpaPersonRepository; -import org.springframework.test.context.junit.jupiter.orm.domain.Person; -import org.springframework.test.context.junit.jupiter.orm.domain.PersonListener; -import org.springframework.test.context.junit.jupiter.orm.domain.PersonRepository; +import org.springframework.test.context.orm.jpa.domain.JpaPersonRepository; +import org.springframework.test.context.orm.jpa.domain.Person; +import org.springframework.test.context.orm.jpa.domain.PersonListener; +import org.springframework.test.context.orm.jpa.domain.PersonRepository; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Transactional; @@ -53,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 5.3.18 * @see issue gh-28228 - * @see org.springframework.test.context.junit4.orm.HibernateSessionFlushingTests + * @see org.springframework.test.context.orm.hibernate.HibernateSessionFlushingTests */ @SpringJUnitConfig @Transactional diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/JpaPersonRepository.java b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/JpaPersonRepository.java similarity index 95% rename from spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/JpaPersonRepository.java rename to spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/JpaPersonRepository.java index eb5e38973e..fdbdfcdbd5 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/JpaPersonRepository.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/JpaPersonRepository.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit.jupiter.orm.domain; +package org.springframework.test.context.orm.jpa.domain; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/Person.java b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/Person.java similarity index 95% rename from spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/Person.java rename to spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/Person.java index 1a67dc439b..e2b77c8161 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/Person.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/Person.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit.jupiter.orm.domain; +package org.springframework.test.context.orm.jpa.domain; import jakarta.persistence.Entity; import jakarta.persistence.EntityListeners; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/PersonListener.java b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/PersonListener.java similarity index 96% rename from spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/PersonListener.java rename to spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/PersonListener.java index 1ba3dce8b6..0e4752ce56 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/PersonListener.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/PersonListener.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit.jupiter.orm.domain; +package org.springframework.test.context.orm.jpa.domain; import java.util.ArrayList; import java.util.List; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/PersonRepository.java b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/PersonRepository.java similarity index 92% rename from spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/PersonRepository.java rename to spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/PersonRepository.java index 9576a649d0..b981db1198 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/orm/domain/PersonRepository.java +++ b/spring-test/src/test/java/org/springframework/test/context/orm/jpa/domain/PersonRepository.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit.jupiter.orm.domain; +package org.springframework.test.context.orm.jpa.domain; /** * Person repository API. diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DefaultProfileAnnotationConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DefaultProfileAnnotationConfigTests.java similarity index 65% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DefaultProfileAnnotationConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/annotation/DefaultProfileAnnotationConfigTests.java index 6e6fed937d..70b9f1532f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DefaultProfileAnnotationConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DefaultProfileAnnotationConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,16 +14,14 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.annotation; +package org.springframework.test.context.profile.annotation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.beans.testfixture.beans.Pet; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.AnnotationConfigContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -32,25 +30,24 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { DefaultProfileConfig.class, DevProfileConfig.class }, loader = AnnotationConfigContextLoader.class) -public class DefaultProfileAnnotationConfigTests { +@SpringJUnitConfig(classes = { DefaultProfileConfig.class, DevProfileConfig.class }, loader = AnnotationConfigContextLoader.class) +class DefaultProfileAnnotationConfigTests { @Autowired - protected Pet pet; + Pet pet; @Autowired(required = false) - protected Employee employee; + Employee employee; @Test - public void pet() { + void pet() { assertThat(pet).isNotNull(); assertThat(pet.getName()).isEqualTo("Fido"); } @Test - public void employee() { + void employee() { assertThat(employee).as("employee bean should not be created for the default profile").isNull(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DefaultProfileConfig.java b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DefaultProfileConfig.java similarity index 90% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DefaultProfileConfig.java rename to spring-test/src/test/java/org/springframework/test/context/profile/annotation/DefaultProfileConfig.java index 67fefb7719..f5ade70123 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DefaultProfileConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DefaultProfileConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.annotation; +package org.springframework.test.context.profile.annotation; import org.springframework.beans.testfixture.beans.Pet; import org.springframework.context.annotation.Bean; @@ -24,7 +24,7 @@ import org.springframework.context.annotation.Configuration; * @author Sam Brannen * @since 3.1 */ -@Configuration +@Configuration(proxyBeanMethods = false) public class DefaultProfileConfig { @Bean diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileAnnotationConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileAnnotationConfigTests.java similarity index 77% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileAnnotationConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileAnnotationConfigTests.java index 36aa83b114..7587d24a8b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileAnnotationConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileAnnotationConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.annotation; +package org.springframework.test.context.profile.annotation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ActiveProfiles; @@ -27,11 +27,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ActiveProfiles("dev") -public class DevProfileAnnotationConfigTests extends DefaultProfileAnnotationConfigTests { +class DevProfileAnnotationConfigTests extends DefaultProfileAnnotationConfigTests { @Test @Override - public void employee() { + void employee() { assertThat(employee).as("employee bean should be loaded for the 'dev' profile").isNotNull(); assertThat(employee.getName()).isEqualTo("John Smith"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileConfig.java b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileConfig.java similarity index 94% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileConfig.java rename to spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileConfig.java index c8a964ce7a..a662ee16a6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.annotation; +package org.springframework.test.context.profile.annotation; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.context.annotation.Bean; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DevProfileResolverAnnotationConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileResolverAnnotationConfigTests.java similarity index 85% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DevProfileResolverAnnotationConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileResolverAnnotationConfigTests.java index a913abaf6e..d27534dab9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DevProfileResolverAnnotationConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/annotation/DevProfileResolverAnnotationConfigTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.importresource; +package org.springframework.test.context.profile.annotation; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfilesResolver; @@ -24,7 +24,7 @@ import org.springframework.test.context.ActiveProfilesResolver; * @since 4.0 */ @ActiveProfiles(resolver = DevProfileResolverAnnotationConfigTests.class, inheritProfiles = false) -public class DevProfileResolverAnnotationConfigTests extends DevProfileAnnotationConfigTests implements +class DevProfileResolverAnnotationConfigTests extends DevProfileAnnotationConfigTests implements ActiveProfilesResolver { @Override diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DefaultProfileAnnotationConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/importresource/DefaultProfileAnnotationConfigTests.java similarity index 66% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DefaultProfileAnnotationConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/importresource/DefaultProfileAnnotationConfigTests.java index 73b57ef93d..bfd2fc7354 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DefaultProfileAnnotationConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/importresource/DefaultProfileAnnotationConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,16 +14,14 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.importresource; +package org.springframework.test.context.profile.importresource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.beans.testfixture.beans.Pet; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -31,25 +29,24 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @since 3.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = DefaultProfileConfig.class) -public class DefaultProfileAnnotationConfigTests { +@SpringJUnitConfig(DefaultProfileConfig.class) +class DefaultProfileAnnotationConfigTests { @Autowired - protected Pet pet; + Pet pet; @Autowired(required = false) - protected Employee employee; + Employee employee; @Test - public void pet() { + void pet() { assertThat(pet).isNotNull(); assertThat(pet.getName()).isEqualTo("Fido"); } @Test - public void employee() { + void employee() { assertThat(employee).as("employee bean should not be created for the default profile").isNull(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DefaultProfileConfig.java b/spring-test/src/test/java/org/springframework/test/context/profile/importresource/DefaultProfileConfig.java similarity index 83% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DefaultProfileConfig.java rename to spring-test/src/test/java/org/springframework/test/context/profile/importresource/DefaultProfileConfig.java index f07511b894..24a11e09fb 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DefaultProfileConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/importresource/DefaultProfileConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.importresource; +package org.springframework.test.context.profile.importresource; import org.springframework.beans.testfixture.beans.Pet; import org.springframework.context.annotation.Bean; @@ -25,8 +25,8 @@ import org.springframework.context.annotation.ImportResource; * @author Juergen Hoeller * @since 3.1 */ -@Configuration -@ImportResource("org/springframework/test/context/junit4/profile/importresource/import.xml") +@Configuration(proxyBeanMethods = false) +@ImportResource("org/springframework/test/context/profile/importresource/import.xml") public class DefaultProfileConfig { @Bean diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DevProfileAnnotationConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/importresource/DevProfileAnnotationConfigTests.java similarity index 77% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DevProfileAnnotationConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/importresource/DevProfileAnnotationConfigTests.java index 0eb24078af..553be1ee63 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/importresource/DevProfileAnnotationConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/importresource/DevProfileAnnotationConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.importresource; +package org.springframework.test.context.profile.importresource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ActiveProfiles; @@ -27,11 +27,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ActiveProfiles("dev") -public class DevProfileAnnotationConfigTests extends DefaultProfileAnnotationConfigTests { +class DevProfileAnnotationConfigTests extends DefaultProfileAnnotationConfigTests { @Test @Override - public void employee() { + void employee() { assertThat(employee).as("employee bean should be loaded for the 'dev' profile").isNotNull(); assertThat(employee.getName()).isEqualTo("John Smith"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileResolverAnnotationConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/importresource/DevProfileResolverAnnotationConfigTests.java similarity index 94% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileResolverAnnotationConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/importresource/DevProfileResolverAnnotationConfigTests.java index 9fe028dc7a..b388184555 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/annotation/DevProfileResolverAnnotationConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/importresource/DevProfileResolverAnnotationConfigTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.annotation; +package org.springframework.test.context.profile.importresource; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfilesResolver; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/resolver/ClassNameActiveProfilesResolver.java b/spring-test/src/test/java/org/springframework/test/context/profile/resolver/ClassNameActiveProfilesResolver.java similarity index 73% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/resolver/ClassNameActiveProfilesResolver.java rename to spring-test/src/test/java/org/springframework/test/context/profile/resolver/ClassNameActiveProfilesResolver.java index d352b5a5a4..f2a8e699f9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/resolver/ClassNameActiveProfilesResolver.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/resolver/ClassNameActiveProfilesResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2025 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.resolver; +package org.springframework.test.context.profile.resolver; import org.springframework.test.context.ActiveProfilesResolver; @@ -22,10 +22,11 @@ import org.springframework.test.context.ActiveProfilesResolver; * @author Michail Nikolaev * @since 4.0 */ -public class ClassNameActiveProfilesResolver implements ActiveProfilesResolver { +class ClassNameActiveProfilesResolver implements ActiveProfilesResolver { @Override public String[] resolve(Class testClass) { - return new String[] { testClass.getSimpleName().toLowerCase() }; + return new String[] { testClass.getSimpleName() }; } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/profile/resolver/ClassNameActiveProfilesResolverTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/resolver/ClassNameActiveProfilesResolverTests.java new file mode 100644 index 0000000000..4c4c87d2dc --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/profile/resolver/ClassNameActiveProfilesResolverTests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2002-2025 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.profile.resolver; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Michail Nikolaev + * @author Sam Brannen + * @since 4.0 + */ +@SpringJUnitConfig +@ActiveProfiles(resolver = ClassNameActiveProfilesResolver.class) +class ClassNameActiveProfilesResolverTests { + + @Test + void test(@Autowired Environment environment) { + assertThat(environment.getActiveProfiles()).contains(getClass().getSimpleName()); + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DefaultProfileXmlConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/xml/DefaultProfileXmlConfigTests.java similarity index 68% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DefaultProfileXmlConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/xml/DefaultProfileXmlConfigTests.java index d9effe2223..14ccf3775f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DefaultProfileXmlConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/xml/DefaultProfileXmlConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,16 +14,14 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.xml; +package org.springframework.test.context.profile.xml; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Employee; import org.springframework.beans.testfixture.beans.Pet; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -31,25 +29,24 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class DefaultProfileXmlConfigTests { +@SpringJUnitConfig +class DefaultProfileXmlConfigTests { @Autowired - protected Pet pet; + Pet pet; @Autowired(required = false) - protected Employee employee; + Employee employee; @Test - public void pet() { + void pet() { assertThat(pet).isNotNull(); assertThat(pet.getName()).isEqualTo("Fido"); } @Test - public void employee() { + void employee() { assertThat(employee).as("employee bean should not be created for the default profile").isNull(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DevProfileResolverXmlConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/xml/DevProfileResolverXmlConfigTests.java similarity index 84% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DevProfileResolverXmlConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/xml/DevProfileResolverXmlConfigTests.java index ef30225d9c..7453f36fa4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DevProfileResolverXmlConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/xml/DevProfileResolverXmlConfigTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.xml; +package org.springframework.test.context.profile.xml; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfilesResolver; @@ -24,7 +24,7 @@ import org.springframework.test.context.ActiveProfilesResolver; * @since 4.0 */ @ActiveProfiles(resolver = DevProfileResolverXmlConfigTests.class, inheritProfiles = false) -public class DevProfileResolverXmlConfigTests extends DevProfileXmlConfigTests implements ActiveProfilesResolver { +class DevProfileResolverXmlConfigTests extends DevProfileXmlConfigTests implements ActiveProfilesResolver { @Override public String[] resolve(Class testClass) { diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DevProfileXmlConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/profile/xml/DevProfileXmlConfigTests.java similarity index 79% rename from spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DevProfileXmlConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/profile/xml/DevProfileXmlConfigTests.java index b79ef637ed..854e9c7066 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/profile/xml/DevProfileXmlConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/profile/xml/DevProfileXmlConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.profile.xml; +package org.springframework.test.context.profile.xml; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.ActiveProfiles; @@ -27,11 +27,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.1 */ @ActiveProfiles("dev") -public class DevProfileXmlConfigTests extends DefaultProfileXmlConfigTests { +class DevProfileXmlConfigTests extends DefaultProfileXmlConfigTests { @Test @Override - public void employee() { + void employee() { assertThat(employee).as("employee bean should be loaded for the 'dev' profile").isNotNull(); assertThat(employee.getName()).isEqualTo("John Smith"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/AbstractBasicWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/AbstractBasicWacTests.java index 70d7aca319..0aefc61994 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/AbstractBasicWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/AbstractBasicWacTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -19,15 +19,13 @@ package org.springframework.test.context.web; import java.io.File; import jakarta.servlet.ServletContext; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockServletContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.request.ServletWebRequest; @@ -38,7 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2 */ -@RunWith(SpringRunner.class) @WebAppConfiguration public abstract class AbstractBasicWacTests implements ServletContextAware { @@ -72,7 +69,7 @@ public abstract class AbstractBasicWacTests implements ServletContextAware { } @Test - public void basicWacFeatures() throws Exception { + protected void basicWacFeatures() throws Exception { assertThat(wac.getServletContext()).as("ServletContext should be set in the WAC.").isNotNull(); assertThat(servletContext).as("ServletContext should have been set via ServletContextAware.").isNotNull(); @@ -90,7 +87,6 @@ public abstract class AbstractBasicWacTests implements ServletContextAware { assertThat(request.getServletContext()).as("ServletContext in the WAC and in the mock request").isSameAs(mockServletContext); assertThat(mockServletContext.getRealPath("index.jsp")).as("Getting real path for ServletContext resource.").isEqualTo(new File("src/main/webapp/index.jsp").getCanonicalPath()); - } } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/BasicAnnotationConfigWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/BasicAnnotationConfigWacTests.java index d0c72e11e6..ec0d9a6f13 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/BasicAnnotationConfigWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/BasicAnnotationConfigWacTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -16,12 +16,12 @@ package org.springframework.test.context.web; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -29,35 +29,37 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2 */ -@ContextConfiguration -public class BasicAnnotationConfigWacTests extends AbstractBasicWacTests { - - @Configuration - static class Config { - - @Bean - public String foo() { - return "enigma"; - } - - @Bean - public ServletContextAwareBean servletContextAwareBean() { - return new ServletContextAwareBean(); - } - } +@SpringJUnitConfig +class BasicAnnotationConfigWacTests extends AbstractBasicWacTests { @Autowired - protected ServletContextAwareBean servletContextAwareBean; + ServletContextAwareBean servletContextAwareBean; @Test - public void fooEnigmaAutowired() { + void fooEnigmaAutowired() { assertThat(foo).isEqualTo("enigma"); } @Test - public void servletContextAwareBeanProcessed() { + void servletContextAwareBeanProcessed() { assertThat(servletContextAwareBean).isNotNull(); - assertThat(servletContextAwareBean.servletContext).isNotNull(); + assertThat(servletContextAwareBean.getServletContext()).isNotNull(); + } + + + @Configuration(proxyBeanMethods = false) + static class Config { + + @Bean + String foo() { + return "enigma"; + } + + @Bean + ServletContextAwareBean servletContextAwareBean() { + return new ServletContextAwareBean(); + } + } } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/BasicGroovyWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/BasicGroovyWacTests.java index 69239d026c..980e5ca6ed 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/BasicGroovyWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/BasicGroovyWacTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -16,9 +16,11 @@ package org.springframework.test.context.web; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -28,11 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @see BasicXmlWacTests */ // Config loaded from BasicGroovyWacTestsContext.groovy +@ExtendWith(SpringExtension.class) @ContextConfiguration -public class BasicGroovyWacTests extends AbstractBasicWacTests { +class BasicGroovyWacTests extends AbstractBasicWacTests { @Test - public void groovyFooAutowired() { + void groovyFooAutowired() { assertThat(foo).isEqualTo("Groovy Foo"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/BasicXmlWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/BasicXmlWacTests.java index c1e9ecb368..2ff6b3cbf4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/BasicXmlWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/BasicXmlWacTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -16,21 +16,26 @@ package org.springframework.test.context.web; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; /** * @author Sam Brannen * @since 3.2 + * @see BasicGroovyWacTests */ +// Config loaded from BasicXmlWacTests-context.xml +@ExtendWith(SpringExtension.class) @ContextConfiguration -public class BasicXmlWacTests extends AbstractBasicWacTests { +class BasicXmlWacTests extends AbstractBasicWacTests { @Test - public void fooBarAutowired() { + void fooBarAutowired() { assertThat(foo).isEqualTo("bar"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9799/Spr9799AnnotationConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/web/EnableWebMvcAnnotationConfigTests.java similarity index 57% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr9799/Spr9799AnnotationConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/web/EnableWebMvcAnnotationConfigTests.java index 91c809c3dc..d99426870a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9799/Spr9799AnnotationConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/EnableWebMvcAnnotationConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2025 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. @@ -14,42 +14,45 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr9799; +package org.springframework.test.context.web; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; +import org.springframework.web.context.WebApplicationContext; import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import static org.assertj.core.api.Assertions.assertThat; + /** * Integration tests used to assess claims raised in - * SPR-9799. + * gh-14432. * * @author Sam Brannen * @since 3.2 - * @see Spr9799XmlConfigTests + * @see EnableWebMvcXmlConfigTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitWebConfig // NOTE: if we omit the @WebAppConfiguration declaration, the ApplicationContext will fail // to load since @EnableWebMvc requires that the context be a WebApplicationContext. -@WebAppConfiguration -public class Spr9799AnnotationConfigTests { +class EnableWebMvcAnnotationConfigTests extends AbstractBasicWacTests { + + @Test + void applicationContextLoads(WebApplicationContext wac) { + assertThat(wac.getBean("foo", String.class)).isEqualTo("enigma"); + } + @Configuration @EnableWebMvc static class Config { - /* intentionally no beans defined */ - } - - @Test - public void applicationContextLoads() { - // no-op + @Bean + String foo() { + return "enigma"; + } } } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9799/Spr9799XmlConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/web/EnableWebMvcXmlConfigTests.java similarity index 50% rename from spring-test/src/test/java/org/springframework/test/context/junit4/spr9799/Spr9799XmlConfigTests.java rename to spring-test/src/test/java/org/springframework/test/context/web/EnableWebMvcXmlConfigTests.java index 37c7f93384..89545f0003 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9799/Spr9799XmlConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/EnableWebMvcXmlConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2025 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. @@ -14,30 +14,29 @@ * limitations under the License. */ -package org.springframework.test.context.junit4.spr9799; +package org.springframework.test.context.web; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; +import org.springframework.web.context.WebApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests used to assess claims raised in - * SPR-9799. + * gh-14432. * * @author Sam Brannen * @since 3.2 - * @see Spr9799AnnotationConfigTests + * @see EnableWebMvcAnnotationConfigTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class Spr9799XmlConfigTests { +@SpringJUnitWebConfig +class EnableWebMvcXmlConfigTests extends AbstractBasicWacTests { @Test - public void applicationContextLoads() { - // nothing to assert: we just want to make sure that the context loads without - // errors. + void applicationContextLoads(WebApplicationContext wac) { + assertThat(wac.getBean("foo", String.class)).isEqualTo("enigma"); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBean.java b/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBean.java index d9f0109ca0..6c6c951803 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBean.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2025 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. @@ -28,11 +28,15 @@ import org.springframework.web.context.ServletContextAware; */ public class ServletContextAwareBean implements ServletContextAware { - protected ServletContext servletContext; + private ServletContext servletContext; @Override public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; } + public ServletContext getServletContext() { + return this.servletContext; + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBeanWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBeanWacTests.java index d4eb31e33b..aa9059d778 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBeanWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBeanWacTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -16,9 +16,13 @@ package org.springframework.test.context.web; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.testkit.engine.EngineTestKit; -import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; /** * Introduced to investigate claims in SPR-11145. @@ -28,11 +32,16 @@ import static org.springframework.test.context.junit4.JUnitTestingUtils.runTests * @author Sam Brannen * @since 4.0.2 */ -public class ServletContextAwareBeanWacTests { +@ExtendWith(SpringExtension.class) +class ServletContextAwareBeanWacTests { @Test - public void ensureServletContextAwareBeanIsProcessedProperlyWhenExecutingJUnitManually() throws Exception { - runTestsAndAssertCounters(BasicAnnotationConfigWacTests.class, 3, 0, 3, 0, 0); + void ensureServletContextAwareBeanIsProcessedProperlyWhenExecutingJUnitManually() { + EngineTestKit.engine("junit-jupiter") + .selectors(selectClass(BasicAnnotationConfigWacTests.class)) + .execute() + .testEvents() + .assertStatistics(stats -> stats.started(3).succeeded(3).failed(0)); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/WebTestConfiguration.java b/spring-test/src/test/java/org/springframework/test/context/web/WebTestConfiguration.java index 1aab367a58..d8dc4b3bdf 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/WebTestConfiguration.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/WebTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2025 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. @@ -36,11 +36,12 @@ import org.springframework.test.context.ContextConfiguration; public @interface WebTestConfiguration { } -@Configuration +@Configuration(proxyBeanMethods = false) class FooConfig { @Bean public String foo() { return "enigma"; } + } diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr6128/AutowiredQualifierTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/AutowiredQualifierTests-context.xml similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/spr6128/AutowiredQualifierTests-context.xml rename to spring-test/src/test/resources/org/springframework/test/context/AutowiredQualifierTests-context.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/hybrid/HybridContextLoaderTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/hybrid/HybridContextLoaderTests-context.xml similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/hybrid/HybridContextLoaderTests-context.xml rename to spring-test/src/test/resources/org/springframework/test/context/hybrid/HybridContextLoaderTests-context.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr3896/BeanOverridingDefaultLocationsInheritedTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/inheritance/BeanOverridingDefaultLocationsInheritedTests-context.xml similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/spr3896/BeanOverridingDefaultLocationsInheritedTests-context.xml rename to spring-test/src/test/resources/org/springframework/test/context/inheritance/BeanOverridingDefaultLocationsInheritedTests-context.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr3896/DefaultLocationsBaseTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/inheritance/DefaultLocationsBaseTests-context.xml similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/spr3896/DefaultLocationsBaseTests-context.xml rename to spring-test/src/test/resources/org/springframework/test/context/inheritance/DefaultLocationsBaseTests-context.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr3896/DefaultLocationsInheritedTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/inheritance/DefaultLocationsInheritedTests-context.xml similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/spr3896/DefaultLocationsInheritedTests-context.xml rename to spring-test/src/test/resources/org/springframework/test/context/inheritance/DefaultLocationsInheritedTests-context.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/aci/xml/MultipleInitializersXmlConfigTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/initializers/xml/MultipleInitializersXmlConfigTests-context.xml similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/aci/xml/MultipleInitializersXmlConfigTests-context.xml rename to spring-test/src/test/resources/org/springframework/test/context/initializers/xml/MultipleInitializersXmlConfigTests-context.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/datasource-config-with-auto-generated-db-name.xml b/spring-test/src/test/resources/org/springframework/test/context/jdbc/datasource-config-with-auto-generated-db-name.xml similarity index 93% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/datasource-config-with-auto-generated-db-name.xml rename to spring-test/src/test/resources/org/springframework/test/context/jdbc/datasource-config-with-auto-generated-db-name.xml index 0ee91d260f..5b30a9820d 100644 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/datasource-config-with-auto-generated-db-name.xml +++ b/spring-test/src/test/resources/org/springframework/test/context/jdbc/datasource-config-with-auto-generated-db-name.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd"> - + diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/datasource-config.xml b/spring-test/src/test/resources/org/springframework/test/context/jdbc/datasource-config.xml similarity index 93% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/datasource-config.xml rename to spring-test/src/test/resources/org/springframework/test/context/jdbc/datasource-config.xml index b0c399df53..6d685c03db 100644 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/datasource-config.xml +++ b/spring-test/src/test/resources/org/springframework/test/context/jdbc/datasource-config.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd"> - + diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql b/spring-test/src/test/resources/org/springframework/test/context/jdbc/enigma-schema.sql similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql rename to spring-test/src/test/resources/org/springframework/test/context/jdbc/enigma-schema.sql diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr9799/Spr9799XmlConfigTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/junit4/spr9799/Spr9799XmlConfigTests-context.xml deleted file mode 100644 index 9eb8fced79..0000000000 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr9799/Spr9799XmlConfigTests-context.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/HibernateSessionFlushingTests-context.xml similarity index 82% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests-context.xml rename to spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/HibernateSessionFlushingTests-context.xml index 7ef4e6b9fa..706386f998 100644 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests-context.xml +++ b/spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/HibernateSessionFlushingTests-context.xml @@ -8,13 +8,13 @@ http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + - - + + - org/springframework/test/context/junit4/orm/domain/Person.hbm.xml - org/springframework/test/context/junit4/orm/domain/DriversLicense.hbm.xml + org/springframework/test/context/orm/hibernate/domain/Person.hbm.xml + org/springframework/test/context/orm/hibernate/domain/DriversLicense.hbm.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/db-schema.sql b/spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/db-schema.sql similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/orm/db-schema.sql rename to spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/db-schema.sql diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/db-test-data.sql b/spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/db-test-data.sql similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/orm/db-test-data.sql rename to spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/db-test-data.sql diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/domain/DriversLicense.hbm.xml b/spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/domain/DriversLicense.hbm.xml similarity index 78% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/orm/domain/DriversLicense.hbm.xml rename to spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/domain/DriversLicense.hbm.xml index 8f98d7d051..12fe954748 100644 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/domain/DriversLicense.hbm.xml +++ b/spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/domain/DriversLicense.hbm.xml @@ -4,7 +4,7 @@ - + diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/domain/Person.hbm.xml b/spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/domain/Person.hbm.xml similarity index 77% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/orm/domain/Person.hbm.xml rename to spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/domain/Person.hbm.xml index b0598cc2fe..447ca5d4af 100644 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/domain/Person.hbm.xml +++ b/spring-test/src/test/resources/org/springframework/test/context/orm/hibernate/domain/Person.hbm.xml @@ -4,12 +4,12 @@ - + - diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/profile/importresource/import.xml b/spring-test/src/test/resources/org/springframework/test/context/profile/importresource/import.xml similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/profile/importresource/import.xml rename to spring-test/src/test/resources/org/springframework/test/context/profile/importresource/import.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/profile/xml/DefaultProfileXmlConfigTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/profile/xml/DefaultProfileXmlConfigTests-context.xml similarity index 100% rename from spring-test/src/test/resources/org/springframework/test/context/junit4/profile/xml/DefaultProfileXmlConfigTests-context.xml rename to spring-test/src/test/resources/org/springframework/test/context/profile/xml/DefaultProfileXmlConfigTests-context.xml diff --git a/spring-test/src/test/resources/org/springframework/test/context/web/EnableWebMvcXmlConfigTests-context.xml b/spring-test/src/test/resources/org/springframework/test/context/web/EnableWebMvcXmlConfigTests-context.xml new file mode 100644 index 0000000000..7437f492b2 --- /dev/null +++ b/spring-test/src/test/resources/org/springframework/test/context/web/EnableWebMvcXmlConfigTests-context.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index 791d708678..577be682ce 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -15,8 +15,9 @@ - + + @@ -53,7 +54,6 @@ - @@ -114,8 +114,7 @@ - - +