01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springunit.framework;
18:
19: import java.util.HashMap;
20: import java.util.Map;
21:
22: import junit.framework.TestCase;
23:
24: public class SpringUnitContextTest extends TestCase {
25:
26: public void testSetData() {
27: Map<String, Object> data = createData();
28: SpringUnitContext<Object> subject = new SpringUnitContext<Object>();
29: subject.setData(data);
30: assertTrue(data.equals(subject.getData()));
31: }
32:
33: public void testGetObject() throws Exception {
34: SpringUnitContext<Object> subject = createSubject();
35: assertNull(subject.getObject("e", "testOne"));
36: assertNull(subject.getObject("e", "testTwo"));
37: assertNull(subject.getObject("e", "testThree"));
38: assertNull(subject.getObject("e", "testFour"));
39: assertEquals(subject.getObject("d", "testOne"), 4);
40: assertEquals(subject.getObject("d", "testTwo"), 4);
41: assertEquals(subject.getObject("d", "testThree"), 4);
42: assertEquals(subject.getObject("d", "testFour"), 4);
43: assertEquals(subject.getObject("c", "testOne"), 3);
44: assertEquals(subject.getObject("b", "testOne"), 2);
45: assertEquals(subject.getObject("a", "testOne"), 1);
46: assertEquals(subject.getObject("testTwo", "testTwo"), 5);
47: }
48:
49: protected SpringUnitContext<Object> createSubject()
50: throws Exception {
51: SpringUnitContext<Object> result = new SpringUnitContext<Object>();
52: result.setData(createData());
53: return result;
54: }
55:
56: protected Map<String, Object> createData() {
57: Map<String, Object> result = new HashMap<String, Object>();
58: Map<String, Object> testData = new HashMap<String, Object>();
59: testData.put("a", 1);
60: testData.put("b", 2);
61: testData.put("c", 3);
62: result.put("testOne", testData);
63: result.put("d", 4);
64: result.put("e", null);
65: result.put("testTwo", 5);
66: result.put("testThree", null);
67: return result;
68: }
69:
70: }
|