diff --git a/spring-test/src/main/java/org/springframework/test/context/support/GenericPropertiesContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/GenericPropertiesContextLoader.java deleted file mode 100644 index 66f1f8e9e3..0000000000 --- a/spring-test/src/main/java/org/springframework/test/context/support/GenericPropertiesContextLoader.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2002-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.test.context.support; - -import java.util.Properties; - -import org.springframework.beans.factory.support.BeanDefinitionReader; -import org.springframework.context.support.GenericApplicationContext; -import org.springframework.test.context.MergedContextConfiguration; -import org.springframework.util.ObjectUtils; - -/** - * Concrete implementation of {@link AbstractGenericContextLoader} that reads - * bean definitions from Java {@link Properties} resources. - * - * @author Sam Brannen - * @since 2.5 - * @deprecated as of 5.3, in favor of Spring's common bean definition formats - * and/or custom loader implementations - */ -@Deprecated -public class GenericPropertiesContextLoader extends AbstractGenericContextLoader { - - /** - * Creates a new {@link org.springframework.beans.factory.support.PropertiesBeanDefinitionReader}. - * @return a new PropertiesBeanDefinitionReader - * @see org.springframework.beans.factory.support.PropertiesBeanDefinitionReader - */ - @Override - protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) { - return new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(context); - } - - /** - * Returns "{@code -context.properties}". - */ - @Override - protected String getResourceSuffix() { - return "-context.properties"; - } - - /** - * Ensure that the supplied {@link MergedContextConfiguration} does not - * contain {@link MergedContextConfiguration#getClasses() classes}. - * @since 4.0.4 - * @see AbstractGenericContextLoader#validateMergedContextConfiguration - */ - @Override - protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) { - if (mergedConfig.hasClasses()) { - String msg = String.format( - "Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, " - + "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(), - ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName()); - logger.error(msg); - throw new IllegalStateException(msg); - } - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLoaderTests.java deleted file mode 100644 index 3f61e2daec..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLoaderTests.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.configuration; - -import org.junit.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.ContextLoader; -import org.springframework.test.context.junit4.PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests which verify that the same custom {@link ContextLoader} can - * be used at all levels within a test class hierarchy when the - * {@code loader} is inherited (i.e., not explicitly declared) via - * {@link ContextConfiguration @ContextConfiguration}. - * - * @author Sam Brannen - * @since 3.0 - * @see PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests - * @see ContextConfigurationWithPropertiesExtendingPropertiesTests - */ -@ContextConfiguration -public class ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLoaderTests extends - PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests { - - @Autowired - private Pet dog; - - @Autowired - private String testString2; - - - @Test - public void verifyExtendedAnnotationAutowiredFields() { - assertThat(this.dog).as("The dog field should have been autowired.").isNotNull(); - assertThat(this.dog.getName()).isEqualTo("Fido"); - - assertThat(this.testString2).as("The testString2 field should have been autowired.").isNotNull(); - assertThat(this.testString2).isEqualTo("Test String #2"); - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesTests.java deleted file mode 100644 index a76729668c..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2002-2020 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.configuration; - -import org.junit.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.ContextLoader; -import org.springframework.test.context.junit4.PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests which verify that the same custom {@link ContextLoader} can - * be used at all levels within a test class hierarchy when the - * {@code loader} is explicitly declared via {@link ContextConfiguration - * @ContextConfiguration}. - * - * @author Sam Brannen - * @since 3.0 - * @see PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests - * @see ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLoaderTests - */ -@SuppressWarnings("deprecation") -@ContextConfiguration(loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) -public class ContextConfigurationWithPropertiesExtendingPropertiesTests extends - PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests { - - @Autowired - private Pet dog; - - @Autowired - private String testString2; - - - @Test - public void verifyExtendedAnnotationAutowiredFields() { - assertThat(this.dog).as("The dog field should have been autowired.").isNotNull(); - assertThat(this.dog.getName()).isEqualTo("Fido"); - - assertThat(this.testString2).as("The testString2 field should have been autowired.").isNotNull(); - assertThat(this.testString2).isEqualTo("Test String #2"); - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/CustomDefaultContextLoaderClassSpringRunnerTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/CustomDefaultContextLoaderClassSpringRunnerTests.java deleted file mode 100644 index 62a33fde0b..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/CustomDefaultContextLoaderClassSpringRunnerTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2002-2020 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; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.testfixture.beans.Pet; -import org.springframework.test.context.BootstrapWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.ContextLoader; -import org.springframework.test.context.support.DefaultTestContextBootstrapper; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests which verify that a subclass of {@link DefaultTestContextBootstrapper} - * can specify a custom default ContextLoader class that overrides the standard - * default class name. - * - * @author Sam Brannen - * @since 3.0 - */ -@RunWith(SpringRunner.class) -@BootstrapWith(CustomDefaultContextLoaderClassSpringRunnerTests.PropertiesBasedTestContextBootstrapper.class) -@ContextConfiguration("PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties") -public class CustomDefaultContextLoaderClassSpringRunnerTests { - - @Autowired - private Pet cat; - - @Autowired - private String testString; - - - @Test - public void verifyAnnotationAutowiredFields() { - assertThat(this.cat).as("The cat field should have been autowired.").isNotNull(); - assertThat(this.cat.getName()).isEqualTo("Garfield"); - - assertThat(this.testString).as("The testString field should have been autowired.").isNotNull(); - assertThat(this.testString).isEqualTo("Test String"); - } - - - public static class PropertiesBasedTestContextBootstrapper extends DefaultTestContextBootstrapper { - - @Override - @SuppressWarnings("deprecation") - protected Class getDefaultContextLoaderClass(Class testClass) { - return org.springframework.test.context.support.GenericPropertiesContextLoader.class; - } - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.java deleted file mode 100644 index a9176f76de..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.java +++ /dev/null @@ -1,77 +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; - -import java.util.Properties; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.testfixture.beans.Pet; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.ContextConfiguration; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - *

- * JUnit 4 based test class, which verifies the expected functionality of - * {@link SpringRunner} in conjunction with support for application contexts - * loaded from Java {@link Properties} files. Specifically, the - * {@link ContextConfiguration#loader() loader} attribute of {@code ContextConfiguration} - * and the - * {@link org.springframework.test.context.support.GenericPropertiesContextLoader#getResourceSuffix() - * resourceSuffix} property of {@code GenericPropertiesContextLoader} are tested. - *

- *

- * Since no {@link ContextConfiguration#locations() locations} are explicitly defined, the - * {@code resourceSuffix} is set to "-context.properties", and since default - * resource locations will be detected by default, this test class's dependencies will be - * injected via {@link Autowired annotation-based autowiring} from beans defined in the - * {@link ApplicationContext} loaded from the default classpath resource: " - * {@code /org/springframework/test/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties} - * ". - *

- * - * @author Sam Brannen - * @since 2.5 - * @see org.springframework.test.context.support.GenericPropertiesContextLoader - * @see SpringJUnit4ClassRunnerAppCtxTests - */ -@RunWith(SpringRunner.class) -@SuppressWarnings("deprecation") -@ContextConfiguration(loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) -public class PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests { - - @Autowired - private Pet cat; - - @Autowired - private String testString; - - - @Test - public void verifyAnnotationAutowiredFields() { - assertThat(this.cat).as("The cat field should have been autowired.").isNotNull(); - assertThat(this.cat.getName()).isEqualTo("Garfield"); - - assertThat(this.testString).as("The testString field should have been autowired.").isNotNull(); - assertThat(this.testString).isEqualTo("Test String"); - } - -} 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 13222ed97f..5302d1c0fb 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-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -93,8 +93,6 @@ StandardJUnit4FeaturesTests.class,// RelativePathSpringJUnit4ClassRunnerAppCtxTests.class,// MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests.class,// InheritedConfigSpringJUnit4ClassRunnerAppCtxTests.class,// - PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.class,// - CustomDefaultContextLoaderClassSpringRunnerTests.class,// ParameterizedDependencyInjectionTests.class,// ConcreteTransactionalJUnit4SpringContextTests.class,// ClassLevelTransactionalSpringRunnerTests.class,// diff --git a/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java index 09c60174d4..d8d9fd5a4f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java @@ -223,20 +223,6 @@ abstract class AbstractContextConfigurationUtilsTests { static class OverriddenClassesBar extends ClassesFoo { } - @SuppressWarnings("deprecation") - @ContextConfiguration(locations = "/foo.properties", loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) - @ActiveProfiles("foo") - static class PropertiesLocationsFoo { - } - - // Combining @Configuration classes with a Properties based loader doesn't really make - // sense, but that's OK for unit testing purposes. - @SuppressWarnings("deprecation") - @ContextConfiguration(classes = FooConfig.class, loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) - @ActiveProfiles("foo") - static class PropertiesClassesFoo { - } - @ContextConfiguration(classes = FooConfig.class, loader = AnnotationConfigContextLoader.class) @NestedTestConfiguration(INHERIT) static class OuterTestCase { diff --git a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java index 464b92e521..6e8c186f59 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java @@ -29,7 +29,6 @@ import org.springframework.core.annotation.AliasFor; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.BootstrapTestUtils; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.ContextLoader; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.support.BootstrapTestUtilsMergedConfigTests.EmptyConfigTestCase.Nested; @@ -140,28 +139,6 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt array(FooConfig.class), DelegatingSmartContextLoader.class); } - @Test - @SuppressWarnings("deprecation") - void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() { - Class testClass = PropertiesLocationsFoo.class; - Class expectedContextLoaderClass = org.springframework.test.context.support.GenericPropertiesContextLoader.class; - MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); - - assertMergedConfig(mergedConfig, testClass, array("classpath:/foo.properties"), EMPTY_CLASS_ARRAY, - expectedContextLoaderClass); - } - - @Test - @SuppressWarnings("deprecation") - void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClasses() { - Class testClass = PropertiesClassesFoo.class; - Class expectedContextLoaderClass = org.springframework.test.context.support.GenericPropertiesContextLoader.class; - MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); - - assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, array(FooConfig.class), - expectedContextLoaderClass); - } - @Test void buildMergedConfigWithLocalAndInheritedAnnotationsAndLocations() { Class testClass = LocationsBar.class; diff --git a/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java deleted file mode 100644 index f502e75206..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2002-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.test.context.support; - -import org.junit.jupiter.api.Test; - -import org.springframework.test.context.MergedContextConfiguration; - -import static org.assertj.core.api.Assertions.assertThatIllegalStateException; - -/** - * Unit tests for {@link GenericPropertiesContextLoader}. - * - * @author Sam Brannen - * @since 4.0.4 - */ -@SuppressWarnings("deprecation") -class GenericPropertiesContextLoaderTests { - - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - - @Test - void configMustNotContainAnnotatedClasses() throws Exception { - GenericPropertiesContextLoader loader = new GenericPropertiesContextLoader(); - MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, - new Class[] { getClass() }, EMPTY_STRING_ARRAY, loader); - assertThatIllegalStateException() - .isThrownBy(() -> loader.loadContext(mergedConfig)) - .withMessageContaining("does not support annotated classes"); - } - -} diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties b/spring-test/src/test/resources/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties deleted file mode 100644 index dc2eae729a..0000000000 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties +++ /dev/null @@ -1,5 +0,0 @@ -cat.(class)=org.springframework.beans.testfixture.beans.Pet -cat.$0=Garfield - -testString.(class)=java.lang.String -testString.$0=Test String