1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration.beanutils;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.commons.configuration.PropertiesConfiguration;
28 import org.junit.Before;
29 import org.junit.Test;
30
31
32
33
34
35
36
37
38
39
40 public class TestDefaultBeanFactory
41 {
42
43 DefaultBeanFactory factory;
44
45 @Before
46 public void setUp() throws Exception
47 {
48 factory = new DefaultBeanFactory();
49 }
50
51
52
53
54 @Test
55 public void testGetDefaultBeanClass()
56 {
57 assertNull("Default class is not null", factory.getDefaultBeanClass());
58 }
59
60
61
62
63 @Test
64 public void testCreateBean() throws Exception
65 {
66 Object bean = factory.createBean(PropertiesConfiguration.class,
67 new TestBeanDeclaration(), null);
68 assertNotNull("New bean is null", bean);
69 assertEquals("Bean is of wrong class", PropertiesConfiguration.class,
70 bean.getClass());
71 PropertiesConfiguration config = (PropertiesConfiguration) bean;
72 assertTrue("Bean was not initialized", config
73 .isThrowExceptionOnMissing());
74 }
75
76
77
78
79 static class TestBeanDeclaration implements BeanDeclaration
80 {
81 public String getBeanFactoryName()
82 {
83 return null;
84 }
85
86 public Object getBeanFactoryParameter()
87 {
88 return null;
89 }
90
91 public String getBeanClassName()
92 {
93 return null;
94 }
95
96 public Map<String, Object> getBeanProperties()
97 {
98 Map<String, Object> props = new HashMap<String, Object>();
99 props.put("throwExceptionOnMissing", Boolean.TRUE);
100 return props;
101 }
102
103 public Map<String, Object> getNestedBeanDeclarations()
104 {
105 return null;
106 }
107 }
108 }