@ -31,6 +31,7 @@ import org.springframework.aot.generate.GeneratedClass;
@@ -31,6 +31,7 @@ import org.springframework.aot.generate.GeneratedClass;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates ;
import org.springframework.aot.test.generator.compile.Compiled ;
import org.springframework.aot.test.generator.compile.TestCompiler ;
import org.springframework.beans.factory.FactoryBean ;
import org.springframework.beans.factory.config.BeanDefinition ;
import org.springframework.beans.factory.config.BeanReference ;
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder ;
@ -46,6 +47,7 @@ import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
@@ -46,6 +47,7 @@ import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
import org.springframework.javapoet.CodeBlock ;
import org.springframework.javapoet.MethodSpec ;
import org.springframework.javapoet.ParameterizedTypeName ;
import org.springframework.lang.Nullable ;
import static org.assertj.core.api.Assertions.assertThat ;
@ -353,6 +355,20 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
@@ -353,6 +355,20 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
} ) ;
}
@Test
void propertyValuesWhenValuesOnFactoryBeanClass ( ) {
this . beanDefinition . setTargetType ( String . class ) ;
this . beanDefinition . setBeanClass ( PropertyValuesFactoryBean . class ) ;
this . beanDefinition . getPropertyValues ( ) . add ( "prefix" , "Hello" ) ;
this . beanDefinition . getPropertyValues ( ) . add ( "name" , "World" ) ;
compile ( ( actual , compiled ) - > {
assertThat ( actual . getPropertyValues ( ) . get ( "prefix" ) ) . isEqualTo ( "Hello" ) ;
assertThat ( actual . getPropertyValues ( ) . get ( "name" ) ) . isEqualTo ( "World" ) ;
} ) ;
String [ ] methodNames = { "setPrefix" , "setName" } ;
assertHasMethodInvokeHints ( PropertyValuesFactoryBean . class , methodNames ) ;
}
@Test
void attributesWhenAllFiltered ( ) {
this . beanDefinition . setAttribute ( "a" , "A" ) ;
@ -460,4 +476,40 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
@@ -460,4 +476,40 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
}
static class PropertyValuesFactoryBean implements FactoryBean < String > {
private Class < ? > prefix ;
private String name ;
public Class < ? > getPrefix ( ) {
return this . prefix ;
}
public void setPrefix ( Class < ? > prefix ) {
this . prefix = prefix ;
}
public String getName ( ) {
return this . name ;
}
public void setName ( String name ) {
this . name = name ;
}
@Nullable
@Override
public String getObject ( ) throws Exception {
return getPrefix ( ) + " " + getName ( ) ;
}
@Nullable
@Override
public Class < ? > getObjectType ( ) {
return String . class ;
}
}
}