@ -24,8 +24,6 @@ import org.junit.jupiter.api.Test;
@@ -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 {
@@ -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 . c lass) ;
method . addStatement ( "$T bean = new $T()" , deprecatedBeanClass , deprecatedBeanC lass) ;
} , compiled - > assertThat ( compiled . getSourceFile ( ) )
. contains ( "@SuppressWarnings(\"deprecation\")" ) ) ;
}
@ -74,12 +73,14 @@ class CodeWarningsTests {
@@ -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 . c lass) ;
method . addStatement ( "$T another = new $T()" , DeprecatedForRemovalBean . class , DeprecatedForRemovalBean . c lass) ;
method . addStatement ( "$T bean = new $T()" , deprecatedBeanClass , deprecatedBeanC lass) ;
method . addStatement ( "$T another = new $T()" , deprecatedForRemovalBeanClass , deprecatedForRemovalBeanC lass) ;
} , compiled - > assertThat ( compiled . getSourceFile ( ) )
. contains ( "@SuppressWarnings({ \"deprecation\", \"removal\" })" ) ) ;
}
@ -87,14 +88,16 @@ class CodeWarningsTests {
@@ -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 {
@@ -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 - > {