Skip to content

Commit 4cad758

Browse files
committed
1. 增加ClassPathXmlApplicationContext的测试用例
1 parent 180b20e commit 4cad758

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/main/java/com/dianpoint/summer/beans/factory/config/BeanDefinition.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.dianpoint.summer.beans.factory.config;
22

33
import com.dianpoint.summer.beans.PropertyValues;
4-
import com.dianpoint.summer.beans.factory.config.ConstructorArgumentValues;
54

65
/**
76
* <p>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.dianpoint.summer.test.xml;
2+
3+
import com.dianpoint.summer.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
4+
import com.dianpoint.summer.beans.factory.config.BeanFactoryPostProcessor;
5+
import com.dianpoint.summer.context.ClassPathXmlApplicationContext;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
import java.util.List;
10+
11+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
12+
13+
14+
/**
15+
* @author wangyi
16+
* @date 2023/3/31
17+
*/
18+
public class ClassPathXmlApplicationContextTest {
19+
static ClassPathXmlApplicationContext classPathXmlApplicationContext;
20+
static String beanNames = "registerBeanStr";
21+
static String beanObject = "beanObject";
22+
23+
@Before
24+
public void setUp() {
25+
classPathXmlApplicationContext = new ClassPathXmlApplicationContext("xml/beanAutowire.xml",false);
26+
classPathXmlApplicationContext.registerBean(beanNames, beanObject);
27+
}
28+
29+
@Test
30+
public void testRegisterBean() {
31+
final String[] names = classPathXmlApplicationContext.getBeanFactory().getSingletonNames();
32+
assertThat(names).contains(beanNames);
33+
assertThat(classPathXmlApplicationContext.getBeanFactory().containsBean(beanNames)).isTrue();
34+
}
35+
36+
@Test
37+
public void testGetSingleton() {
38+
final Object result = classPathXmlApplicationContext.getSingleton(beanNames);
39+
assertThat(result).isEqualTo(beanObject);
40+
}
41+
42+
@Test
43+
public void testAddBeanPostProcessor() {
44+
classPathXmlApplicationContext.addBeanPostProcessor(new AutowiredAnnotationBeanPostProcessor());
45+
final Integer count = classPathXmlApplicationContext.getBeanPostProcessorCount();
46+
assertThat(count).isEqualTo(1);
47+
}
48+
49+
@Test
50+
public void testGetBeanDefinitionCount() {
51+
final Integer result = classPathXmlApplicationContext.getBeanDefinitionCount();
52+
assertThat(result).isEqualTo(2);
53+
}
54+
55+
56+
@Test
57+
public void testAddBeanFactoryPostProcessor() {
58+
classPathXmlApplicationContext.addBeanFactoryPostProcessor(beanFactory -> {
59+
60+
});
61+
final List<BeanFactoryPostProcessor> list = classPathXmlApplicationContext.getBeanFactoryPostProcessors();
62+
assertThat(!list.isEmpty()).isTrue();
63+
}
64+
65+
@Test
66+
public void testIsActive() {
67+
final boolean result = classPathXmlApplicationContext.isActive();
68+
assertThat(result).isTrue();
69+
}
70+
}

0 commit comments

Comments
 (0)