From cced3cba0925b3c5e4f1754a514595511fa15004 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 2 Sep 2022 14:52:58 +0200 Subject: [PATCH] Register runtime hints for @TestExecutionListeners Closes gh-29024 --- .../test/context/aot/TestContextAotGenerator.java | 3 +++ .../context/aot/TestContextAotGeneratorTests.java | 1 + .../aot/samples/basic/BasicSpringJupiterTests.java | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) 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 ca1c856c7837..38f18d952dd6 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 @@ -199,6 +199,9 @@ MergedContextConfiguration buildMergedContextConfiguration(Class testClass) { TestContextBootstrapper testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(testClass); registerDeclaredConstructors(testContextBootstrapper.getClass()); + testContextBootstrapper.getTestExecutionListeners().stream() + .map(Object::getClass) + .forEach(this::registerDeclaredConstructors); return testContextBootstrapper.buildMergedContextConfiguration(); } 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 9204976146a7..48072cac429d 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 @@ -141,6 +141,7 @@ private static void assertRuntimeHints(RuntimeHints runtimeHints) { // TestExecutionListener Stream.of( + org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener.class, org.springframework.test.context.event.ApplicationEventsTestExecutionListener.class, org.springframework.test.context.event.EventPublishingTestExecutionListener.class, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.class, diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java index 786a70797f70..9d27c1f89d8d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java @@ -23,11 +23,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; +import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyExtension; +import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener; import org.springframework.test.context.aot.samples.common.MessageService; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import org.springframework.test.context.support.AbstractTestExecutionListener; import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS; /** * @author Sam Brannen @@ -37,6 +42,7 @@ // for repeated annotations. @ExtendWith(DummyExtension.class) @SpringJUnitConfig(BasicTestConfiguration.class) +@TestExecutionListeners(listeners = DummyTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS) @TestPropertySource(properties = "test.engine = jupiter") public class BasicSpringJupiterTests { @@ -65,7 +71,11 @@ void test(@Autowired ApplicationContext context, @Autowired MessageService messa } -} + static class DummyExtension implements Extension { + } + + public static class DummyTestExecutionListener extends AbstractTestExecutionListener { + } -class DummyExtension implements Extension { } +