Add RuntimeHints predicates generator

The `RuntimeHints` API allows to describe hints for the reflection,
proxies and resources behavior at runtime. The need for a particular
behavior can be covered by several types of hints, at different levels.
This knowledge can be important in several cases:

* before contributing additional hints, infrastructure can check if an
  existing hint already covers the behavior
* this can be used in test suites and test infrastructure

This commit adds a new RuntimeHintsPredicates that generates `Predicate`
instances for testing `RuntimeHints` against a desired runtime behavior
for reflection, resources or proxies.

Closes gh-28555
This commit is contained in:
Brian Clozel
2022-06-10 17:04:54 +02:00
parent 100ce9642a
commit 9c9b2356ce
13 changed files with 1318 additions and 55 deletions

View File

@@ -28,8 +28,8 @@ import javax.lang.model.element.Modifier;
import org.junit.jupiter.api.Test;
import org.springframework.aot.generate.GeneratedMethods;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsPredicates;
import org.springframework.aot.test.generator.compile.Compiled;
import org.springframework.aot.test.generator.compile.TestCompiler;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -277,15 +277,8 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
}
private void assertHasMethodInvokeHints(Class<?> beanType, String... methodNames) {
assertThat(this.hints.reflection().getTypeHint(beanType)).satisfies(typeHint -> {
for (String methodName : methodNames) {
assertThat(typeHint.methods()).anySatisfy(methodHint -> {
assertThat(methodHint.getName()).isEqualTo(methodName);
assertThat(methodHint.getModes())
.containsExactly(ExecutableMode.INVOKE);
});
}
});
assertThat(methodNames).allMatch(methodName ->
RuntimeHintsPredicates.reflection().onMethod(beanType, methodName).invoke().test(this.hints));
}
@Test