KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23
24 import org.apache.commons.collections.BidiMap;
25 import org.apache.commons.collections.MapIterator;
26 import org.apache.commons.collections.Unmodifiable;
27 import org.apache.commons.collections.bidimap.DualHashBidiMap;
28
29 /**
30  * Tests the UnmodifiableMapIterator.
31  *
32  * @version $Revision: 1.8 $ $Date: 2004/02/18 01:20:33 $
33  *
34  * @author Stephen Colebourne
35  */

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