Restore imports for deprecated types in tests
This commit is contained in:
parent
1e7fc6035d
commit
a4fe57a9e2
|
@ -53,6 +53,7 @@ import org.springframework.beans.testfixture.beans.factory.aot.TestHierarchy;
|
|||
import org.springframework.beans.testfixture.beans.factory.aot.TestHierarchy.Implementation;
|
||||
import org.springframework.beans.testfixture.beans.factory.aot.TestHierarchy.One;
|
||||
import org.springframework.beans.testfixture.beans.factory.aot.TestHierarchy.Two;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.test.io.support.MockSpringFactoriesLoader;
|
||||
import org.springframework.core.test.tools.CompileWithForkedClassLoader;
|
||||
|
@ -751,8 +752,7 @@ class BeanDefinitionMethodGeneratorTests {
|
|||
|
||||
@Test
|
||||
void generateBeanDefinitionMethodWithDeprecatedTargetClass() {
|
||||
Class<?> beanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(DeprecatedBean.class);
|
||||
RegisteredBean registeredBean = registerBean(beanDefinition);
|
||||
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(
|
||||
methodGeneratorFactory, registeredBean, null,
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import org.springframework.aot.test.generate.TestGenerationContext;
|
||||
import org.springframework.beans.testfixture.beans.factory.aot.DeferredTypeBuilder;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean;
|
||||
import org.springframework.core.test.tools.Compiled;
|
||||
import org.springframework.core.test.tools.TestCompiler;
|
||||
import org.springframework.javapoet.MethodSpec;
|
||||
|
@ -61,11 +63,10 @@ class CodeWarningsTests {
|
|||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void registerWarningSuppressesIt() {
|
||||
Class<?> deprecatedBeanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
this.codeWarnings.register("deprecation");
|
||||
compile(method -> {
|
||||
this.codeWarnings.suppress(method);
|
||||
method.addStatement("$T bean = new $T()", deprecatedBeanClass, deprecatedBeanClass);
|
||||
method.addStatement("$T bean = new $T()", DeprecatedBean.class, DeprecatedBean.class);
|
||||
}, compiled -> assertThat(compiled.getSourceFile())
|
||||
.contains("@SuppressWarnings(\"deprecation\")"));
|
||||
}
|
||||
|
@ -73,14 +74,12 @@ class CodeWarningsTests {
|
|||
@Test
|
||||
@SuppressWarnings({ "deprecation", "removal" })
|
||||
void registerSeveralWarningsSuppressesThem() {
|
||||
Class<?> deprecatedBeanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
Class<?> deprecatedForRemovalBeanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean.class;
|
||||
this.codeWarnings.register("deprecation");
|
||||
this.codeWarnings.register("removal");
|
||||
compile(method -> {
|
||||
this.codeWarnings.suppress(method);
|
||||
method.addStatement("$T bean = new $T()", deprecatedBeanClass, deprecatedBeanClass);
|
||||
method.addStatement("$T another = new $T()", deprecatedForRemovalBeanClass, deprecatedForRemovalBeanClass);
|
||||
method.addStatement("$T bean = new $T()", DeprecatedBean.class, DeprecatedBean.class);
|
||||
method.addStatement("$T another = new $T()", DeprecatedForRemovalBean.class, DeprecatedForRemovalBean.class);
|
||||
}, compiled -> assertThat(compiled.getSourceFile())
|
||||
.contains("@SuppressWarnings({ \"deprecation\", \"removal\" })"));
|
||||
}
|
||||
|
@ -88,16 +87,14 @@ class CodeWarningsTests {
|
|||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void detectDeprecationOnAnnotatedElementWithDeprecated() {
|
||||
Class<?> deprecatedBeanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
this.codeWarnings.detectDeprecation(deprecatedBeanClass);
|
||||
this.codeWarnings.detectDeprecation(DeprecatedBean.class);
|
||||
assertThat(this.codeWarnings.getWarnings()).containsExactly("deprecation");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
void detectDeprecationOnAnnotatedElementWithDeprecatedForRemoval() {
|
||||
Class<?> deprecatedForRemovalBeanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean.class;
|
||||
this.codeWarnings.detectDeprecation(deprecatedForRemovalBeanClass);
|
||||
this.codeWarnings.detectDeprecation(DeprecatedForRemovalBean.class);
|
||||
assertThat(this.codeWarnings.getWarnings()).containsExactly("removal");
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,9 @@ import org.springframework.beans.testfixture.beans.factory.generator.InnerCompon
|
|||
import org.springframework.beans.testfixture.beans.factory.generator.InnerComponentConfiguration.EnvironmentAwareComponent;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.InnerComponentConfiguration.NoDependencyComponent;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.SimpleConfiguration;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedConstructor;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalConstructor;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalMemberConfiguration;
|
||||
import org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedMemberConfiguration;
|
||||
|
@ -278,9 +280,7 @@ class InstanceSupplierCodeGeneratorTests {
|
|||
@Test
|
||||
@Disabled("Need to move to a separate method so that the warning can be suppressed")
|
||||
void generateWhenTargetClassIsDeprecated() {
|
||||
Class<?> deprecatedBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
compileAndCheckWarnings(new RootBeanDefinition(deprecatedBeanClass));
|
||||
compileAndCheckWarnings(new RootBeanDefinition(DeprecatedBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -305,18 +305,14 @@ class InstanceSupplierCodeGeneratorTests {
|
|||
.setFactoryMethodOnBean("deprecatedParameter", "config").getBeanDefinition();
|
||||
beanFactory.registerBeanDefinition("config", BeanDefinitionBuilder
|
||||
.genericBeanDefinition(DeprecatedMemberConfiguration.class).getBeanDefinition());
|
||||
Class<?> deprecatedBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
beanFactory.registerBeanDefinition("parameter", new RootBeanDefinition(deprecatedBeanClass));
|
||||
beanFactory.registerBeanDefinition("parameter", new RootBeanDefinition(DeprecatedBean.class));
|
||||
compileAndCheckWarnings(beanDefinition);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateWhenTargetFactoryMethodReturnTypeIsDeprecated() {
|
||||
Class<?> deprecatedBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
BeanDefinition beanDefinition = BeanDefinitionBuilder
|
||||
.rootBeanDefinition(deprecatedBeanClass)
|
||||
.rootBeanDefinition(DeprecatedBean.class)
|
||||
.setFactoryMethodOnBean("deprecatedReturnType", "config").getBeanDefinition();
|
||||
beanFactory.registerBeanDefinition("config", BeanDefinitionBuilder
|
||||
.genericBeanDefinition(DeprecatedMemberConfiguration.class).getBeanDefinition());
|
||||
|
@ -340,9 +336,7 @@ class InstanceSupplierCodeGeneratorTests {
|
|||
@Test
|
||||
@Disabled("Need to move to a separate method so that the warning can be suppressed")
|
||||
void generateWhenTargetClassIsDeprecatedForRemoval() {
|
||||
Class<?> deprecatedForRemovalBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean.class;
|
||||
compileAndCheckWarnings(new RootBeanDefinition(deprecatedForRemovalBeanClass));
|
||||
compileAndCheckWarnings(new RootBeanDefinition(DeprecatedForRemovalBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -367,9 +361,7 @@ class InstanceSupplierCodeGeneratorTests {
|
|||
.setFactoryMethodOnBean("deprecatedParameter", "config").getBeanDefinition();
|
||||
beanFactory.registerBeanDefinition("config", BeanDefinitionBuilder
|
||||
.genericBeanDefinition(DeprecatedForRemovalMemberConfiguration.class).getBeanDefinition());
|
||||
Class<?> deprecatedForRemovalBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean.class;
|
||||
beanFactory.registerBeanDefinition("parameter", new RootBeanDefinition(deprecatedForRemovalBeanClass));
|
||||
beanFactory.registerBeanDefinition("parameter", new RootBeanDefinition(DeprecatedForRemovalBean.class));
|
||||
compileAndCheckWarnings(beanDefinition);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue