Register runtime hints for TestContextBootstrappers

This commit automatically registers runtime hints for
TestContextBootstrapper classes, including default bootstrappers as
well as any bootstrapper configured via @BootstrapWith.

Closes gh-29023
This commit is contained in:
Sam Brannen
2022-09-02 14:40:09 +02:00
parent 1cae054cf5
commit 34635d7751
4 changed files with 17 additions and 18 deletions

View File

@@ -124,6 +124,7 @@ 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,

View File

@@ -21,11 +21,16 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextLoader;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.aot.samples.basic.BasicSpringVintageTests.CustomXmlBootstrapper;
import org.springframework.test.context.aot.samples.common.MessageService;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.springframework.test.context.support.DefaultTestContextBootstrapper;
import org.springframework.test.context.support.GenericXmlContextLoader;
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,7 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Sam Brannen
* @since 6.0
*/
@BootstrapWith(CustomXmlBootstrapper.class)
@RunWith(SpringRunner.class)
// Override the default loader configured by the CustomXmlBootstrapper
@ContextConfiguration(classes = BasicTestConfiguration.class, loader = AnnotationConfigContextLoader.class)
@TestPropertySource(properties = "test.engine = vintage")
public class BasicSpringVintageTests {
@@ -55,4 +62,11 @@ public class BasicSpringVintageTests {
.as("@TestPropertySource").isEqualTo("vintage");
}
public static class CustomXmlBootstrapper extends DefaultTestContextBootstrapper {
@Override
protected Class<? extends ContextLoader> getDefaultContextLoaderClass(Class<?> testClass) {
return GenericXmlContextLoader.class;
}
}
}