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 38f18d952d..244d20a2d6 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 @@ -27,7 +27,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.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeReference; @@ -46,6 +45,8 @@ import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import static org.springframework.aot.hint.MemberCategory.INVOKE_DECLARED_CONSTRUCTORS; +import static org.springframework.aot.hint.MemberCategory.INVOKE_PUBLIC_METHODS; /** * {@code TestContextAotGenerator} generates AOT artifacts for integration tests * that depend on support from the Spring TestContext Framework. @@ -198,7 +199,9 @@ public class TestContextAotGenerator { MergedContextConfiguration buildMergedContextConfiguration(Class testClass) { TestContextBootstrapper testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(testClass); + // @BootstrapWith registerDeclaredConstructors(testContextBootstrapper.getClass()); + // @TestExecutionListeners testContextBootstrapper.getTestExecutionListeners().stream() .map(Object::getClass) .forEach(this::registerDeclaredConstructors); @@ -227,20 +230,23 @@ public class TestContextAotGenerator { generationContext.writeGeneratedContent(); String className = codeGenerator.getGeneratedClass().getName().reflectionName(); this.runtimeHints.reflection() - .registerType(TypeReference.of(className), MemberCategory.INVOKE_PUBLIC_METHODS); + .registerType(TypeReference.of(className), INVOKE_PUBLIC_METHODS); } private void registerHintsForMergedConfig(MergedContextConfiguration mergedConfig) { + // @ContextConfiguration(loader = ...) ContextLoader contextLoader = mergedConfig.getContextLoader(); if (contextLoader != null) { registerDeclaredConstructors(contextLoader.getClass()); } + + // @ContextConfiguration(initializers = ...) mergedConfig.getContextInitializerClasses().forEach(this::registerDeclaredConstructors); } private void registerDeclaredConstructors(Class type) { ReflectionHints reflectionHints = this.runtimeHints.reflection(); - reflectionHints.registerType(type, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); + reflectionHints.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 c146d294a8..a2eb7c1ef7 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 @@ -125,9 +125,6 @@ class TestContextAotGeneratorTests extends AbstractAotTests { ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_PUBLIC_CONSTRUCTORS)); Stream.of( - org.springframework.test.context.aot.samples.basic.BasicSpringVintageTests.CustomXmlBootstrapper.class, - org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests.CustomInitializer.class, - org.springframework.test.context.support.AnnotationConfigContextLoader.class, org.springframework.test.context.support.DefaultTestContextBootstrapper.class, org.springframework.test.context.support.DelegatingSmartContextLoader.class, org.springframework.test.context.support.GenericGroovyXmlContextLoader.class, @@ -142,6 +139,7 @@ class TestContextAotGeneratorTests extends AbstractAotTests { // TestExecutionListener Stream.of( + // @TestExecutionListeners org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener.class, org.springframework.test.context.event.ApplicationEventsTestExecutionListener.class, org.springframework.test.context.event.EventPublishingTestExecutionListener.class, @@ -158,6 +156,15 @@ class TestContextAotGeneratorTests extends AbstractAotTests { "org.springframework.test.context.support.DynamicPropertiesContextCustomizerFactory", "org.springframework.test.context.web.socket.MockServerContainerContextCustomizerFactory" ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); + + Stream.of( + // @BootstrapWith + org.springframework.test.context.aot.samples.basic.BasicSpringVintageTests.CustomXmlBootstrapper.class, + // @ContextConfiguration(initializers=...) + org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests.CustomInitializer.class, + // @ContextConfiguration(loader=...) + org.springframework.test.context.support.AnnotationConfigContextLoader.class + ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); } private static void assertReflectionRegistered(RuntimeHints runtimeHints, String type, MemberCategory memberCategory) {