|
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;
|
@@ -98,6 +104,40 @@ void detectDeprecationOnAnnotatedElementWithDeprecatedForRemoval() {
|
98 | 104 | assertThat(this.codeWarnings.getWarnings()).containsExactly("removal");
|
99 | 105 | }
|
100 | 106 |
|
| 107 | + @ParameterizedTest |
| 108 | + @MethodSource("resolvableTypesWithDeprecated") |
| 109 | + void detectDeprecationOnResolvableTypeWithDeprecated(ResolvableType resolvableType) { |
| 110 | + this.codeWarnings.detectDeprecation(resolvableType); |
| 111 | + assertThat(this.codeWarnings.getWarnings()).containsExactly("deprecation"); |
| 112 | + } |
| 113 | + |
| 114 | + @SuppressWarnings("deprecation") |
| 115 | + static Stream<Arguments> resolvableTypesWithDeprecated() { |
| 116 | + return Stream.of( |
| 117 | + Arguments.of(ResolvableType.forClass(DeprecatedBean.class)), |
| 118 | + Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedBean.class)), |
| 119 | + Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, |
| 120 | + ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedBean.class))) |
| 121 | + ); |
| 122 | + } |
| 123 | + |
| 124 | + @ParameterizedTest |
| 125 | + @MethodSource("resolvableTypesWithDeprecatedForRemoval") |
| 126 | + void detectDeprecationOnResolvableTypeWithDeprecatedForRemoval(ResolvableType resolvableType) { |
| 127 | + this.codeWarnings.detectDeprecation(resolvableType); |
| 128 | + assertThat(this.codeWarnings.getWarnings()).containsExactly("removal"); |
| 129 | + } |
| 130 | + |
| 131 | + @SuppressWarnings("removal") |
| 132 | + static Stream<Arguments> resolvableTypesWithDeprecatedForRemoval() { |
| 133 | + return Stream.of( |
| 134 | + Arguments.of(ResolvableType.forClass(DeprecatedForRemovalBean.class)), |
| 135 | + Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedForRemovalBean.class)), |
| 136 | + Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, |
| 137 | + ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedForRemovalBean.class))) |
| 138 | + ); |
| 139 | + } |
| 140 | + |
101 | 141 | @Test
|
102 | 142 | void toStringIncludeWarnings() {
|
103 | 143 | this.codeWarnings.register("deprecation");
|
|
0 commit comments