|
19 | 19 | import java.lang.reflect.Constructor;
|
20 | 20 | import java.util.Arrays;
|
21 | 21 | import java.util.Collections;
|
| 22 | +import java.util.HashMap; |
22 | 23 | import java.util.List;
|
23 | 24 | import java.util.Map;
|
24 | 25 | import java.util.function.Consumer;
|
|
34 | 35 | import org.springframework.aot.hint.RuntimeHints;
|
35 | 36 | import org.springframework.aot.hint.TypeHint;
|
36 | 37 | import org.springframework.aot.hint.TypeReference;
|
| 38 | +import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; |
37 | 39 | import org.springframework.beans.factory.aot.AotFactoriesLoader;
|
38 | 40 | import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
|
39 | 41 | import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
|
|
53 | 55 | * Tests for {@link ConfigurationPropertiesBeanFactoryInitializationAotProcessor}.
|
54 | 56 | *
|
55 | 57 | * @author Stephane Nicoll
|
| 58 | + * @author Moritz Halbritter |
56 | 59 | */
|
57 | 60 | class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
|
58 | 61 |
|
@@ -227,6 +230,31 @@ void processConfigurationPropertiesWithUnresolvedGeneric() {
|
227 | 230 | .anySatisfy(javaBeanBinding(GenericObject.class));
|
228 | 231 | }
|
229 | 232 |
|
| 233 | + @Test |
| 234 | + void processConfigurationPropertiesWithNestedGenerics() { |
| 235 | + RuntimeHints runtimeHints = process(NestedGenerics.class); |
| 236 | + assertThat(RuntimeHintsPredicates.reflection().onType(NestedGenerics.class) |
| 237 | + .withMemberCategories(MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS)) |
| 238 | + .accepts(runtimeHints); |
| 239 | + assertThat(RuntimeHintsPredicates.reflection().onType(NestedGenerics.Nested.class) |
| 240 | + .withMemberCategories(MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS)) |
| 241 | + .accepts(runtimeHints); |
| 242 | + } |
| 243 | + |
| 244 | + @Test |
| 245 | + void processConfigurationPropertiesWithMultipleNestedClasses() { |
| 246 | + RuntimeHints runtimeHints = process(TripleNested.class); |
| 247 | + assertThat(RuntimeHintsPredicates.reflection().onType(TripleNested.class) |
| 248 | + .withMemberCategories(MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS)) |
| 249 | + .accepts(runtimeHints); |
| 250 | + assertThat(RuntimeHintsPredicates.reflection().onType(TripleNested.DoubleNested.class) |
| 251 | + .withMemberCategories(MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS)) |
| 252 | + .accepts(runtimeHints); |
| 253 | + assertThat(RuntimeHintsPredicates.reflection().onType(TripleNested.DoubleNested.Nested.class) |
| 254 | + .withMemberCategories(MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS)) |
| 255 | + .accepts(runtimeHints); |
| 256 | + } |
| 257 | + |
230 | 258 | private Consumer<TypeHint> javaBeanBinding(Class<?> type) {
|
231 | 259 | return javaBeanBinding(type, type.getDeclaredConstructors()[0]);
|
232 | 260 | }
|
@@ -590,4 +618,64 @@ public T getValue() {
|
590 | 618 |
|
591 | 619 | }
|
592 | 620 |
|
| 621 | + @ConfigurationProperties(prefix = "nested-generics") |
| 622 | + public static class NestedGenerics { |
| 623 | + |
| 624 | + private final Map<String, List<Nested>> nested = new HashMap<>(); |
| 625 | + |
| 626 | + public Map<String, List<Nested>> getNested() { |
| 627 | + return this.nested; |
| 628 | + } |
| 629 | + |
| 630 | + public static class Nested { |
| 631 | + |
| 632 | + private String field; |
| 633 | + |
| 634 | + public String getField() { |
| 635 | + return this.field; |
| 636 | + } |
| 637 | + |
| 638 | + public void setField(String field) { |
| 639 | + this.field = field; |
| 640 | + } |
| 641 | + |
| 642 | + } |
| 643 | + |
| 644 | + } |
| 645 | + |
| 646 | + @ConfigurationProperties(prefix = "triple-nested") |
| 647 | + public static class TripleNested { |
| 648 | + |
| 649 | + private final DoubleNested doubleNested = new DoubleNested(); |
| 650 | + |
| 651 | + public DoubleNested getDoubleNested() { |
| 652 | + return this.doubleNested; |
| 653 | + } |
| 654 | + |
| 655 | + public static class DoubleNested { |
| 656 | + |
| 657 | + private final Nested nested = new Nested(); |
| 658 | + |
| 659 | + public Nested getNested() { |
| 660 | + return this.nested; |
| 661 | + } |
| 662 | + |
| 663 | + public static class Nested { |
| 664 | + |
| 665 | + private String field; |
| 666 | + |
| 667 | + public String getField() { |
| 668 | + return this.field; |
| 669 | + } |
| 670 | + |
| 671 | + public void setField(String field) { |
| 672 | + this.field = field; |
| 673 | + } |
| 674 | + |
| 675 | + } |
| 676 | + |
| 677 | + } |
| 678 | + |
| 679 | + } |
| 680 | + |
593 | 681 | }
|
0 commit comments