Update tests

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131337 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-11-08 18:47:38 +00:00
parent 533ad6c843
commit 0b990513ea
7 changed files with 147 additions and 226 deletions

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/AbstractTestBidiMap.java,v 1.7 2003/11/02 19:48:39 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/AbstractTestBidiMap.java,v 1.8 2003/11/08 18:46:57 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -69,7 +69,7 @@ import org.apache.commons.collections.iterators.MapIterator;
/**
* Abstract test class for {@link BidiMap} methods and contracts.
*
* @version $Revision: 1.7 $ $Date: 2003/11/02 19:48:39 $
* @version $Revision: 1.8 $ $Date: 2003/11/08 18:46:57 $
*
* @author Matthew Hawthorne
* @author Stephen Colebourne
@ -242,6 +242,8 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
//-----------------------------------------------------------------------
public void testBidiModifyEntrySet() {
if (isSetValueSupported() == false) return;
modifyEntrySet(makeFullBidiMap());
modifyEntrySet(makeFullBidiMap().inverseBidiMap());
}
@ -288,8 +290,8 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
remove(makeFullBidiMap(), entries[0][0]);
remove(makeFullBidiMap().inverseBidiMap(), entries[0][1]);
removeKey(makeFullBidiMap(), entries[0][1]);
removeKey(makeFullBidiMap().inverseBidiMap(), entries[0][0]);
removeValue(makeFullBidiMap(), entries[0][1]);
removeValue(makeFullBidiMap().inverseBidiMap(), entries[0][0]);
}
private final void remove(BidiMap map, Object key) {
@ -298,8 +300,8 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
assertNull("Value was not removed.", map.getKey(value));
}
private final void removeKey(BidiMap map, Object value) {
final Object key = map.removeKey(value);
private final void removeValue(BidiMap map, Object value) {
final Object key = map.removeValue(value);
assertTrue("Key was not removed.", !map.containsKey(key));
assertNull("Value was not removed.", map.getKey(value));
}
@ -484,8 +486,8 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
super("TestBidiMapIterator");
}
protected Object addSetValue() {
return AbstractTestBidiMap.this.getNewSampleValues()[0];
protected Object[] addSetValues() {
return AbstractTestBidiMap.this.getNewSampleValues();
}
protected boolean supportsRemove() {
@ -511,41 +513,17 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
return AbstractTestBidiMap.this.map;
}
protected Map getConfirmedMap() {
// assumes makeFullMapIterator() called first
return AbstractTestBidiMap.this.confirmed;
}
protected void verify() {
super.verify();
AbstractTestBidiMap.this.verifyInverse();
AbstractTestBidiMap.this.verify();
}
}
//-----------------------------------------------------------------------
public void testBidiMapIteratorRemove() {
resetFull();
BidiMap bidi = (BidiMap) map;
MapIterator it = bidi.mapIterator();
assertEquals(true, it.hasNext());
Object key = it.next();
if (isRemoveSupported() == false) {
try {
it.remove();
fail();
} catch (UnsupportedOperationException ex) {
}
return;
}
it.remove();
confirmed.remove(key);
assertEquals(false, bidi.containsKey(key));
verify();
try {
it.remove(); // second remove fails
} catch (IllegalStateException ex) {
}
verify();
}
//-----------------------------------------------------------------------
public void testBidiMapIteratorSet() {
Object newValue1 = getOtherValues()[0];

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestFlat3Map.java,v 1.1 2003/11/02 23:41:46 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestFlat3Map.java,v 1.2 2003/11/08 18:46:57 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -68,7 +68,7 @@ import org.apache.commons.collections.iterators.MapIterator;
/**
* JUnit tests.
*
* @version $Revision: 1.1 $ $Date: 2003/11/02 23:41:46 $
* @version $Revision: 1.2 $ $Date: 2003/11/08 18:46:57 $
*
* @author Stephen Colebourne
*/
@ -100,8 +100,8 @@ public class TestFlat3Map extends AbstractTestMap {
super("TestFlatMapIterator");
}
protected Object addSetValue() {
return TestFlat3Map.this.getNewSampleValues()[0];
protected Object[] addSetValues() {
return TestFlat3Map.this.getNewSampleValues();
}
protected boolean supportsRemove() {
@ -127,88 +127,14 @@ public class TestFlat3Map extends AbstractTestMap {
return TestFlat3Map.this.map;
}
protected Map getConfirmedMap() {
// assumes makeFullMapIterator() called first
return TestFlat3Map.this.confirmed;
}
protected void verify() {
super.verify();
// cannot cross verify as we don't know what superclass did
TestFlat3Map.this.verify();
}
}
//-----------------------------------------------------------------------
public void testMapIteratorRemove() {
resetFull();
Flat3Map testMap = (Flat3Map) map;
MapIterator it = testMap.mapIterator();
assertEquals(true, it.hasNext());
Object key = it.next();
if (isRemoveSupported() == false) {
try {
it.remove();
fail();
} catch (UnsupportedOperationException ex) {
}
return;
}
it.remove();
confirmed.remove(key);
assertEquals(false, testMap.containsKey(key));
verify();
try {
it.remove(); // second remove fails
} catch (IllegalStateException ex) {
}
verify();
}
//-----------------------------------------------------------------------
public void testMapIteratorSet() {
Object newValue1 = getOtherValues()[0];
Object newValue2 = getOtherValues()[1];
resetFull();
Flat3Map testMap = (Flat3Map) map;
MapIterator it = testMap.mapIterator();
assertEquals(true, it.hasNext());
Object key1 = it.next();
if (isSetValueSupported() == false) {
try {
it.setValue(newValue1);
fail();
} catch (UnsupportedOperationException ex) {
}
return;
}
it.setValue(newValue1);
confirmed.put(key1, newValue1);
assertSame(key1, it.getKey());
assertSame(newValue1, it.getValue());
assertEquals(true, testMap.containsKey(key1));
assertEquals(true, testMap.containsValue(newValue1));
assertEquals(newValue1, testMap.get(key1));
verify();
it.setValue(newValue1); // same value - should be OK
confirmed.put(key1, newValue1);
assertSame(key1, it.getKey());
assertSame(newValue1, it.getValue());
assertEquals(true, testMap.containsKey(key1));
assertEquals(true, testMap.containsValue(newValue1));
assertEquals(newValue1, testMap.get(key1));
verify();
Object key2 = it.next();
it.setValue(newValue2);
confirmed.put(key2, newValue2);
assertSame(key2, it.getKey());
assertSame(newValue2, it.getValue());
assertEquals(true, testMap.containsKey(key2));
assertEquals(true, testMap.containsValue(newValue2));
assertEquals(newValue2, testMap.get(key2));
verify();
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestIteratorUtils.java,v 1.8 2003/11/02 15:27:54 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestIteratorUtils.java,v 1.9 2003/11/08 18:47:38 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -66,13 +66,17 @@ import java.util.NoSuchElementException;
import junit.framework.Test;
import org.apache.commons.collections.iterators.MapIterator;
import org.apache.commons.collections.iterators.OrderedMapIterator;
import org.apache.commons.collections.iterators.ResetableIterator;
import org.apache.commons.collections.iterators.ResetableListIterator;
import org.apache.commons.collections.iterators.ResetableMapIterator;
import org.apache.commons.collections.iterators.ResetableOrderedMapIterator;
/**
* Tests for IteratorUtils.
*
* @version $Revision: 1.8 $ $Date: 2003/11/02 15:27:54 $
* @version $Revision: 1.9 $ $Date: 2003/11/08 18:47:38 $
*
* @author Unknown
*/
@ -429,6 +433,8 @@ public class TestIteratorUtils extends BulkTest {
* Test empty iterator
*/
public void testEmptyIterator() {
assertTrue(IteratorUtils.EMPTY_ITERATOR instanceof Iterator);
assertTrue(IteratorUtils.EMPTY_ITERATOR instanceof ResetableIterator);
assertEquals(false, IteratorUtils.EMPTY_ITERATOR.hasNext());
IteratorUtils.EMPTY_ITERATOR.reset();
assertSame(IteratorUtils.EMPTY_ITERATOR, IteratorUtils.EMPTY_ITERATOR);
@ -448,6 +454,10 @@ public class TestIteratorUtils extends BulkTest {
* Test empty list iterator
*/
public void testEmptyListIterator() {
assertTrue(IteratorUtils.EMPTY_LIST_ITERATOR instanceof Iterator);
assertTrue(IteratorUtils.EMPTY_LIST_ITERATOR instanceof ListIterator);
assertTrue(IteratorUtils.EMPTY_LIST_ITERATOR instanceof ResetableIterator);
assertTrue(IteratorUtils.EMPTY_LIST_ITERATOR instanceof ResetableListIterator);
assertEquals(false, IteratorUtils.EMPTY_LIST_ITERATOR.hasNext());
assertEquals(0, IteratorUtils.EMPTY_LIST_ITERATOR.nextIndex());
assertEquals(-1, IteratorUtils.EMPTY_LIST_ITERATOR.previousIndex());
@ -481,6 +491,10 @@ public class TestIteratorUtils extends BulkTest {
* Test empty map iterator
*/
public void testEmptyMapIterator() {
assertTrue(IteratorUtils.EMPTY_MAP_ITERATOR instanceof Iterator);
assertTrue(IteratorUtils.EMPTY_MAP_ITERATOR instanceof MapIterator);
assertTrue(IteratorUtils.EMPTY_MAP_ITERATOR instanceof ResetableIterator);
assertTrue(IteratorUtils.EMPTY_MAP_ITERATOR instanceof ResetableMapIterator);
assertEquals(false, IteratorUtils.EMPTY_MAP_ITERATOR.hasNext());
IteratorUtils.EMPTY_MAP_ITERATOR.reset();
assertSame(IteratorUtils.EMPTY_MAP_ITERATOR, IteratorUtils.EMPTY_MAP_ITERATOR);
@ -505,8 +519,46 @@ public class TestIteratorUtils extends BulkTest {
IteratorUtils.EMPTY_MAP_ITERATOR.setValue(null);
fail();
} catch (IllegalStateException ex) {}
}
//-----------------------------------------------------------------------
/**
* Test empty map iterator
*/
public void testEmptyOrderedMapIterator() {
assertTrue(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof Iterator);
assertTrue(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof MapIterator);
assertTrue(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof OrderedMapIterator);
assertTrue(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof ResetableIterator);
assertTrue(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof ResetableMapIterator);
assertTrue(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof ResetableOrderedMapIterator);
assertEquals(false, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.hasNext());
assertEquals(false, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.hasPrevious());
IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.reset();
assertSame(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR);
assertSame(IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR, IteratorUtils.emptyOrderedMapIterator());
try {
IteratorUtils.EMPTY_MAP_ITERATOR.asMapEntry();
IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.next();
fail();
} catch (NoSuchElementException ex) {}
try {
IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.previous();
fail();
} catch (NoSuchElementException ex) {}
try {
IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.remove();
fail();
} catch (IllegalStateException ex) {}
try {
IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.getKey();
fail();
} catch (IllegalStateException ex) {}
try {
IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.getValue();
fail();
} catch (IllegalStateException ex) {}
try {
IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR.setValue(null);
fail();
} catch (IllegalStateException ex) {}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestOrderedMap.java,v 1.3 2003/11/04 23:36:23 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestOrderedMap.java,v 1.4 2003/11/08 18:46:57 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -76,7 +76,7 @@ import org.apache.commons.collections.iterators.MapIterator;
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/11/04 23:36:23 $
* @version $Revision: 1.4 $ $Date: 2003/11/08 18:46:57 $
*
* @author Henri Yandell
* @author Stephen Colebourne
@ -136,6 +136,16 @@ public class TestOrderedMap extends AbstractTestMap {
// assumes makeFullMapIterator() called first
return TestOrderedMap.this.map;
}
protected Map getConfirmedMap() {
// assumes makeFullMapIterator() called first
return TestOrderedMap.this.confirmed;
}
protected void verify() {
super.verify();
TestOrderedMap.this.verify();
}
}
//-----------------------------------------------------------------------

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java,v 1.3 2003/11/02 19:47:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java,v 1.4 2003/11/08 18:46:57 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -71,7 +71,7 @@ import org.apache.commons.collections.AbstractTestObject;
* overriding the supportsXxx() methods if necessary.
*
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/11/02 19:47:10 $
* @version $Revision: 1.4 $ $Date: 2003/11/08 18:46:57 $
*
* @author Morgan Delagrange
* @author Stephen Colebourne
@ -229,14 +229,12 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
// remove after next should be fine
it.next();
it.remove();
verify();
// should throw IllegalStateException for second remove()
try {
it.remove();
fail();
} catch (IllegalStateException ex) {}
verify();
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java,v 1.2 2003/11/02 19:47:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java,v 1.3 2003/11/08 18:46:57 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -62,7 +62,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Map.Entry;
/**
* Abstract class for testing the MapIterator interface.
@ -73,7 +72,7 @@ import java.util.Map.Entry;
* overriding the supportsXxx() methods if necessary.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/11/02 19:47:10 $
* @version $Revision: 1.3 $ $Date: 2003/11/08 18:46:57 $
*
* @author Stephen Colebourne
*/
@ -112,14 +111,13 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
protected abstract Map getMap();
/**
* Override if the map returned by getMap() is NOT the one tied to the iterator.
* Implement this method to return the confirmed map which contains the same
* data as the iterator.
*
* @return true if the getMap() map is the one tied to the iterator
* @return a full map which can be updated
*/
protected boolean supportsTiedMap() {
return true;
}
protected abstract Map getConfirmedMap();
/**
* Implements the abstract superclass method to return the list iterator.
*
@ -149,11 +147,11 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
}
/**
* The value to be used in the add and set tests.
* Default is null.
* The values to be used in the add and set tests.
* Default is two strings.
*/
protected Object addSetValue() {
return null;
protected Object[] addSetValues() {
return new Object[] {"A", "B"};
}
//-----------------------------------------------------------------------
@ -187,23 +185,17 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
fail();
} catch (IllegalStateException ex) {}
// asMapEntry() should throw an IllegalStateException
try {
it.asMapEntry();
fail();
} catch (IllegalStateException ex) {}
if (supportsSetValue() == false) {
// setValue() should throw an UnsupportedOperationException/IllegalStateException
try {
it.setValue(addSetValue());
it.setValue(addSetValues()[0]);
fail();
} catch (UnsupportedOperationException ex) {
} catch (IllegalStateException ex) {}
} else {
// setValue() should throw an IllegalStateException
try {
it.setValue(addSetValue());
it.setValue(addSetValues()[0]);
fail();
} catch (IllegalStateException ex) {}
}
@ -223,9 +215,6 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
assertEquals(true, it.hasNext());
assertEquals(true, it.hasNext());
Map.Entry lastEntry = null;
Object lastKey = null;
Object lastValue = null;
Set set = new HashSet();
while (it.hasNext()) {
// getKey
@ -239,21 +228,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
assertSame("Value must be mapped to key", map.get(key), value);
assertTrue("Value must be in map", map.containsValue(value));
assertSame("Value must be mapped to key", map.get(key), value);
// asMapEntry
Map.Entry entry = it.asMapEntry();
assertSame("MapEntry key must match", key, entry.getKey());
assertSame("MapEntry value must match", value, entry.getValue());
assertTrue("MapEntry must be independent", entry != lastEntry);
if (lastKey != null && lastValue != null) {
assertSame("MapEntry must not change after next()", lastKey, lastEntry.getKey());
assertSame("MapEntry must not change after next()", lastValue, lastEntry.getValue());
}
lastEntry = entry;
lastKey = key;
lastValue = value;
verify();
}
}
@ -264,13 +239,14 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
return;
}
Object newValue = addSetValue();
Object newValue = addSetValues()[0];
Object newValue2 = addSetValues()[1];
MapIterator it = makeFullMapIterator();
Map map = getMap();
Map confirmed = getConfirmedMap();
assertEquals(true, it.hasNext());
Object key = it.next();
Object value = it.getValue();
Entry entry = it.asMapEntry();
if (supportsSetValue() == false) {
try {
@ -281,97 +257,70 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
}
Object old = it.setValue(newValue);
confirmed.put(key, newValue);
assertSame("Key must not change after setValue", key, it.getKey());
assertSame("Key must not change after setValue", key, entry.getKey());
assertSame("Value must be changed after setValue", newValue, it.getValue());
assertSame("Value must be changed after setValue", newValue, entry.getValue());
assertSame("setValue must return old value", value, old);
if (supportsTiedMap()) {
assertTrue("Key must be in map", map.containsKey(key));
assertTrue("Old value must not be in map", map.containsValue(value) == false);
assertTrue("Value must be in map", map.containsValue(newValue));
assertSame("Value must be mapped to key", map.get(key), newValue);
}
verify();
it.setValue(newValue); // same value - should be OK
confirmed.put(key, newValue);
assertSame("Key must not change after setValue", key, it.getKey());
assertSame("Key must not change after setValue", key, entry.getKey());
assertSame("Value must be changed after setValue", newValue, it.getValue());
assertSame("Value must be changed after setValue", newValue, entry.getValue());
if (supportsTiedMap()) {
assertTrue("Key must be in map", map.containsKey(key));
assertTrue("Old value must not be in map", map.containsValue(value) == false);
assertTrue("Value must be in map", map.containsValue(newValue));
assertSame("Value must be mapped to key", map.get(key), newValue);
}
verify();
it.setValue(newValue2); // new value
confirmed.put(key, newValue2);
assertSame("Key must not change after setValue", key, it.getKey());
assertSame("Value must be changed after setValue", newValue2, it.getValue());
verify();
}
//-----------------------------------------------------------------------
public void testMapIteratorMapEntrySet() {
if (supportsFullIterator() == false) {
return;
}
Object newValue = addSetValue();
public void testRemove() { // override
MapIterator it = makeFullMapIterator();
Map map = getMap();
Map confirmed = getConfirmedMap();
assertEquals(true, it.hasNext());
Object key = it.next();
Object value = it.getValue();
Entry entry = it.asMapEntry();
if (supportsSetValue() == false) {
if (supportsRemove() == false) {
try {
entry.setValue(newValue);
it.remove();
fail();
} catch (UnsupportedOperationException ex) {}
} catch (UnsupportedOperationException ex) {
}
return;
}
Object old = entry.setValue(newValue);
assertSame("Key must not change after setValue", key, it.getKey());
assertSame("Key must not change after setValue", key, entry.getKey());
assertSame("Value must be changed after setValue", newValue, it.getValue());
assertSame("Value must be changed after setValue", newValue, entry.getValue());
assertSame("setValue must return old value", value, old);
if (supportsTiedMap()) {
assertTrue("Key must be in map", map.containsKey(key));
assertTrue("Old value must not be in map", map.containsValue(value) == false);
assertTrue("Value must be in map", map.containsValue(newValue));
assertSame("Value must be mapped to key", map.get(key), newValue);
}
it.remove();
confirmed.remove(key);
assertEquals(false, map.containsKey(key));
verify();
entry.setValue(newValue); // same value - should be OK
assertSame("Key must not change after setValue", key, it.getKey());
assertSame("Key must not change after setValue", key, entry.getKey());
assertSame("Value must be changed after setValue", newValue, it.getValue());
assertSame("Value must be changed after setValue", newValue, entry.getValue());
if (supportsTiedMap()) {
assertTrue("Key must be in map", map.containsKey(key));
assertTrue("Old value must not be in map", map.containsValue(value) == false);
assertTrue("Value must be in map", map.containsValue(newValue));
assertSame("Value must be mapped to key", map.get(key), newValue);
try {
it.remove(); // second remove fails
} catch (IllegalStateException ex) {
}
verify();
}
//-----------------------------------------------------------------------
public void testBidiMapIteratorSetRemoveSet() {
public void testMapIteratorSetRemoveSet() {
if (supportsSetValue() == false || supportsRemove() == false) {
return;
}
Object newValue = addSetValue();
Object newValue = addSetValues()[0];
MapIterator it = makeFullMapIterator();
Map map = getMap();
Map confirmed = getConfirmedMap();
assertEquals(true, it.hasNext());
Object key = it.next();
it.setValue(newValue);
it.remove();
confirmed.remove(key);
verify();
try {

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/TestUnmodifiableMapIterator.java,v 1.1 2003/11/02 18:29:59 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/TestUnmodifiableMapIterator.java,v 1.2 2003/11/08 18:46:57 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -57,6 +57,7 @@
*/
package org.apache.commons.collections.iterators;
import java.util.HashMap;
import java.util.Map;
import junit.framework.Test;
@ -69,7 +70,7 @@ import org.apache.commons.collections.Unmodifiable;
/**
* Tests the UnmodifiableMapIterator.
*
* @version $Revision: 1.1 $ $Date: 2003/11/02 18:29:59 $
* @version $Revision: 1.2 $ $Date: 2003/11/08 18:46:57 $
*
* @author Stephen Colebourne
*/
@ -99,6 +100,13 @@ public class TestUnmodifiableMapIterator extends AbstractTestMapIterator {
return testMap;
}
protected Map getConfirmedMap() {
Map testMap = new HashMap();
testMap.put("A", "a");
testMap.put("B", "b");
testMap.put("C", "c");
return testMap;
}
public boolean supportsRemove() {
return false;