KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
19
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22
23 import org.apache.commons.collections.KeyValue;
24 import org.apache.commons.collections.Unmodifiable;
25
26 /**
27  * Test the UnmodifiableMapEntry class.
28  *
29  * @since Commons Collections 3.0
30  * @version $Revision: 1.3 $ $Date: 2004/02/18 01:20:40 $
31  *
32  * @author Neil O'Toole
33  */

34 public class TestUnmodifiableMapEntry extends AbstractTestMapEntry {
35
36     public TestUnmodifiableMapEntry(String JavaDoc testName) {
37         super(testName);
38
39     }
40
41     public static void main(String JavaDoc[] args) {
42         junit.textui.TestRunner.run(TestUnmodifiableMapEntry.class);
43     }
44
45     public static Test suite() {
46         return new TestSuite(TestUnmodifiableMapEntry.class);
47     }
48
49     //-----------------------------------------------------------------------
50
/**
51      * Make an instance of Map.Entry with the default (null) key and value.
52      * Subclasses should override this method to return a Map.Entry
53      * of the type being tested.
54      */

55     public Map.Entry JavaDoc makeMapEntry() {
56         return new UnmodifiableMapEntry(null, null);
57     }
58
59     /**
60      * Make an instance of Map.Entry with the specified key and value.
61      * Subclasses should override this method to return a Map.Entry
62      * of the type being tested.
63      */

64     public Map.Entry JavaDoc makeMapEntry(Object JavaDoc key, Object JavaDoc value) {
65         return new UnmodifiableMapEntry(key, value);
66     }
67
68     //-----------------------------------------------------------------------
69
/**
70      * Subclasses should override this method.
71      *
72      */

73     public void testConstructors() {
74         // 1. test key-value constructor
75
Map.Entry JavaDoc entry = new UnmodifiableMapEntry(key, value);
76         assertSame(key, entry.getKey());
77         assertSame(value, entry.getValue());
78
79         // 2. test pair constructor
80
KeyValue pair = new DefaultKeyValue(key, value);
81         entry = new UnmodifiableMapEntry(pair);
82         assertSame(key, entry.getKey());
83         assertSame(value, entry.getValue());
84
85         // 3. test copy constructor
86
Map.Entry JavaDoc entry2 = new UnmodifiableMapEntry(entry);
87         assertSame(key, entry2.getKey());
88         assertSame(value, entry2.getValue());
89
90         assertTrue(entry instanceof Unmodifiable);
91     }
92
93     public void testAccessorsAndMutators() {
94         Map.Entry JavaDoc entry = makeMapEntry(key, value);
95
96         assertSame(key, entry.getKey());
97         assertSame(value, entry.getValue());
98
99         // check that null doesn't do anything funny
100
entry = makeMapEntry(null, null);
101         assertSame(null, entry.getKey());
102         assertSame(null, entry.getValue());
103     }
104
105     public void testSelfReferenceHandling() {
106         // block
107
}
108
109     public void testUnmodifiable() {
110         Map.Entry JavaDoc entry = makeMapEntry();
111         try {
112             entry.setValue(null);
113             fail();
114
115         } catch (UnsupportedOperationException JavaDoc ex) {}
116     }
117
118 }
119
Popular Tags