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

@@ -198,6 +198,7 @@ public class TestContextAotGenerator {
MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass) {
TestContextBootstrapper testContextBootstrapper =
BootstrapUtils.resolveTestContextBootstrapper(testClass);
registerDeclaredConstructors(testContextBootstrapper.getClass());
return testContextBootstrapper.buildMergedContextConfiguration();
}

View File

@@ -44,25 +44,12 @@ class TestContextRuntimeHints implements RuntimeHintsRegistrar {
ReflectionHints reflectionHints = runtimeHints.reflection();
// Loaded reflectively in BootstrapUtils
registerPublicConstructors(reflectionHints,
// Loaded reflectively in BootstrapUtils
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.class,
// Loaded reflectively in BootstrapUtils
org.springframework.test.context.support.DefaultBootstrapContext.class
);
registerDeclaredConstructors(reflectionHints,
// Loaded reflectively in BootstrapUtils
org.springframework.test.context.support.DefaultTestContextBootstrapper.class
);
if (servletPresent) {
registerDeclaredConstructors(reflectionHints,
// Loaded reflectively in BootstrapUtils
"org.springframework.test.context.web.WebTestContextBootstrapper"
);
}
if (groovyPresent) {
registerDeclaredConstructors(reflectionHints,
// Loaded reflectively in DelegatingSmartContextLoader
@@ -90,10 +77,6 @@ class TestContextRuntimeHints implements RuntimeHintsRegistrar {
reflectionHints.registerTypes(types, TypeHint.builtWith(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
}
private static void registerDeclaredConstructors(ReflectionHints reflectionHints, Class<?>... types) {
registerDeclaredConstructors(reflectionHints, TypeReference.listOf(types));
}
private static void registerDeclaredConstructors(ReflectionHints reflectionHints, String... classNames) {
registerDeclaredConstructors(reflectionHints, listOf(classNames));
}