15
15
*/
16
16
package org .apache .ibatis .reflection .factory ;
17
17
18
+ import java .util .ArrayList ;
18
19
import java .util .Arrays ;
20
+ import java .util .Collection ;
19
21
import java .util .Collections ;
22
+ import java .util .HashMap ;
23
+ import java .util .HashSet ;
24
+ import java .util .List ;
25
+ import java .util .Map ;
26
+ import java .util .Set ;
27
+ import java .util .SortedSet ;
28
+ import java .util .TreeSet ;
20
29
21
30
import org .apache .ibatis .reflection .ReflectionException ;
22
31
import org .junit .Assert ;
30
39
public class DefaultObjectFactoryTest {
31
40
32
41
@ Test
33
- public void instantiateClass () throws Exception {
42
+ public void createClass () throws Exception {
34
43
DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory ();
35
- TestClass testClass = defaultObjectFactory .instantiateClass (TestClass .class ,
44
+ TestClass testClass = defaultObjectFactory .create (TestClass .class ,
36
45
Arrays .<Class <?>>asList (String .class , Integer .class ), Arrays .<Object >asList ("foo" , 0 ));
37
46
38
47
Assert .assertEquals ("myInteger didn't match expected" , (Integer ) 0 , testClass .myInteger );
39
48
Assert .assertEquals ("myString didn't match expected" , "foo" , testClass .myString );
40
49
}
41
50
42
51
@ Test
43
- public void instantiateClassThrowsProperErrorMsg () {
52
+ public void createClassThrowsProperErrorMsg () {
44
53
DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory ();
45
54
try {
46
- defaultObjectFactory .instantiateClass (TestClass .class , Collections .<Class <?>>singletonList (String .class ), Collections .<Object >singletonList ("foo" ));
55
+ defaultObjectFactory .create (TestClass .class , Collections .<Class <?>>singletonList (String .class ), Collections .<Object >singletonList ("foo" ));
47
56
Assert .fail ("Should have thrown ReflectionException" );
48
57
} catch (Exception e ) {
49
58
Assert .assertTrue ("Should be ReflectionException" , e instanceof ReflectionException );
@@ -52,4 +61,39 @@ public void instantiateClassThrowsProperErrorMsg() {
52
61
}
53
62
}
54
63
64
+ @ Test
65
+ public void creatHashMap () throws Exception {
66
+ DefaultObjectFactory defaultObjectFactory =new DefaultObjectFactory ();
67
+ Map map = defaultObjectFactory .create (Map .class ,null ,null );
68
+ Assert .assertTrue ("Should be HashMap" ,map instanceof HashMap );
69
+ }
70
+
71
+ @ Test
72
+ public void createArrayList () throws Exception {
73
+ DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory ();
74
+ List list = defaultObjectFactory .create (List .class );
75
+ Assert .assertTrue (" list should be ArrayList" , list instanceof ArrayList );
76
+
77
+ Collection collection = defaultObjectFactory .create (Collection .class );
78
+ Assert .assertTrue (" collection should be ArrayList" , collection instanceof ArrayList );
79
+
80
+ Iterable iterable = defaultObjectFactory .create (Iterable .class );
81
+ Assert .assertTrue (" iterable should be ArrayList" , iterable instanceof ArrayList );
82
+ }
83
+
84
+
85
+ @ Test
86
+ public void createTreeSet () throws Exception {
87
+ DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory ();
88
+ SortedSet sortedSet = defaultObjectFactory .create (SortedSet .class );
89
+ Assert .assertTrue (" sortedSet should be TreeSet" , sortedSet instanceof TreeSet );
90
+ }
91
+
92
+
93
+ @ Test
94
+ public void createHashSet () throws Exception {
95
+ DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory ();
96
+ Set set = defaultObjectFactory .create (Set .class );
97
+ Assert .assertTrue (" set should be HashSet" , set instanceof HashSet );
98
+ }
55
99
}
0 commit comments