BeanFactory does not unwrap java.util.Optional for top-level bean
Issue: SPR-14121
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -2711,7 +2712,7 @@ public class DefaultListableBeanFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveEmbeddedValue() throws Exception {
|
||||
public void resolveEmbeddedValue() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
StringValueResolver r1 = mock(StringValueResolver.class);
|
||||
StringValueResolver r2 = mock(StringValueResolver.class);
|
||||
@@ -2730,6 +2731,25 @@ public class DefaultListableBeanFactoryTests {
|
||||
verify(r3, never()).resolveStringValue(isNull(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void populatedJavaUtilOptionalBean() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(Optional.class);
|
||||
bd.setFactoryMethodName("of");
|
||||
bd.getConstructorArgumentValues().addGenericArgumentValue("CONTENT");
|
||||
bf.registerBeanDefinition("optionalBean", bd);
|
||||
assertEquals(Optional.of("CONTENT"), bf.getBean(Optional.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyJavaUtilOptionalBean() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(Optional.class);
|
||||
bd.setFactoryMethodName("empty");
|
||||
bf.registerBeanDefinition("optionalBean", bd);
|
||||
assertSame(Optional.empty(), bf.getBean(Optional.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that by-type bean lookup caching is working effectively by searching for a
|
||||
* bean of type B 10K times within a container having 1K additional beans of type A.
|
||||
|
||||
Reference in New Issue
Block a user