1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .beans .factory .xml ;
18
18
19
19
import java .lang .reflect .Proxy ;
20
+ import java .util .Arrays ;
20
21
import java .util .List ;
21
22
import java .util .Map ;
22
23
import java .util .Properties ;
23
24
import java .util .Set ;
24
25
import java .util .TreeMap ;
25
- import java .util .Arrays ;
26
26
27
- import junit .framework .TestCase ;
27
+ import org .junit .Before ;
28
+ import org .junit .Test ;
28
29
29
30
import org .springframework .beans .factory .config .FieldRetrievingFactoryBean ;
30
31
import org .springframework .beans .factory .config .PropertiesFactoryBean ;
35
36
import org .springframework .tests .beans .CollectingReaderEventListener ;
36
37
import org .springframework .tests .sample .beans .CustomEnum ;
37
38
import org .springframework .tests .sample .beans .TestBean ;
39
+ import org .springframework .util .LinkedCaseInsensitiveMap ;
40
+
41
+ import static org .junit .Assert .*;
38
42
39
43
/**
40
44
* @author Rob Harrop
41
45
* @author Juergen Hoeller
42
46
* @author Mark Fisher
43
47
*/
44
- public class UtilNamespaceHandlerTests extends TestCase {
48
+ public class UtilNamespaceHandlerTests {
45
49
46
50
private DefaultListableBeanFactory beanFactory ;
47
51
48
52
private CollectingReaderEventListener listener = new CollectingReaderEventListener ();
49
53
50
- @ Override
54
+
55
+ @ Before
51
56
public void setUp () {
52
57
this .beanFactory = new DefaultListableBeanFactory ();
53
58
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader (this .beanFactory );
54
59
reader .setEventListener (this .listener );
55
60
reader .loadBeanDefinitions (new ClassPathResource ("testUtilNamespace.xml" , getClass ()));
56
61
}
57
62
58
- public void testConstant () throws Exception {
63
+
64
+ @ Test
65
+ public void testConstant () {
59
66
Integer min = (Integer ) this .beanFactory .getBean ("min" );
60
67
assertEquals (Integer .MIN_VALUE , min .intValue ());
61
68
}
62
69
63
- public void testConstantWithDefaultName () throws Exception {
70
+ @ Test
71
+ public void testConstantWithDefaultName () {
64
72
Integer max = (Integer ) this .beanFactory .getBean ("java.lang.Integer.MAX_VALUE" );
65
73
assertEquals (Integer .MAX_VALUE , max .intValue ());
66
74
}
67
75
68
- public void testEvents () throws Exception {
76
+ @ Test
77
+ public void testEvents () {
69
78
ComponentDefinition propertiesComponent = this .listener .getComponentDefinition ("myProperties" );
70
79
assertNotNull ("Event for 'myProperties' not sent" , propertiesComponent );
71
80
AbstractBeanDefinition propertiesBean = (AbstractBeanDefinition ) propertiesComponent .getBeanDefinitions ()[0 ];
@@ -77,74 +86,92 @@ public void testEvents() throws Exception {
77
86
assertEquals ("Incorrect BeanDefinition" , FieldRetrievingFactoryBean .class , constantBean .getBeanClass ());
78
87
}
79
88
80
- public void testNestedProperties () throws Exception {
89
+ @ Test
90
+ public void testNestedProperties () {
81
91
TestBean bean = (TestBean ) this .beanFactory .getBean ("testBean" );
82
92
Properties props = bean .getSomeProperties ();
83
93
assertEquals ("Incorrect property value" , "bar" , props .get ("foo" ));
84
94
}
85
95
86
- public void testPropertyPath () throws Exception {
96
+ @ Test
97
+ public void testPropertyPath () {
87
98
String name = (String ) this .beanFactory .getBean ("name" );
88
99
assertEquals ("Rob Harrop" , name );
89
100
}
90
101
91
- public void testNestedPropertyPath () throws Exception {
102
+ @ Test
103
+ public void testNestedPropertyPath () {
92
104
TestBean bean = (TestBean ) this .beanFactory .getBean ("testBean" );
93
105
assertEquals ("Rob Harrop" , bean .getName ());
94
106
}
95
107
96
- public void testSimpleMap () throws Exception {
108
+ @ Test
109
+ public void testSimpleMap () {
97
110
Map map = (Map ) this .beanFactory .getBean ("simpleMap" );
98
111
assertEquals ("bar" , map .get ("foo" ));
99
112
Map map2 = (Map ) this .beanFactory .getBean ("simpleMap" );
100
113
assertTrue (map == map2 );
101
114
}
102
115
103
- public void testScopedMap () throws Exception {
116
+ @ Test
117
+ public void testScopedMap () {
104
118
Map map = (Map ) this .beanFactory .getBean ("scopedMap" );
105
119
assertEquals ("bar" , map .get ("foo" ));
106
120
Map map2 = (Map ) this .beanFactory .getBean ("scopedMap" );
107
121
assertEquals ("bar" , map2 .get ("foo" ));
108
122
assertTrue (map != map2 );
109
123
}
110
124
111
- public void testSimpleList () throws Exception {
125
+ @ Test
126
+ public void testSimpleList () {
112
127
List list = (List ) this .beanFactory .getBean ("simpleList" );
113
128
assertEquals ("Rob Harrop" , list .get (0 ));
114
129
List list2 = (List ) this .beanFactory .getBean ("simpleList" );
115
130
assertTrue (list == list2 );
116
131
}
117
132
118
- public void testScopedList () throws Exception {
133
+ @ Test
134
+ public void testScopedList () {
119
135
List list = (List ) this .beanFactory .getBean ("scopedList" );
120
136
assertEquals ("Rob Harrop" , list .get (0 ));
121
137
List list2 = (List ) this .beanFactory .getBean ("scopedList" );
122
138
assertEquals ("Rob Harrop" , list2 .get (0 ));
123
139
assertTrue (list != list2 );
124
140
}
125
141
126
- public void testSimpleSet () throws Exception {
142
+ @ Test
143
+ public void testSimpleSet () {
127
144
Set set = (Set ) this .beanFactory .getBean ("simpleSet" );
128
145
assertTrue (set .contains ("Rob Harrop" ));
129
146
Set set2 = (Set ) this .beanFactory .getBean ("simpleSet" );
130
147
assertTrue (set == set2 );
131
148
}
132
149
133
- public void testScopedSet () throws Exception {
150
+ @ Test
151
+ public void testScopedSet () {
134
152
Set set = (Set ) this .beanFactory .getBean ("scopedSet" );
135
153
assertTrue (set .contains ("Rob Harrop" ));
136
154
Set set2 = (Set ) this .beanFactory .getBean ("scopedSet" );
137
155
assertTrue (set2 .contains ("Rob Harrop" ));
138
156
assertTrue (set != set2 );
139
157
}
140
158
141
- public void testMapWithRef () throws Exception {
159
+ @ Test
160
+ public void testMapWithRef () {
142
161
Map map = (Map ) this .beanFactory .getBean ("mapWithRef" );
143
162
assertTrue (map instanceof TreeMap );
144
163
assertEquals (this .beanFactory .getBean ("testBean" ), map .get ("bean" ));
145
164
}
146
165
147
- public void testNestedCollections () throws Exception {
166
+ @ Test
167
+ public void testMapWithTypes () {
168
+ Map map = (Map ) this .beanFactory .getBean ("mapWithTypes" );
169
+ assertTrue (map instanceof LinkedCaseInsensitiveMap );
170
+ assertEquals (this .beanFactory .getBean ("testBean" ), map .get ("bean" ));
171
+ }
172
+
173
+ @ Test
174
+ public void testNestedCollections () {
148
175
TestBean bean = (TestBean ) this .beanFactory .getBean ("nestedCollectionsBean" );
149
176
150
177
List list = bean .getSomeList ();
@@ -171,7 +198,8 @@ public void testNestedCollections() throws Exception {
171
198
assertFalse (map == bean2 .getSomeMap ());
172
199
}
173
200
174
- public void testNestedShortcutCollections () throws Exception {
201
+ @ Test
202
+ public void testNestedShortcutCollections () {
175
203
TestBean bean = (TestBean ) this .beanFactory .getBean ("nestedShortcutCollections" );
176
204
177
205
assertEquals (1 , bean .getStringArray ().length );
@@ -194,7 +222,8 @@ public void testNestedShortcutCollections() throws Exception {
194
222
assertFalse (set == bean2 .getSomeSet ());
195
223
}
196
224
197
- public void testNestedInCollections () throws Exception {
225
+ @ Test
226
+ public void testNestedInCollections () {
198
227
TestBean bean = (TestBean ) this .beanFactory .getBean ("nestedCustomTagBean" );
199
228
200
229
List list = bean .getSomeList ();
@@ -219,7 +248,8 @@ public void testNestedInCollections() throws Exception {
219
248
assertFalse (map == bean2 .getSomeMap ());
220
249
}
221
250
222
- public void testCircularCollections () throws Exception {
251
+ @ Test
252
+ public void testCircularCollections () {
223
253
TestBean bean = (TestBean ) this .beanFactory .getBean ("circularCollectionsBean" );
224
254
225
255
List list = bean .getSomeList ();
@@ -235,7 +265,8 @@ public void testCircularCollections() throws Exception {
235
265
assertEquals (bean , map .get ("foo" ));
236
266
}
237
267
238
- public void testCircularCollectionBeansStartingWithList () throws Exception {
268
+ @ Test
269
+ public void testCircularCollectionBeansStartingWithList () {
239
270
this .beanFactory .getBean ("circularList" );
240
271
TestBean bean = (TestBean ) this .beanFactory .getBean ("circularCollectionBeansBean" );
241
272
@@ -255,7 +286,8 @@ public void testCircularCollectionBeansStartingWithList() throws Exception {
255
286
assertEquals (bean , map .get ("foo" ));
256
287
}
257
288
258
- public void testCircularCollectionBeansStartingWithSet () throws Exception {
289
+ @ Test
290
+ public void testCircularCollectionBeansStartingWithSet () {
259
291
this .beanFactory .getBean ("circularSet" );
260
292
TestBean bean = (TestBean ) this .beanFactory .getBean ("circularCollectionBeansBean" );
261
293
@@ -275,7 +307,8 @@ public void testCircularCollectionBeansStartingWithSet() throws Exception {
275
307
assertEquals (bean , map .get ("foo" ));
276
308
}
277
309
278
- public void testCircularCollectionBeansStartingWithMap () throws Exception {
310
+ @ Test
311
+ public void testCircularCollectionBeansStartingWithMap () {
279
312
this .beanFactory .getBean ("circularMap" );
280
313
TestBean bean = (TestBean ) this .beanFactory .getBean ("circularCollectionBeansBean" );
281
314
@@ -295,20 +328,23 @@ public void testCircularCollectionBeansStartingWithMap() throws Exception {
295
328
assertEquals (bean , map .get ("foo" ));
296
329
}
297
330
298
- public void testNestedInConstructor () throws Exception {
331
+ @ Test
332
+ public void testNestedInConstructor () {
299
333
TestBean bean = (TestBean ) this .beanFactory .getBean ("constructedTestBean" );
300
334
assertEquals ("Rob Harrop" , bean .getName ());
301
335
}
302
336
303
- public void testLoadProperties () throws Exception {
337
+ @ Test
338
+ public void testLoadProperties () {
304
339
Properties props = (Properties ) this .beanFactory .getBean ("myProperties" );
305
340
assertEquals ("Incorrect property value" , "bar" , props .get ("foo" ));
306
341
assertEquals ("Incorrect property value" , null , props .get ("foo2" ));
307
342
Properties props2 = (Properties ) this .beanFactory .getBean ("myProperties" );
308
343
assertTrue (props == props2 );
309
344
}
310
345
311
- public void testScopedProperties () throws Exception {
346
+ @ Test
347
+ public void testScopedProperties () {
312
348
Properties props = (Properties ) this .beanFactory .getBean ("myScopedProperties" );
313
349
assertEquals ("Incorrect property value" , "bar" , props .get ("foo" ));
314
350
assertEquals ("Incorrect property value" , null , props .get ("foo2" ));
@@ -318,30 +354,35 @@ public void testScopedProperties() throws Exception {
318
354
assertTrue (props != props2 );
319
355
}
320
356
321
- public void testLocalProperties () throws Exception {
357
+ @ Test
358
+ public void testLocalProperties () {
322
359
Properties props = (Properties ) this .beanFactory .getBean ("myLocalProperties" );
323
360
assertEquals ("Incorrect property value" , null , props .get ("foo" ));
324
361
assertEquals ("Incorrect property value" , "bar2" , props .get ("foo2" ));
325
362
}
326
363
327
- public void testMergedProperties () throws Exception {
364
+ @ Test
365
+ public void testMergedProperties () {
328
366
Properties props = (Properties ) this .beanFactory .getBean ("myMergedProperties" );
329
367
assertEquals ("Incorrect property value" , "bar" , props .get ("foo" ));
330
368
assertEquals ("Incorrect property value" , "bar2" , props .get ("foo2" ));
331
369
}
332
370
371
+ @ Test
333
372
public void testLocalOverrideDefault () {
334
373
Properties props = (Properties ) this .beanFactory .getBean ("defaultLocalOverrideProperties" );
335
374
assertEquals ("Incorrect property value" , "bar" , props .get ("foo" ));
336
375
assertEquals ("Incorrect property value" , "local2" , props .get ("foo2" ));
337
376
}
338
377
378
+ @ Test
339
379
public void testLocalOverrideFalse () {
340
380
Properties props = (Properties ) this .beanFactory .getBean ("falseLocalOverrideProperties" );
341
381
assertEquals ("Incorrect property value" , "bar" , props .get ("foo" ));
342
382
assertEquals ("Incorrect property value" , "local2" , props .get ("foo2" ));
343
383
}
344
384
385
+ @ Test
345
386
public void testLocalOverrideTrue () {
346
387
Properties props = (Properties ) this .beanFactory .getBean ("trueLocalOverrideProperties" );
347
388
assertEquals ("Incorrect property value" , "local" , props .get ("foo" ));
0 commit comments