|
17 | 17 | package org.springframework.beans.factory.aot;
|
18 | 18 |
|
19 | 19 | import java.util.function.Consumer;
|
| 20 | +import java.util.stream.Stream; |
20 | 21 |
|
21 | 22 | import javax.lang.model.element.Modifier;
|
22 | 23 |
|
23 | 24 | import org.junit.jupiter.api.Test;
|
| 25 | +import org.junit.jupiter.params.ParameterizedTest; |
| 26 | +import org.junit.jupiter.params.provider.Arguments; |
| 27 | +import org.junit.jupiter.params.provider.MethodSource; |
24 | 28 |
|
25 | 29 | import org.springframework.aot.test.generate.TestGenerationContext;
|
| 30 | +import org.springframework.beans.testfixture.beans.GenericBean; |
26 | 31 | import org.springframework.beans.testfixture.beans.factory.aot.DeferredTypeBuilder;
|
27 | 32 | import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean;
|
28 | 33 | import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean;
|
| 34 | +import org.springframework.core.ResolvableType; |
29 | 35 | import org.springframework.core.test.tools.Compiled;
|
30 | 36 | import org.springframework.core.test.tools.TestCompiler;
|
31 | 37 | import org.springframework.javapoet.MethodSpec;
|
@@ -92,6 +98,40 @@ void detectDeprecationOnAnnotatedElementWithDeprecatedForRemoval() {
|
92 | 98 | assertThat(this.codeWarnings.getWarnings()).containsOnly("removal");
|
93 | 99 | }
|
94 | 100 |
|
| 101 | + @ParameterizedTest |
| 102 | + @MethodSource("resolvableTypesWithDeprecated") |
| 103 | + void detectDeprecationOnResolvableTypeWithDeprecated(ResolvableType resolvableType) { |
| 104 | + this.codeWarnings.detectDeprecation(resolvableType); |
| 105 | + assertThat(this.codeWarnings.getWarnings()).containsExactly("deprecation"); |
| 106 | + } |
| 107 | + |
| 108 | + @SuppressWarnings("deprecation") |
| 109 | + static Stream<Arguments> resolvableTypesWithDeprecated() { |
| 110 | + return Stream.of( |
| 111 | + Arguments.of(ResolvableType.forClass(DeprecatedBean.class)), |
| 112 | + Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedBean.class)), |
| 113 | + Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, |
| 114 | + ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedBean.class))) |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + @ParameterizedTest |
| 119 | + @MethodSource("resolvableTypesWithDeprecatedForRemoval") |
| 120 | + void detectDeprecationOnResolvableTypeWithDeprecatedForRemoval(ResolvableType resolvableType) { |
| 121 | + this.codeWarnings.detectDeprecation(resolvableType); |
| 122 | + assertThat(this.codeWarnings.getWarnings()).containsExactly("removal"); |
| 123 | + } |
| 124 | + |
| 125 | + @SuppressWarnings("removal") |
| 126 | + static Stream<Arguments> resolvableTypesWithDeprecatedForRemoval() { |
| 127 | + return Stream.of( |
| 128 | + Arguments.of(ResolvableType.forClass(DeprecatedForRemovalBean.class)), |
| 129 | + Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedForRemovalBean.class)), |
| 130 | + Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, |
| 131 | + ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedForRemovalBean.class))) |
| 132 | + ); |
| 133 | + } |
| 134 | + |
95 | 135 | @Test
|
96 | 136 | void toStringIncludesWarnings() {
|
97 | 137 | this.codeWarnings.register("deprecation");
|
|
0 commit comments