KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > map > AbstractTestIterableMap


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.map;
17
18 import java.util.ConcurrentModificationException JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.commons.collections.IterableMap;
23 import org.apache.commons.collections.BulkTest;
24 import org.apache.commons.collections.MapIterator;
25 import org.apache.commons.collections.iterators.AbstractTestMapIterator;
26
27 /**
28  * Abstract test class for {@link IterableMap} methods and contracts.
29  *
30  * @version $Revision: 1.4 $ $Date: 2004/02/18 01:20:38 $
31  *
32  * @author Stephen Colebourne
33  */

34 public abstract class AbstractTestIterableMap extends AbstractTestMap {
35
36     /**
37      * JUnit constructor.
38      *
39      * @param testName the test name
40      */

41     public AbstractTestIterableMap(String JavaDoc testName) {
42         super(testName);
43     }
44     
45     //-----------------------------------------------------------------------
46
public void testFailFastEntrySet() {
47         if (isRemoveSupported() == false) return;
48         resetFull();
49         Iterator JavaDoc it = map.entrySet().iterator();
50         Map.Entry JavaDoc val = (Map.Entry JavaDoc) it.next();
51         map.remove(val.getKey());
52         try {
53             it.next();
54             fail();
55         } catch (ConcurrentModificationException JavaDoc ex) {}
56         
57         resetFull();
58         it = map.entrySet().iterator();
59         it.next();
60         map.clear();
61         try {
62             it.next();
63             fail();
64         } catch (ConcurrentModificationException JavaDoc ex) {}
65     }
66     
67     public void testFailFastKeySet() {
68         if (isRemoveSupported() == false) return;
69         resetFull();
70         Iterator JavaDoc it = map.keySet().iterator();
71         Object JavaDoc val = it.next();
72         map.remove(val);
73         try {
74             it.next();
75             fail();
76         } catch (ConcurrentModificationException JavaDoc ex) {}
77         
78         resetFull();
79         it = map.keySet().iterator();
80         it.next();
81         map.clear();
82         try {
83             it.next();
84             fail();
85         } catch (ConcurrentModificationException JavaDoc ex) {}
86     }
87     
88     public void testFailFastValues() {
89         if (isRemoveSupported() == false) return;
90         resetFull();
91         Iterator JavaDoc it = map.values().iterator();
92         it.next();
93         map.remove(map.keySet().iterator().next());
94         try {
95             it.next();
96             fail();
97         } catch (ConcurrentModificationException JavaDoc ex) {}
98         
99         resetFull();
100         it = map.values().iterator();
101         it.next();
102         map.clear();
103         try {
104             it.next();
105             fail();
106         } catch (ConcurrentModificationException JavaDoc ex) {}
107     }
108     
109     //-----------------------------------------------------------------------
110
public BulkTest bulkTestMapIterator() {
111         return new InnerTestMapIterator();
112     }
113     
114     public class InnerTestMapIterator extends AbstractTestMapIterator {
115         public InnerTestMapIterator() {
116             super("InnerTestMapIterator");
117         }
118         
119         public Object JavaDoc[] addSetValues() {
120             return AbstractTestIterableMap.this.getNewSampleValues();
121         }
122         
123         public boolean supportsRemove() {
124             return AbstractTestIterableMap.this.isRemoveSupported();
125         }
126         
127         public boolean isGetStructuralModify() {
128             return AbstractTestIterableMap.this.isGetStructuralModify();
129         }
130
131         public boolean supportsSetValue() {
132             return AbstractTestIterableMap.this.isSetValueSupported();
133         }
134
135         public MapIterator makeEmptyMapIterator() {
136             resetEmpty();
137             return ((IterableMap) AbstractTestIterableMap.this.map).mapIterator();
138         }
139
140         public MapIterator makeFullMapIterator() {
141             resetFull();
142             return ((IterableMap) AbstractTestIterableMap.this.map).mapIterator();
143         }
144         
145         public Map JavaDoc getMap() {
146             // assumes makeFullMapIterator() called first
147
return AbstractTestIterableMap.this.map;
148         }
149         
150         public Map JavaDoc getConfirmedMap() {
151             // assumes makeFullMapIterator() called first
152
return AbstractTestIterableMap.this.confirmed;
153         }
154         
155         public void verify() {
156             super.verify();
157             AbstractTestIterableMap.this.verify();
158         }
159     }
160     
161 // public void testCreate() throws Exception {
162
// resetEmpty();
163
// writeExternalFormToDisk((Serializable) map, "D:/dev/collections/data/test/HashedMap.emptyCollection.version3.obj");
164
// resetFull();
165
// writeExternalFormToDisk((Serializable) map, "D:/dev/collections/data/test/HashedMap.fullCollection.version3.obj");
166
// }
167
}
168
Popular Tags