Remove deprecated GenericPropertiesContextLoader from the TCF

Since GenericPropertiesContextLoader was deprecated in Spring Framework
5.3, we have decided to remove it in Spring Framework 6.0.

Closes gh-28911
This commit is contained in:
Sam Brannen
2022-08-02 12:53:07 +03:00
parent b0ab0edd9d
commit 9c91375d75
10 changed files with 1 additions and 434 deletions

View File

@@ -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 <i>inherited</i> (i.e., not explicitly declared) via
* {@link ContextConfiguration &#064;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");
}
}

View File

@@ -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
* &#064;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");
}
}

View File

@@ -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 <em>default ContextLoader class</em> 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<? extends ContextLoader> getDefaultContextLoaderClass(Class<?> testClass) {
return org.springframework.test.context.support.GenericPropertiesContextLoader.class;
}
}
}

View File

@@ -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;
/**
* <p>
* 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.
* </p>
* <p>
* Since no {@link ContextConfiguration#locations() locations} are explicitly defined, the
* {@code resourceSuffix} is set to &quot;-context.properties&quot;, 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: &quot;
* {@code /org/springframework/test/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties}
* &quot;.
* </p>
*
* @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");
}
}

View File

@@ -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,//

View File

@@ -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 {

View File

@@ -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<? extends ContextLoader> 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<? extends ContextLoader> 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;

View File

@@ -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");
}
}