Clean up warnings in tests
This commit is contained in:
@@ -53,7 +53,6 @@ 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;
|
||||
@@ -752,7 +751,8 @@ class BeanDefinitionMethodGeneratorTests {
|
||||
|
||||
@Test
|
||||
void generateBeanDefinitionMethodWithDeprecatedTargetClass() {
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(DeprecatedBean.class);
|
||||
Class<?> beanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
|
||||
RegisteredBean registeredBean = registerBean(beanDefinition);
|
||||
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(
|
||||
methodGeneratorFactory, registeredBean, null,
|
||||
|
||||
@@ -24,8 +24,6 @@ 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;
|
||||
@@ -63,10 +61,11 @@ 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()", DeprecatedBean.class, DeprecatedBean.class);
|
||||
method.addStatement("$T bean = new $T()", deprecatedBeanClass, deprecatedBeanClass);
|
||||
}, compiled -> assertThat(compiled.getSourceFile())
|
||||
.contains("@SuppressWarnings(\"deprecation\")"));
|
||||
}
|
||||
@@ -74,12 +73,14 @@ 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()", DeprecatedBean.class, DeprecatedBean.class);
|
||||
method.addStatement("$T another = new $T()", DeprecatedForRemovalBean.class, DeprecatedForRemovalBean.class);
|
||||
method.addStatement("$T bean = new $T()", deprecatedBeanClass, deprecatedBeanClass);
|
||||
method.addStatement("$T another = new $T()", deprecatedForRemovalBeanClass, deprecatedForRemovalBeanClass);
|
||||
}, compiled -> assertThat(compiled.getSourceFile())
|
||||
.contains("@SuppressWarnings({ \"deprecation\", \"removal\" })"));
|
||||
}
|
||||
@@ -87,14 +88,16 @@ class CodeWarningsTests {
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void detectDeprecationOnAnnotatedElementWithDeprecated() {
|
||||
this.codeWarnings.detectDeprecation(DeprecatedBean.class);
|
||||
Class<?> deprecatedBeanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
this.codeWarnings.detectDeprecation(deprecatedBeanClass);
|
||||
assertThat(this.codeWarnings.getWarnings()).containsExactly("deprecation");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
void detectDeprecationOnAnnotatedElementWithDeprecatedForRemoval() {
|
||||
this.codeWarnings.detectDeprecation(DeprecatedForRemovalBean.class);
|
||||
Class<?> deprecatedForRemovalBeanClass = org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean.class;
|
||||
this.codeWarnings.detectDeprecation(deprecatedForRemovalBeanClass);
|
||||
assertThat(this.codeWarnings.getWarnings()).containsExactly("removal");
|
||||
}
|
||||
|
||||
@@ -105,8 +108,7 @@ class CodeWarningsTests {
|
||||
assertThat(this.codeWarnings).hasToString("CodeWarnings[deprecation, rawtypes]");
|
||||
}
|
||||
|
||||
private void compile(Consumer<Builder> method,
|
||||
Consumer<Compiled> result) {
|
||||
private void compile(Consumer<Builder> method, Consumer<Compiled> result) {
|
||||
DeferredTypeBuilder typeBuilder = new DeferredTypeBuilder();
|
||||
this.generationContext.getGeneratedClasses().addForFeature("TestCode", typeBuilder);
|
||||
typeBuilder.set(type -> {
|
||||
|
||||
@@ -46,9 +46,7 @@ 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;
|
||||
@@ -280,7 +278,9 @@ class InstanceSupplierCodeGeneratorTests {
|
||||
@Test
|
||||
@Disabled("Need to move to a separate method so that the warning can be suppressed")
|
||||
void generateWhenTargetClassIsDeprecated() {
|
||||
compileAndCheckWarnings(new RootBeanDefinition(DeprecatedBean.class));
|
||||
Class<?> deprecatedBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
compileAndCheckWarnings(new RootBeanDefinition(deprecatedBeanClass));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -305,14 +305,18 @@ class InstanceSupplierCodeGeneratorTests {
|
||||
.setFactoryMethodOnBean("deprecatedParameter", "config").getBeanDefinition();
|
||||
beanFactory.registerBeanDefinition("config", BeanDefinitionBuilder
|
||||
.genericBeanDefinition(DeprecatedMemberConfiguration.class).getBeanDefinition());
|
||||
beanFactory.registerBeanDefinition("parameter", new RootBeanDefinition(DeprecatedBean.class));
|
||||
Class<?> deprecatedBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
beanFactory.registerBeanDefinition("parameter", new RootBeanDefinition(deprecatedBeanClass));
|
||||
compileAndCheckWarnings(beanDefinition);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateWhenTargetFactoryMethodReturnTypeIsDeprecated() {
|
||||
Class<?> deprecatedBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedBean.class;
|
||||
BeanDefinition beanDefinition = BeanDefinitionBuilder
|
||||
.rootBeanDefinition(DeprecatedBean.class)
|
||||
.rootBeanDefinition(deprecatedBeanClass)
|
||||
.setFactoryMethodOnBean("deprecatedReturnType", "config").getBeanDefinition();
|
||||
beanFactory.registerBeanDefinition("config", BeanDefinitionBuilder
|
||||
.genericBeanDefinition(DeprecatedMemberConfiguration.class).getBeanDefinition());
|
||||
@@ -336,7 +340,9 @@ class InstanceSupplierCodeGeneratorTests {
|
||||
@Test
|
||||
@Disabled("Need to move to a separate method so that the warning can be suppressed")
|
||||
void generateWhenTargetClassIsDeprecatedForRemoval() {
|
||||
compileAndCheckWarnings(new RootBeanDefinition(DeprecatedForRemovalBean.class));
|
||||
Class<?> deprecatedForRemovalBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean.class;
|
||||
compileAndCheckWarnings(new RootBeanDefinition(deprecatedForRemovalBeanClass));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -361,7 +367,9 @@ class InstanceSupplierCodeGeneratorTests {
|
||||
.setFactoryMethodOnBean("deprecatedParameter", "config").getBeanDefinition();
|
||||
beanFactory.registerBeanDefinition("config", BeanDefinitionBuilder
|
||||
.genericBeanDefinition(DeprecatedForRemovalMemberConfiguration.class).getBeanDefinition());
|
||||
beanFactory.registerBeanDefinition("parameter", new RootBeanDefinition(DeprecatedForRemovalBean.class));
|
||||
Class<?> deprecatedForRemovalBeanClass =
|
||||
org.springframework.beans.testfixture.beans.factory.generator.deprecation.DeprecatedForRemovalBean.class;
|
||||
beanFactory.registerBeanDefinition("parameter", new RootBeanDefinition(deprecatedForRemovalBeanClass));
|
||||
compileAndCheckWarnings(beanDefinition);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.context.ApplicationEvent;
|
||||
@SuppressWarnings("serial")
|
||||
public class MyEvent extends ApplicationEvent {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String message;
|
||||
|
||||
public MyEvent(Object source, String message) {
|
||||
|
||||
@@ -25,6 +25,7 @@ public class MyEventListener implements ApplicationListener<MyEvent> {
|
||||
|
||||
public int eventCount;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Autowired
|
||||
private MyEventListener eventDemoListener;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user