KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > keyvalue > TestTiedMapEntry


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.Map JavaDoc;
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: 1.3 $ $Date: 2004/02/18 01:20:40 $
29  *
30  * @author Stephen Colebourne
31  */

32 public class TestTiedMapEntry extends AbstractTestMapEntry {
33
34     public TestTiedMapEntry(String JavaDoc testName) {
35         super(testName);
36
37     }
38
39     public static void main(String JavaDoc[] 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 JavaDoc makeMapEntry(Object JavaDoc key, Object JavaDoc value) {
52         Map JavaDoc map = new HashMap JavaDoc();
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 JavaDoc map = new HashMap JavaDoc();
70         map.put("A", "a");
71         map.put("B", "b");
72         map.put("C", "c");
73         Map.Entry JavaDoc 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 }
96
Popular Tags