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:
Sam Brannen
2022-09-08 13:04:29 +02:00
parent d46a816745
commit f5bc182ba7
8 changed files with 38 additions and 38 deletions

View File

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

View File

@@ -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());

View File

@@ -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()

View File

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

View File

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

View File

@@ -31,7 +31,7 @@ abstract class AbstractAotTests {
static final String[] expectedSourceFilesForBasicSpringTests = {
// Global
"org/springframework/test/context/aot/AotTestMappings__Generated.java",
"org/springframework/test/context/aot/TestAotMappings__Generated.java",
// BasicSpringJupiterSharedConfigTests
"org/springframework/context/event/DefaultEventListenerFactory__TestContext001_BeanDefinitions.java",
"org/springframework/context/event/EventListenerMethodProcessor__TestContext001_BeanDefinitions.java",

View File

@@ -130,7 +130,7 @@ class AotIntegrationTests extends AbstractAotTests {
private static final String[] expectedSourceFilesForBasicSpringJupiterTests = {
// Global
"org/springframework/test/context/aot/AotTestMappings__Generated.java",
"org/springframework/test/context/aot/TestAotMappings__Generated.java",
// BasicSpringJupiterSharedConfigTests
"org/springframework/context/event/DefaultEventListenerFactory__TestContext001_BeanDefinitions.java",
"org/springframework/context/event/EventListenerMethodProcessor__TestContext001_BeanDefinitions.java",

View File

@@ -72,7 +72,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
/**
* Tests for {@link TestContextAotGenerator}, {@link AotTestMappings},
* Tests for {@link TestContextAotGenerator}, {@link TestAotMappings},
* {@link AotContextLoader}, and run-time hints.
*
* @author Sam Brannen
@@ -85,7 +85,7 @@ class TestContextAotGeneratorTests extends AbstractAotTests {
* @see AotIntegrationTests#endToEndTests()
*/
@Test
void processAheadOfTimeAndGenerateAotTestMappings() {
void processAheadOfTimeAndGenerateTestAotMappings() {
Set<Class<?>> testClasses = Set.of(
BasicSpringJupiterSharedConfigTests.class,
BasicSpringJupiterTests.class,
@@ -107,7 +107,7 @@ class TestContextAotGeneratorTests extends AbstractAotTests {
assertThat(sourceFiles).containsExactlyInAnyOrder(expectedSourceFiles);
TestCompiler.forSystem().withFiles(generatedFiles).compile(ThrowingConsumer.of(compiled -> {
AotTestMappings aotTestMappings = new AotTestMappings();
TestAotMappings aotTestMappings = new TestAotMappings();
for (Class<?> testClass : testClasses) {
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);
ApplicationContextInitializer<ConfigurableApplicationContext> contextInitializer =
@@ -129,7 +129,7 @@ class TestContextAotGeneratorTests extends AbstractAotTests {
}
private static void assertRuntimeHints(RuntimeHints runtimeHints) {
assertReflectionRegistered(runtimeHints, AotTestMappings.GENERATED_MAPPINGS_CLASS_NAME, INVOKE_PUBLIC_METHODS);
assertReflectionRegistered(runtimeHints, TestAotMappings.GENERATED_MAPPINGS_CLASS_NAME, INVOKE_PUBLIC_METHODS);
Stream.of(
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.class,
@@ -331,7 +331,7 @@ class TestContextAotGeneratorTests extends AbstractAotTests {
private static final String[] expectedSourceFiles = {
// Global
"org/springframework/test/context/aot/AotTestMappings__Generated.java",
"org/springframework/test/context/aot/TestAotMappings__Generated.java",
// BasicSpringJupiterSharedConfigTests
"org/springframework/context/event/DefaultEventListenerFactory__TestContext001_BeanDefinitions.java",
"org/springframework/context/event/EventListenerMethodProcessor__TestContext001_BeanDefinitions.java",