Add shortcut method to register multiple types hints

Closes gh-28339
This commit is contained in:
Stephane Nicoll
2022-04-14 10:22:07 +02:00
parent 780d07217b
commit 5be6b3d2a7
2 changed files with 28 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.aot.hint;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.function.Consumer;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
@@ -87,6 +88,20 @@ class ReflectionHintsTests {
typeWithMemberCategories(Integer.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
}
@Test
void registerTypesApplyTheSameHints() {
this.reflectionHints.registerTypes(Stream.of(Integer.class, String.class, Double.class)
.map(TypeReference::of).toList(), hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
assertThat(this.reflectionHints.typeHints())
.anySatisfy(
typeWithMemberCategories(Integer.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
.anySatisfy(
typeWithMemberCategories(String.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
.anySatisfy(
typeWithMemberCategories(Double.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
.hasSize(3);
}
@Test
void registerField() {
Field field = ReflectionUtils.findField(TestType.class, "field");