diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java index f64a9adb2c..4d0f946775 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java @@ -28,7 +28,6 @@ import org.springframework.aot.generate.DefaultGenerationContext; import org.springframework.aot.generate.GeneratedClasses; import org.springframework.aot.generate.GeneratedFiles; import org.springframework.aot.generate.GenerationContext; -import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeReference; import org.springframework.beans.factory.aot.AotServices; @@ -111,10 +110,11 @@ public class TestContextAotGenerator { public void processAheadOfTime(Stream> testClasses) throws TestContextAotException { MultiValueMap> mergedConfigMappings = new LinkedMultiValueMap<>(); testClasses.forEach(testClass -> mergedConfigMappings.add(buildMergedContextConfiguration(testClass), testClass)); - processAheadOfTime(mergedConfigMappings); + MultiValueMap> initializerClassMappings = processAheadOfTime(mergedConfigMappings); + generateTestAotMappings(initializerClassMappings); } - private void processAheadOfTime(MultiValueMap> mergedConfigMappings) { + private MultiValueMap> processAheadOfTime(MultiValueMap> mergedConfigMappings) { MultiValueMap> initializerClassMappings = new LinkedMultiValueMap<>(); mergedConfigMappings.forEach((mergedConfig, testClasses) -> { logger.debug(LogMessage.format("Generating AOT artifacts for test classes %s", @@ -137,8 +137,7 @@ public class TestContextAotGenerator { testClasses.stream().map(Class::getName).toList()), ex); } }); - - generateTestAotMappings(initializerClassMappings); + return initializerClassMappings; } /** @@ -207,11 +206,9 @@ public class TestContextAotGenerator { private MergedContextConfiguration buildMergedContextConfiguration(Class testClass) { TestContextBootstrapper testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(testClass); - // @BootstrapWith - registerDeclaredConstructors(testContextBootstrapper.getClass()); - // @TestExecutionListeners + registerDeclaredConstructors(testContextBootstrapper.getClass()); // @BootstrapWith testContextBootstrapper.getTestExecutionListeners().forEach(listener -> { - registerDeclaredConstructors(listener.getClass()); + registerDeclaredConstructors(listener.getClass()); // @TestExecutionListeners if (listener instanceof AotTestExecutionListener aotListener) { aotListener.processAheadOfTime(testClass, this.runtimeHints, getClass().getClassLoader()); } @@ -240,13 +237,15 @@ public class TestContextAotGenerator { new TestAotMappingsCodeGenerator(initializerClassMappings, generatedClasses); generationContext.writeGeneratedContent(); String className = codeGenerator.getGeneratedClass().getName().reflectionName(); - this.runtimeHints.reflection() - .registerType(TypeReference.of(className), INVOKE_PUBLIC_METHODS); + registerPublicMethods(className); + } + + private void registerPublicMethods(String className) { + this.runtimeHints.reflection().registerType(TypeReference.of(className), INVOKE_PUBLIC_METHODS); } private void registerDeclaredConstructors(Class type) { - ReflectionHints reflectionHints = this.runtimeHints.reflection(); - reflectionHints.registerType(type, INVOKE_DECLARED_CONSTRUCTORS); + this.runtimeHints.reflection().registerType(type, INVOKE_DECLARED_CONSTRUCTORS); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java index 4a2213030e..faec46178c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java @@ -82,10 +82,12 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC class TestContextAotGeneratorTests extends AbstractAotTests { /** - * @see AotIntegrationTests#endToEndTests() + * End-to-end tests within the scope of the {@link TestContextAotGenerator}. + * + * @see AotIntegrationTests */ @Test - void processAheadOfTimeAndGenerateTestAotMappings() { + void endToEndTests() { Set> testClasses = Set.of( BasicSpringJupiterSharedConfigTests.class, BasicSpringJupiterTests.class,