Skip to content

Commit

Permalink
Register runtime hints for @TestExecutionListeners
Browse files Browse the repository at this point in the history
Closes gh-29024
  • Loading branch information
sbrannen committed Sep 2, 2022
1 parent 34635d7 commit cced3cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -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 {
}

0 comments on commit cced3cb

Please sign in to comment.