KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > map > TestSingletonMap


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.map;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import junit.framework.Test;
22 import junit.textui.TestRunner;
23
24 import org.apache.commons.collections.BoundedMap;
25 import org.apache.commons.collections.BulkTest;
26 import org.apache.commons.collections.KeyValue;
27
28 /**
29  * JUnit tests.
30  *
31  * @version $Revision: 1.1 $ $Date: 2004/04/09 14:46:35 $
32  *
33  * @author Stephen Colebourne
34  */

35 public class TestSingletonMap extends AbstractTestOrderedMap {
36
37     private static final Integer JavaDoc ONE = new Integer JavaDoc(1);
38     private static final Integer JavaDoc TWO = new Integer JavaDoc(2);
39     private static final String JavaDoc TEN = "10";
40     private static final String JavaDoc TWENTY = "20";
41         
42     public TestSingletonMap(String JavaDoc testName) {
43         super(testName);
44     }
45
46     public static void main(String JavaDoc[] args) {
47         TestRunner.run(suite());
48     }
49     
50     public static Test suite() {
51         return BulkTest.makeSuite(TestSingletonMap.class);
52     }
53
54     //-----------------------------------------------------------------------
55
public Map JavaDoc makeEmptyMap() {
56         // need an empty singleton map, but thats not possible
57
// use a ridiculous fake instead to make the tests pass
58
return UnmodifiableOrderedMap.decorate(ListOrderedMap.decorate(new HashMap JavaDoc()));
59     }
60     
61     public String JavaDoc[] ignoredTests() {
62         // the ridiculous map above still doesn't pass these tests
63
// but its not relevant, so we ignore them
64
return new String JavaDoc[] {
65             "TestSingletonMap.bulkTestMapIterator.testEmptyMapIterator",
66             "TestSingletonMap.bulkTestOrderedMapIterator.testEmptyMapIterator",
67         };
68     }
69
70
71     public Map JavaDoc makeFullMap() {
72         return new SingletonMap(ONE, TWO);
73     }
74
75     public boolean isPutAddSupported() {
76         return false;
77     }
78
79     public boolean isRemoveSupported() {
80         return false;
81     }
82
83     public Object JavaDoc[] getSampleKeys() {
84         return new Object JavaDoc[] {ONE};
85     }
86
87     public Object JavaDoc[] getSampleValues() {
88         return new Object JavaDoc[] {TWO};
89     }
90
91     public Object JavaDoc[] getNewSampleValues() {
92         return new Object JavaDoc[] {TEN};
93     }
94
95     //-----------------------------------------------------------------------
96
public void testClone() {
97         SingletonMap map = new SingletonMap(ONE, TWO);
98         assertEquals(1, map.size());
99         SingletonMap cloned = (SingletonMap) map.clone();
100         assertEquals(1, cloned.size());
101         assertEquals(true, cloned.containsKey(ONE));
102         assertEquals(true, cloned.containsValue(TWO));
103     }
104
105     public void testKeyValue() {
106         SingletonMap map = new SingletonMap(ONE, TWO);
107         assertEquals(1, map.size());
108         assertEquals(ONE, map.getKey());
109         assertEquals(TWO, map.getValue());
110         assertTrue(map instanceof KeyValue);
111     }
112
113     public void testBoundedMap() {
114         SingletonMap map = new SingletonMap(ONE, TWO);
115         assertEquals(1, map.size());
116         assertEquals(true, map.isFull());
117         assertEquals(1, map.maxSize());
118         assertTrue(map instanceof BoundedMap);
119     }
120
121     //-----------------------------------------------------------------------
122
// public BulkTest bulkTestMapIterator() {
123
// return new TestFlatMapIterator();
124
// }
125
//
126
// public class TestFlatMapIterator extends AbstractTestOrderedMapIterator {
127
// public TestFlatMapIterator() {
128
// super("TestFlatMapIterator");
129
// }
130
//
131
// public Object[] addSetValues() {
132
// return TestSingletonMap.this.getNewSampleValues();
133
// }
134
//
135
// public boolean supportsRemove() {
136
// return TestSingletonMap.this.isRemoveSupported();
137
// }
138
//
139
// public boolean supportsSetValue() {
140
// return TestSingletonMap.this.isSetValueSupported();
141
// }
142
//
143
// public MapIterator makeEmptyMapIterator() {
144
// resetEmpty();
145
// return ((Flat3Map) TestSingletonMap.this.map).mapIterator();
146
// }
147
//
148
// public MapIterator makeFullMapIterator() {
149
// resetFull();
150
// return ((Flat3Map) TestSingletonMap.this.map).mapIterator();
151
// }
152
//
153
// public Map getMap() {
154
// // assumes makeFullMapIterator() called first
155
// return TestSingletonMap.this.map;
156
// }
157
//
158
// public Map getConfirmedMap() {
159
// // assumes makeFullMapIterator() called first
160
// return TestSingletonMap.this.confirmed;
161
// }
162
//
163
// public void verify() {
164
// super.verify();
165
// TestSingletonMap.this.verify();
166
// }
167
// }
168

169     public String JavaDoc getCompatibilityVersion() {
170         return "3.1";
171     }
172
173 // public void testCreate() throws Exception {
174
// resetEmpty();
175
// writeExternalFormToDisk(
176
// (java.io.Serializable) map,
177
// "D:/dev/collections/data/test/SingletonMap.emptyCollection.version3.1.obj");
178
// resetFull();
179
// writeExternalFormToDisk(
180
// (java.io.Serializable) map,
181
// "D:/dev/collections/data/test/SingletonMap.fullCollection.version3.1.obj");
182
// }
183
}
184
Popular Tags