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