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.map;
017:
018: import java.util.ConcurrentModificationException;
019: import java.util.Iterator;
020: import java.util.Map;
021:
022: import org.apache.commons.collections.IterableMap;
023: import org.apache.commons.collections.BulkTest;
024: import org.apache.commons.collections.MapIterator;
025: import org.apache.commons.collections.iterators.AbstractTestMapIterator;
026:
027: /**
028: * Abstract test class for {@link IterableMap} methods and contracts.
029: *
030: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
031: *
032: * @author Stephen Colebourne
033: */
034: public abstract class AbstractTestIterableMap extends AbstractTestMap {
035:
036: /**
037: * JUnit constructor.
038: *
039: * @param testName the test name
040: */
041: public AbstractTestIterableMap(String testName) {
042: super (testName);
043: }
044:
045: //-----------------------------------------------------------------------
046: public void testFailFastEntrySet() {
047: if (isRemoveSupported() == false)
048: return;
049: resetFull();
050: Iterator it = map.entrySet().iterator();
051: Map.Entry val = (Map.Entry) it.next();
052: map.remove(val.getKey());
053: try {
054: it.next();
055: fail();
056: } catch (ConcurrentModificationException ex) {
057: }
058:
059: resetFull();
060: it = map.entrySet().iterator();
061: it.next();
062: map.clear();
063: try {
064: it.next();
065: fail();
066: } catch (ConcurrentModificationException ex) {
067: }
068: }
069:
070: public void testFailFastKeySet() {
071: if (isRemoveSupported() == false)
072: return;
073: resetFull();
074: Iterator it = map.keySet().iterator();
075: Object val = it.next();
076: map.remove(val);
077: try {
078: it.next();
079: fail();
080: } catch (ConcurrentModificationException ex) {
081: }
082:
083: resetFull();
084: it = map.keySet().iterator();
085: it.next();
086: map.clear();
087: try {
088: it.next();
089: fail();
090: } catch (ConcurrentModificationException ex) {
091: }
092: }
093:
094: public void testFailFastValues() {
095: if (isRemoveSupported() == false)
096: return;
097: resetFull();
098: Iterator it = map.values().iterator();
099: it.next();
100: map.remove(map.keySet().iterator().next());
101: try {
102: it.next();
103: fail();
104: } catch (ConcurrentModificationException ex) {
105: }
106:
107: resetFull();
108: it = map.values().iterator();
109: it.next();
110: map.clear();
111: try {
112: it.next();
113: fail();
114: } catch (ConcurrentModificationException ex) {
115: }
116: }
117:
118: //-----------------------------------------------------------------------
119: public BulkTest bulkTestMapIterator() {
120: return new InnerTestMapIterator();
121: }
122:
123: public class InnerTestMapIterator extends AbstractTestMapIterator {
124: public InnerTestMapIterator() {
125: super ("InnerTestMapIterator");
126: }
127:
128: public Object[] addSetValues() {
129: return AbstractTestIterableMap.this .getNewSampleValues();
130: }
131:
132: public boolean supportsRemove() {
133: return AbstractTestIterableMap.this .isRemoveSupported();
134: }
135:
136: public boolean isGetStructuralModify() {
137: return AbstractTestIterableMap.this .isGetStructuralModify();
138: }
139:
140: public boolean supportsSetValue() {
141: return AbstractTestIterableMap.this .isSetValueSupported();
142: }
143:
144: public MapIterator makeEmptyMapIterator() {
145: resetEmpty();
146: return ((IterableMap) AbstractTestIterableMap.this .map)
147: .mapIterator();
148: }
149:
150: public MapIterator makeFullMapIterator() {
151: resetFull();
152: return ((IterableMap) AbstractTestIterableMap.this .map)
153: .mapIterator();
154: }
155:
156: public Map getMap() {
157: // assumes makeFullMapIterator() called first
158: return AbstractTestIterableMap.this .map;
159: }
160:
161: public Map getConfirmedMap() {
162: // assumes makeFullMapIterator() called first
163: return AbstractTestIterableMap.this .confirmed;
164: }
165:
166: public void verify() {
167: super .verify();
168: AbstractTestIterableMap.this .verify();
169: }
170: }
171:
172: // public void testCreate() throws Exception {
173: // resetEmpty();
174: // writeExternalFormToDisk((Serializable) map, "D:/dev/collections/data/test/HashedMap.emptyCollection.version3.obj");
175: // resetFull();
176: // writeExternalFormToDisk((Serializable) map, "D:/dev/collections/data/test/HashedMap.fullCollection.version3.obj");
177: // }
178: }
|