KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > iterators > TestUnmodifiableOrderedMapIterator


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.iterators;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.TreeMap JavaDoc;
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.commons.collections.MapIterator;
26 import org.apache.commons.collections.OrderedMap;
27 import org.apache.commons.collections.OrderedMapIterator;
28 import org.apache.commons.collections.Unmodifiable;
29 import org.apache.commons.collections.map.ListOrderedMap;
30
31 /**
32  * Tests the UnmodifiableOrderedMapIterator.
33  *
34  * @version $Revision: 1.5 $ $Date: 2004/02/18 01:20:33 $
35  *
36  * @author Stephen Colebourne
37  */

38 public class TestUnmodifiableOrderedMapIterator extends AbstractTestOrderedMapIterator {
39
40     public static Test suite() {
41         return new TestSuite(TestUnmodifiableOrderedMapIterator.class);
42     }
43
44     public TestUnmodifiableOrderedMapIterator(String JavaDoc testName) {
45         super(testName);
46     }
47
48     public MapIterator makeEmptyMapIterator() {
49         return UnmodifiableOrderedMapIterator.decorate(
50             ListOrderedMap.decorate(new HashMap JavaDoc()).orderedMapIterator());
51     }
52
53     public MapIterator makeFullMapIterator() {
54         return UnmodifiableOrderedMapIterator.decorate(
55             ((OrderedMap) getMap()).orderedMapIterator());
56     }
57     
58     public Map JavaDoc getMap() {
59         Map JavaDoc testMap = ListOrderedMap.decorate(new HashMap JavaDoc());
60         testMap.put("A", "a");
61         testMap.put("B", "b");
62         testMap.put("C", "c");
63         return testMap;
64     }
65
66     public Map JavaDoc getConfirmedMap() {
67         Map JavaDoc testMap = new TreeMap JavaDoc();
68         testMap.put("A", "a");
69         testMap.put("B", "b");
70         testMap.put("C", "c");
71         return testMap;
72     }
73
74     public boolean supportsRemove() {
75         return false;
76     }
77
78     public boolean supportsSetValue() {
79         return false;
80     }
81     
82     //-----------------------------------------------------------------------
83
public void testOrderedMapIterator() {
84         assertTrue(makeEmptyOrderedMapIterator() instanceof Unmodifiable);
85     }
86     
87     public void testDecorateFactory() {
88         OrderedMapIterator it = makeFullOrderedMapIterator();
89         assertSame(it, UnmodifiableOrderedMapIterator.decorate(it));
90         
91         it = ((OrderedMap) getMap()).orderedMapIterator() ;
92         assertTrue(it != UnmodifiableOrderedMapIterator.decorate(it));
93         
94         try {
95             UnmodifiableOrderedMapIterator.decorate(null);
96             fail();
97         } catch (IllegalArgumentException JavaDoc ex) {}
98     }
99
100 }
101
Popular Tags