01: /*
02: * Copyright 2001-2004 The Apache Software Foundation
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: package org.apache.commons.collections.keyvalue;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: import junit.framework.Test;
22: import junit.framework.TestSuite;
23:
24: /**
25: * Test the TiedMapEntry class.
26: *
27: * @since Commons Collections 3.0
28: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
29: *
30: * @author Stephen Colebourne
31: */
32: public class TestTiedMapEntry extends AbstractTestMapEntry {
33:
34: public TestTiedMapEntry(String testName) {
35: super (testName);
36:
37: }
38:
39: public static void main(String[] args) {
40: junit.textui.TestRunner.run(TestTiedMapEntry.class);
41: }
42:
43: public static Test suite() {
44: return new TestSuite(TestTiedMapEntry.class);
45: }
46:
47: //-----------------------------------------------------------------------
48: /**
49: * Gets the instance to test
50: */
51: public Map.Entry makeMapEntry(Object key, Object value) {
52: Map map = new HashMap();
53: map.put(key, value);
54: return new TiedMapEntry(map, key);
55: }
56:
57: //-----------------------------------------------------------------------
58: /**
59: * Tests the constructors.
60: */
61: public void testConstructors() {
62: // ignore
63: }
64:
65: /**
66: * Tests the constructors.
67: */
68: public void testSetValue() {
69: Map map = new HashMap();
70: map.put("A", "a");
71: map.put("B", "b");
72: map.put("C", "c");
73: Map.Entry entry = new TiedMapEntry(map, "A");
74: assertSame("A", entry.getKey());
75: assertSame("a", entry.getValue());
76: assertSame("a", entry.setValue("x"));
77: assertSame("A", entry.getKey());
78: assertSame("x", entry.getValue());
79:
80: entry = new TiedMapEntry(map, "B");
81: assertSame("B", entry.getKey());
82: assertSame("b", entry.getValue());
83: assertSame("b", entry.setValue("y"));
84: assertSame("B", entry.getKey());
85: assertSame("y", entry.getValue());
86:
87: entry = new TiedMapEntry(map, "C");
88: assertSame("C", entry.getKey());
89: assertSame("c", entry.getValue());
90: assertSame("c", entry.setValue("z"));
91: assertSame("C", entry.getKey());
92: assertSame("z", entry.getValue());
93: }
94:
95: }
|