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: import java.util.TreeMap;
021:
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024:
025: import org.apache.commons.collections.MapIterator;
026: import org.apache.commons.collections.OrderedMap;
027: import org.apache.commons.collections.OrderedMapIterator;
028: import org.apache.commons.collections.Unmodifiable;
029: import org.apache.commons.collections.map.ListOrderedMap;
030:
031: /**
032: * Tests the UnmodifiableOrderedMapIterator.
033: *
034: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
035: *
036: * @author Stephen Colebourne
037: */
038: public class TestUnmodifiableOrderedMapIterator extends
039: AbstractTestOrderedMapIterator {
040:
041: public static Test suite() {
042: return new TestSuite(TestUnmodifiableOrderedMapIterator.class);
043: }
044:
045: public TestUnmodifiableOrderedMapIterator(String testName) {
046: super (testName);
047: }
048:
049: public MapIterator makeEmptyMapIterator() {
050: return UnmodifiableOrderedMapIterator.decorate(ListOrderedMap
051: .decorate(new HashMap()).orderedMapIterator());
052: }
053:
054: public MapIterator makeFullMapIterator() {
055: return UnmodifiableOrderedMapIterator
056: .decorate(((OrderedMap) getMap()).orderedMapIterator());
057: }
058:
059: public Map getMap() {
060: Map testMap = ListOrderedMap.decorate(new HashMap());
061: testMap.put("A", "a");
062: testMap.put("B", "b");
063: testMap.put("C", "c");
064: return testMap;
065: }
066:
067: public Map getConfirmedMap() {
068: Map testMap = new TreeMap();
069: testMap.put("A", "a");
070: testMap.put("B", "b");
071: testMap.put("C", "c");
072: return testMap;
073: }
074:
075: public boolean supportsRemove() {
076: return false;
077: }
078:
079: public boolean supportsSetValue() {
080: return false;
081: }
082:
083: //-----------------------------------------------------------------------
084: public void testOrderedMapIterator() {
085: assertTrue(makeEmptyOrderedMapIterator() instanceof Unmodifiable);
086: }
087:
088: public void testDecorateFactory() {
089: OrderedMapIterator it = makeFullOrderedMapIterator();
090: assertSame(it, UnmodifiableOrderedMapIterator.decorate(it));
091:
092: it = ((OrderedMap) getMap()).orderedMapIterator();
093: assertTrue(it != UnmodifiableOrderedMapIterator.decorate(it));
094:
095: try {
096: UnmodifiableOrderedMapIterator.decorate(null);
097: fail();
098: } catch (IllegalArgumentException ex) {
099: }
100: }
101:
102: }
|