Rename AotTestMappings to TestAotMappings
This provides consistency with other classes in the aot package, leaving only extended core interfaces starting with the `Aot` prefix.
This commit is contained in:
@@ -28,7 +28,7 @@ import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* {@code AotTestMappings} provides mappings from test classes to AOT-optimized
|
||||
* {@code TestAotMappings} provides mappings from test classes to AOT-optimized
|
||||
* context initializers.
|
||||
*
|
||||
* <p>If a test class is not {@linkplain #isSupportedTestClass(Class) supported} in
|
||||
@@ -42,27 +42,27 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Stephane Nicoll
|
||||
* @since 6.0
|
||||
*/
|
||||
public class AotTestMappings {
|
||||
public class TestAotMappings {
|
||||
|
||||
// TODO Add support in ClassNameGenerator for supplying a predefined class name.
|
||||
// There is a similar issue in Spring Boot where code relies on a generated name.
|
||||
// Ideally we would generate a class named: org.springframework.test.context.aot.GeneratedAotTestMappings
|
||||
static final String GENERATED_MAPPINGS_CLASS_NAME = AotTestMappings.class.getName() + "__Generated";
|
||||
// Ideally we would generate a class named: org.springframework.test.context.aot.GeneratedTestAotMappings
|
||||
static final String GENERATED_MAPPINGS_CLASS_NAME = TestAotMappings.class.getName() + "__Generated";
|
||||
|
||||
static final String GENERATED_MAPPINGS_METHOD_NAME = "getContextInitializers";
|
||||
|
||||
private final Map<String, Supplier<ApplicationContextInitializer<ConfigurableApplicationContext>>> contextInitializers;
|
||||
|
||||
|
||||
public AotTestMappings() {
|
||||
public TestAotMappings() {
|
||||
this(GENERATED_MAPPINGS_CLASS_NAME);
|
||||
}
|
||||
|
||||
AotTestMappings(String initializerClassName) {
|
||||
TestAotMappings(String initializerClassName) {
|
||||
this(loadContextInitializersMap(initializerClassName));
|
||||
}
|
||||
|
||||
AotTestMappings(Map<String, Supplier<ApplicationContextInitializer<ConfigurableApplicationContext>>> contextInitializers) {
|
||||
TestAotMappings(Map<String, Supplier<ApplicationContextInitializer<ConfigurableApplicationContext>>> contextInitializers) {
|
||||
this.contextInitializers = contextInitializers;
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ import org.springframework.javapoet.WildcardTypeName;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* Internal code generator for mappings used by {@link AotTestMappings}.
|
||||
* Internal code generator for mappings used by {@link TestAotMappings}.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.0
|
||||
*/
|
||||
class AotTestMappingsCodeGenerator {
|
||||
class TestAotMappingsCodeGenerator {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AotTestMappingsCodeGenerator.class);
|
||||
private static final Log logger = LogFactory.getLog(TestAotMappingsCodeGenerator.class);
|
||||
|
||||
private static final ParameterizedTypeName CONTEXT_INITIALIZER = ParameterizedTypeName.get(
|
||||
ClassName.get(ApplicationContextInitializer.class),
|
||||
@@ -67,7 +67,7 @@ class AotTestMappingsCodeGenerator {
|
||||
private final GeneratedClass generatedClass;
|
||||
|
||||
|
||||
AotTestMappingsCodeGenerator(MultiValueMap<ClassName, Class<?>> initializerClassMappings,
|
||||
TestAotMappingsCodeGenerator(MultiValueMap<ClassName, Class<?>> initializerClassMappings,
|
||||
GeneratedClasses generatedClasses) {
|
||||
|
||||
this.initializerClassMappings = initializerClassMappings;
|
||||
@@ -82,13 +82,13 @@ class AotTestMappingsCodeGenerator {
|
||||
private void generateType(TypeSpec.Builder type) {
|
||||
logger.debug(LogMessage.format("Generating AOT test mappings in %s",
|
||||
this.generatedClass.getName().reflectionName()));
|
||||
type.addJavadoc("Generated mappings for {@link $T}.", AotTestMappings.class);
|
||||
type.addJavadoc("Generated mappings for {@link $T}.", TestAotMappings.class);
|
||||
type.addModifiers(Modifier.PUBLIC);
|
||||
type.addMethod(generateMappingMethod());
|
||||
}
|
||||
|
||||
private MethodSpec generateMappingMethod() {
|
||||
MethodSpec.Builder method = MethodSpec.methodBuilder(AotTestMappings.GENERATED_MAPPINGS_METHOD_NAME);
|
||||
MethodSpec.Builder method = MethodSpec.methodBuilder(TestAotMappings.GENERATED_MAPPINGS_METHOD_NAME);
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
method.returns(CONTEXT_SUPPLIER_MAP);
|
||||
method.addCode(generateMappingCode());
|
||||
@@ -138,7 +138,7 @@ public class TestContextAotGenerator {
|
||||
}
|
||||
});
|
||||
|
||||
generateAotTestMappings(initializerClassMappings);
|
||||
generateTestAotMappings(initializerClassMappings);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,14 +230,14 @@ public class TestContextAotGenerator {
|
||||
return "TestContext%03d_".formatted(this.sequence.incrementAndGet());
|
||||
}
|
||||
|
||||
private void generateAotTestMappings(MultiValueMap<ClassName, Class<?>> initializerClassMappings) {
|
||||
ClassNameGenerator classNameGenerator = new ClassNameGenerator(AotTestMappings.class);
|
||||
private void generateTestAotMappings(MultiValueMap<ClassName, Class<?>> initializerClassMappings) {
|
||||
ClassNameGenerator classNameGenerator = new ClassNameGenerator(TestAotMappings.class);
|
||||
DefaultGenerationContext generationContext =
|
||||
new DefaultGenerationContext(classNameGenerator, this.generatedFiles, this.runtimeHints);
|
||||
GeneratedClasses generatedClasses = generationContext.getGeneratedClasses();
|
||||
|
||||
AotTestMappingsCodeGenerator codeGenerator =
|
||||
new AotTestMappingsCodeGenerator(initializerClassMappings, generatedClasses);
|
||||
TestAotMappingsCodeGenerator codeGenerator =
|
||||
new TestAotMappingsCodeGenerator(initializerClassMappings, generatedClasses);
|
||||
generationContext.writeGeneratedContent();
|
||||
String className = codeGenerator.getGeneratedClass().getName().reflectionName();
|
||||
this.runtimeHints.reflection()
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.test.context.ContextLoader;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.test.context.SmartContextLoader;
|
||||
import org.springframework.test.context.aot.AotContextLoader;
|
||||
import org.springframework.test.context.aot.AotTestMappings;
|
||||
import org.springframework.test.context.aot.TestAotMappings;
|
||||
import org.springframework.test.context.aot.TestContextAotException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
|
||||
static final ContextCache defaultContextCache = new DefaultContextCache();
|
||||
|
||||
@Nullable
|
||||
private final AotTestMappings aotTestMappings = getAotTestMappings();
|
||||
private final TestAotMappings testAotMappings = getTestAotMappings();
|
||||
|
||||
private final ContextCache contextCache;
|
||||
|
||||
@@ -168,7 +168,7 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
|
||||
protected ApplicationContext loadContextInAotMode(MergedContextConfiguration mergedConfig) throws Exception {
|
||||
Class<?> testClass = mergedConfig.getTestClass();
|
||||
ApplicationContextInitializer<ConfigurableApplicationContext> contextInitializer =
|
||||
this.aotTestMappings.getContextInitializer(testClass);
|
||||
this.testAotMappings.getContextInitializer(testClass);
|
||||
Assert.state(contextInitializer != null,
|
||||
() -> "Failed to load AOT ApplicationContextInitializer for test class [%s]"
|
||||
.formatted(testClass.getName()));
|
||||
@@ -200,17 +200,17 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
|
||||
* Determine if we are running in AOT mode for the supplied test class.
|
||||
*/
|
||||
private boolean runningInAotMode(Class<?> testClass) {
|
||||
return (this.aotTestMappings != null && this.aotTestMappings.isSupportedTestClass(testClass));
|
||||
return (this.testAotMappings != null && this.testAotMappings.isSupportedTestClass(testClass));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AotTestMappings getAotTestMappings() {
|
||||
private static TestAotMappings getTestAotMappings() {
|
||||
if (AotDetector.useGeneratedArtifacts()) {
|
||||
try {
|
||||
return new AotTestMappings();
|
||||
return new TestAotMappings();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to instantiate AotTestMappings", ex);
|
||||
throw new IllegalStateException("Failed to instantiate TestAotMappings", ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.Conventions;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.aot.AotTestMappings;
|
||||
import org.springframework.test.context.aot.TestAotMappings;
|
||||
|
||||
/**
|
||||
* {@code TestExecutionListener} which provides support for dependency
|
||||
@@ -61,7 +61,7 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
|
||||
private static final Log logger = LogFactory.getLog(DependencyInjectionTestExecutionListener.class);
|
||||
|
||||
@Nullable
|
||||
private final AotTestMappings aotTestMappings = getAotTestMappings();
|
||||
private final TestAotMappings testAotMappings = getTestAotMappings();
|
||||
|
||||
|
||||
/**
|
||||
@@ -162,17 +162,17 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
|
||||
* Determine if we are running in AOT mode for the supplied test class.
|
||||
*/
|
||||
private boolean runningInAotMode(Class<?> testClass) {
|
||||
return (this.aotTestMappings != null && this.aotTestMappings.isSupportedTestClass(testClass));
|
||||
return (this.testAotMappings != null && this.testAotMappings.isSupportedTestClass(testClass));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AotTestMappings getAotTestMappings() {
|
||||
private static TestAotMappings getTestAotMappings() {
|
||||
if (AotDetector.useGeneratedArtifacts()) {
|
||||
try {
|
||||
return new AotTestMappings();
|
||||
return new TestAotMappings();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to instantiate AotTestMappings", ex);
|
||||
throw new IllegalStateException("Failed to instantiate TestAotMappings", ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user