Deprecate methods in ContextLoader API in the TestContext framework

For Spring Framework 6.0 we have decided to deprecate the obsolete
methods in the ContextLoader API in the Spring TestContext Framework in
favor of the methods in the SmartContextLoader API which has been
available since Spring Framework 3.1.

Closes gh-28905
This commit is contained in:
Sam Brannen
2022-08-02 13:05:08 +03:00
parent 9c91375d75
commit 2207d65b82
10 changed files with 73 additions and 66 deletions

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.
@@ -37,20 +37,21 @@ import static org.assertj.core.api.Assertions.assertThat;
class CustomizedGenericXmlContextLoaderTests {
@Test
@SuppressWarnings("deprecation")
void customizeContext() throws Exception {
StringBuilder builder = new StringBuilder();
String expectedContents = "customizeContext() was called";
new GenericXmlContextLoader() {
GenericXmlContextLoader customLoader = new GenericXmlContextLoader() {
@Override
protected void customizeContext(GenericApplicationContext context) {
assertThat(context.isActive()).as("The context should not yet have been refreshed.").isFalse();
builder.append(expectedContents);
}
}.loadContext("classpath:/org/springframework/test/context/support/CustomizedGenericXmlContextLoaderTests-context.xml");
};
customLoader.loadContext("classpath:/org/springframework/test/context/support/CustomizedGenericXmlContextLoaderTests-context.xml");
assertThat(builder.toString()).as("customizeContext() should have been called.").isEqualTo(expectedContents);
assertThat(builder).asString().as("customizeContext() should have been called.").isEqualTo(expectedContents);
}
}

View File

@@ -57,6 +57,7 @@ class GenericXmlContextLoaderResourceLocationsTests {
ContextConfiguration contextConfig = testClass.getAnnotation(ContextConfiguration.class);
ContextLoader contextLoader = new GenericXmlContextLoader();
String[] configuredLocations = (String[]) AnnotationUtils.getValue(contextConfig);
@SuppressWarnings("deprecation")
String[] processedLocations = contextLoader.processLocations(testClass, configuredLocations);
if (logger.isDebugEnabled()) {