001: /*
002: * Copyright 2003-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.framework.TestSuite;
023:
024: import org.apache.commons.collections.Unmodifiable;
025:
026: /**
027: * Extension of {@link AbstractTestMap} for exercising the
028: * {@link UnmodifiableMap} implementation.
029: *
030: * @since Commons Collections 3.0
031: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
032: *
033: * @author Phil Steitz
034: */
035: public class TestUnmodifiableMap extends AbstractTestIterableMap {
036:
037: public TestUnmodifiableMap(String testName) {
038: super (testName);
039: }
040:
041: public static Test suite() {
042: return new TestSuite(TestUnmodifiableMap.class);
043: }
044:
045: public static void main(String args[]) {
046: String[] testCaseName = { TestUnmodifiableMap.class.getName() };
047: junit.textui.TestRunner.main(testCaseName);
048: }
049:
050: //-------------------------------------------------------------------
051:
052: public Map makeEmptyMap() {
053: return UnmodifiableMap.decorate(new HashMap());
054: }
055:
056: public boolean isPutChangeSupported() {
057: return false;
058: }
059:
060: public boolean isPutAddSupported() {
061: return false;
062: }
063:
064: public boolean isRemoveSupported() {
065: return false;
066: }
067:
068: public Map makeFullMap() {
069: Map m = new HashMap();
070: addSampleMappings(m);
071: return UnmodifiableMap.decorate(m);
072: }
073:
074: //-----------------------------------------------------------------------
075: public void testUnmodifiable() {
076: assertTrue(makeEmptyMap() instanceof Unmodifiable);
077: assertTrue(makeFullMap() instanceof Unmodifiable);
078: }
079:
080: public void testDecorateFactory() {
081: Map map = makeFullMap();
082: assertSame(map, UnmodifiableMap.decorate(map));
083:
084: try {
085: UnmodifiableMap.decorate(null);
086: fail();
087: } catch (IllegalArgumentException ex) {
088: }
089: }
090:
091: public String getCompatibilityVersion() {
092: return "3.1";
093: }
094:
095: // public void testCreate() throws Exception {
096: // resetEmpty();
097: // writeExternalFormToDisk(
098: // (java.io.Serializable) map,
099: // "D:/dev/collections/data/test/UnmodifiableMap.emptyCollection.version3.1.obj");
100: // resetFull();
101: // writeExternalFormToDisk(
102: // (java.io.Serializable) map,
103: // "D:/dev/collections/data/test/UnmodifiableMap.fullCollection.version3.1.obj");
104: // }
105: }
|