|
31 | 31 | import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
32 | 32 | import org.springframework.aot.test.generator.compile.Compiled;
|
33 | 33 | import org.springframework.aot.test.generator.compile.TestCompiler;
|
| 34 | +import org.springframework.beans.factory.FactoryBean; |
34 | 35 | import org.springframework.beans.factory.config.BeanDefinition;
|
35 | 36 | import org.springframework.beans.factory.config.BeanReference;
|
36 | 37 | import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
|
|
46 | 47 | import org.springframework.javapoet.CodeBlock;
|
47 | 48 | import org.springframework.javapoet.MethodSpec;
|
48 | 49 | import org.springframework.javapoet.ParameterizedTypeName;
|
| 50 | +import org.springframework.lang.Nullable; |
49 | 51 |
|
50 | 52 | import static org.assertj.core.api.Assertions.assertThat;
|
51 | 53 |
|
@@ -353,6 +355,20 @@ void propertyValuesWhenContainsManagedMap() {
|
353 | 355 | });
|
354 | 356 | }
|
355 | 357 |
|
| 358 | + @Test |
| 359 | + void propertyValuesWhenValuesOnFactoryBeanClass() { |
| 360 | + this.beanDefinition.setTargetType(String.class); |
| 361 | + this.beanDefinition.setBeanClass(PropertyValuesFactoryBean.class); |
| 362 | + this.beanDefinition.getPropertyValues().add("prefix", "Hello"); |
| 363 | + this.beanDefinition.getPropertyValues().add("name", "World"); |
| 364 | + compile((actual, compiled) -> { |
| 365 | + assertThat(actual.getPropertyValues().get("prefix")).isEqualTo("Hello"); |
| 366 | + assertThat(actual.getPropertyValues().get("name")).isEqualTo("World"); |
| 367 | + }); |
| 368 | + String[] methodNames = { "setPrefix", "setName" }; |
| 369 | + assertHasMethodInvokeHints(PropertyValuesFactoryBean.class, methodNames); |
| 370 | + } |
| 371 | + |
356 | 372 | @Test
|
357 | 373 | void attributesWhenAllFiltered() {
|
358 | 374 | this.beanDefinition.setAttribute("a", "A");
|
@@ -460,4 +476,40 @@ public void setSpring(String spring) {
|
460 | 476 |
|
461 | 477 | }
|
462 | 478 |
|
| 479 | + static class PropertyValuesFactoryBean implements FactoryBean<String> { |
| 480 | + |
| 481 | + private Class<?> prefix; |
| 482 | + |
| 483 | + private String name; |
| 484 | + |
| 485 | + public Class<?> getPrefix() { |
| 486 | + return this.prefix; |
| 487 | + } |
| 488 | + |
| 489 | + public void setPrefix(Class<?> prefix) { |
| 490 | + this.prefix = prefix; |
| 491 | + } |
| 492 | + |
| 493 | + public String getName() { |
| 494 | + return this.name; |
| 495 | + } |
| 496 | + |
| 497 | + public void setName(String name) { |
| 498 | + this.name = name; |
| 499 | + } |
| 500 | + |
| 501 | + @Nullable |
| 502 | + @Override |
| 503 | + public String getObject() throws Exception { |
| 504 | + return getPrefix() + " " + getName(); |
| 505 | + } |
| 506 | + |
| 507 | + @Nullable |
| 508 | + @Override |
| 509 | + public Class<?> getObjectType() { |
| 510 | + return String.class; |
| 511 | + } |
| 512 | + |
| 513 | + } |
| 514 | + |
463 | 515 | }
|
0 commit comments