001: /*
002: * Copyright 2001-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.map;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import junit.framework.Test;
022: import junit.textui.TestRunner;
023:
024: import org.apache.commons.collections.BoundedMap;
025: import org.apache.commons.collections.BulkTest;
026: import org.apache.commons.collections.KeyValue;
027:
028: /**
029: * JUnit tests.
030: *
031: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
032: *
033: * @author Stephen Colebourne
034: */
035: public class TestSingletonMap extends AbstractTestOrderedMap {
036:
037: private static final Integer ONE = new Integer(1);
038: private static final Integer TWO = new Integer(2);
039: private static final String TEN = "10";
040: private static final String TWENTY = "20";
041:
042: public TestSingletonMap(String testName) {
043: super (testName);
044: }
045:
046: public static void main(String[] args) {
047: TestRunner.run(suite());
048: }
049:
050: public static Test suite() {
051: return BulkTest.makeSuite(TestSingletonMap.class);
052: }
053:
054: //-----------------------------------------------------------------------
055: public Map makeEmptyMap() {
056: // need an empty singleton map, but thats not possible
057: // use a ridiculous fake instead to make the tests pass
058: return UnmodifiableOrderedMap.decorate(ListOrderedMap
059: .decorate(new HashMap()));
060: }
061:
062: public String[] ignoredTests() {
063: // the ridiculous map above still doesn't pass these tests
064: // but its not relevant, so we ignore them
065: return new String[] {
066: "TestSingletonMap.bulkTestMapIterator.testEmptyMapIterator",
067: "TestSingletonMap.bulkTestOrderedMapIterator.testEmptyMapIterator", };
068: }
069:
070: public Map makeFullMap() {
071: return new SingletonMap(ONE, TWO);
072: }
073:
074: public boolean isPutAddSupported() {
075: return false;
076: }
077:
078: public boolean isRemoveSupported() {
079: return false;
080: }
081:
082: public Object[] getSampleKeys() {
083: return new Object[] { ONE };
084: }
085:
086: public Object[] getSampleValues() {
087: return new Object[] { TWO };
088: }
089:
090: public Object[] getNewSampleValues() {
091: return new Object[] { TEN };
092: }
093:
094: //-----------------------------------------------------------------------
095: public void testClone() {
096: SingletonMap map = new SingletonMap(ONE, TWO);
097: assertEquals(1, map.size());
098: SingletonMap cloned = (SingletonMap) map.clone();
099: assertEquals(1, cloned.size());
100: assertEquals(true, cloned.containsKey(ONE));
101: assertEquals(true, cloned.containsValue(TWO));
102: }
103:
104: public void testKeyValue() {
105: SingletonMap map = new SingletonMap(ONE, TWO);
106: assertEquals(1, map.size());
107: assertEquals(ONE, map.getKey());
108: assertEquals(TWO, map.getValue());
109: assertTrue(map instanceof KeyValue);
110: }
111:
112: public void testBoundedMap() {
113: SingletonMap map = new SingletonMap(ONE, TWO);
114: assertEquals(1, map.size());
115: assertEquals(true, map.isFull());
116: assertEquals(1, map.maxSize());
117: assertTrue(map instanceof BoundedMap);
118: }
119:
120: //-----------------------------------------------------------------------
121: // public BulkTest bulkTestMapIterator() {
122: // return new TestFlatMapIterator();
123: // }
124: //
125: // public class TestFlatMapIterator extends AbstractTestOrderedMapIterator {
126: // public TestFlatMapIterator() {
127: // super("TestFlatMapIterator");
128: // }
129: //
130: // public Object[] addSetValues() {
131: // return TestSingletonMap.this.getNewSampleValues();
132: // }
133: //
134: // public boolean supportsRemove() {
135: // return TestSingletonMap.this.isRemoveSupported();
136: // }
137: //
138: // public boolean supportsSetValue() {
139: // return TestSingletonMap.this.isSetValueSupported();
140: // }
141: //
142: // public MapIterator makeEmptyMapIterator() {
143: // resetEmpty();
144: // return ((Flat3Map) TestSingletonMap.this.map).mapIterator();
145: // }
146: //
147: // public MapIterator makeFullMapIterator() {
148: // resetFull();
149: // return ((Flat3Map) TestSingletonMap.this.map).mapIterator();
150: // }
151: //
152: // public Map getMap() {
153: // // assumes makeFullMapIterator() called first
154: // return TestSingletonMap.this.map;
155: // }
156: //
157: // public Map getConfirmedMap() {
158: // // assumes makeFullMapIterator() called first
159: // return TestSingletonMap.this.confirmed;
160: // }
161: //
162: // public void verify() {
163: // super.verify();
164: // TestSingletonMap.this.verify();
165: // }
166: // }
167:
168: public String getCompatibilityVersion() {
169: return "3.1";
170: }
171:
172: // public void testCreate() throws Exception {
173: // resetEmpty();
174: // writeExternalFormToDisk(
175: // (java.io.Serializable) map,
176: // "D:/dev/collections/data/test/SingletonMap.emptyCollection.version3.1.obj");
177: // resetFull();
178: // writeExternalFormToDisk(
179: // (java.io.Serializable) map,
180: // "D:/dev/collections/data/test/SingletonMap.fullCollection.version3.1.obj");
181: // }
182: }
|