diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java index 3dbcad3e149..4c5a7f355bb 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java @@ -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, diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/CodeWarningsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/CodeWarningsTests.java index 365ae5ced2b..e764839afe9 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/CodeWarningsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/CodeWarningsTests.java @@ -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 method, - Consumer result) { + private void compile(Consumer method, Consumer result) { DeferredTypeBuilder typeBuilder = new DeferredTypeBuilder(); this.generationContext.getGeneratedClasses().addForFeature("TestCode", typeBuilder); typeBuilder.set(type -> { diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java index 5e166745de6..cec5a3f8493 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java @@ -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); } diff --git a/spring-context/src/test/java/org/springframework/context/event/test/self_inject/MyEvent.java b/spring-context/src/test/java/org/springframework/context/event/test/self_inject/MyEvent.java index fa426c57c11..bd47102348f 100644 --- a/spring-context/src/test/java/org/springframework/context/event/test/self_inject/MyEvent.java +++ b/spring-context/src/test/java/org/springframework/context/event/test/self_inject/MyEvent.java @@ -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) { diff --git a/spring-context/src/test/java/org/springframework/context/event/test/self_inject/MyEventListener.java b/spring-context/src/test/java/org/springframework/context/event/test/self_inject/MyEventListener.java index cf0063e7788..fb15ad17446 100644 --- a/spring-context/src/test/java/org/springframework/context/event/test/self_inject/MyEventListener.java +++ b/spring-context/src/test/java/org/springframework/context/event/test/self_inject/MyEventListener.java @@ -25,6 +25,7 @@ public class MyEventListener implements ApplicationListener { public int eventCount; + @SuppressWarnings("unused") @Autowired private MyEventListener eventDemoListener;