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