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.iterators;
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.BidiMap;
025: import org.apache.commons.collections.MapIterator;
026: import org.apache.commons.collections.Unmodifiable;
027: import org.apache.commons.collections.bidimap.DualHashBidiMap;
028:
029: /**
030: * Tests the UnmodifiableMapIterator.
031: *
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 TestUnmodifiableMapIterator extends
037: AbstractTestMapIterator {
038:
039: public static Test suite() {
040: return new TestSuite(TestUnmodifiableMapIterator.class);
041: }
042:
043: public TestUnmodifiableMapIterator(String testName) {
044: super (testName);
045: }
046:
047: public MapIterator makeEmptyMapIterator() {
048: return UnmodifiableMapIterator.decorate(new DualHashBidiMap()
049: .mapIterator());
050: }
051:
052: public MapIterator makeFullMapIterator() {
053: return UnmodifiableMapIterator.decorate(((BidiMap) getMap())
054: .mapIterator());
055: }
056:
057: public Map getMap() {
058: Map testMap = new DualHashBidiMap();
059: testMap.put("A", "a");
060: testMap.put("B", "b");
061: testMap.put("C", "c");
062: return testMap;
063: }
064:
065: public Map getConfirmedMap() {
066: Map testMap = new HashMap();
067: testMap.put("A", "a");
068: testMap.put("B", "b");
069: testMap.put("C", "c");
070: return testMap;
071: }
072:
073: public boolean supportsRemove() {
074: return false;
075: }
076:
077: public boolean supportsSetValue() {
078: return false;
079: }
080:
081: //-----------------------------------------------------------------------
082: public void testMapIterator() {
083: assertTrue(makeEmptyMapIterator() instanceof Unmodifiable);
084: }
085:
086: public void testDecorateFactory() {
087: MapIterator it = makeFullMapIterator();
088: assertSame(it, UnmodifiableMapIterator.decorate(it));
089:
090: it = ((BidiMap) getMap()).mapIterator();
091: assertTrue(it != UnmodifiableMapIterator.decorate(it));
092:
093: try {
094: UnmodifiableMapIterator.decorate(null);
095: fail();
096: } catch (IllegalArgumentException ex) {
097: }
098: }
099:
100: }
|