Add missing test cases in XmlBeanFactoryTests

Closes gh-24189
This commit is contained in:
lixiaolong11000
2019-12-11 23:44:42 +08:00
committed by Sam Brannen
parent 49ddf798e0
commit bee2b7cd73
2 changed files with 62 additions and 0 deletions

View File

@@ -536,6 +536,46 @@ public class XmlBeanFactoryTests {
assertThat(complexEgo.getSpouse().getSpouse() == complexEgo).as("Correct circular reference").isTrue();
}
@Test
public void testCircularReferencesWithConstructor() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("jenny_constructor"))
.matches(ex -> ex.contains(BeanCurrentlyInCreationException.class));
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("david_constructor"))
.matches(ex -> ex.contains(BeanCurrentlyInCreationException.class));
}
@Test
public void testCircularReferencesWithPrototype() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("jenny_prototype"))
.matches(ex -> ex.contains(BeanCurrentlyInCreationException.class));
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("david_prototype"))
.matches(ex -> ex.contains(BeanCurrentlyInCreationException.class));
}
@Test
public void testCircularReferencesWithDependOn() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("jenny_depends_on"));
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("david_depends_on"));
}
@Test
public void testCircularReferenceWithFactoryBeanFirst() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();