Enable iterator testing to better integrate with collection/map tests

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131321 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-11-02 19:47:10 +00:00
parent 792b248c3c
commit 1bec2d62d7
2 changed files with 25 additions and 4 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/iterators/AbstractTestIterator.java,v 1.2 2003/10/02 22:14:34 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.3 2003/11/02 19:47:10 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.2 $ $Date: 2003/10/02 22:14:34 $
* @version $Revision: 1.3 $ $Date: 2003/11/02 19:47:10 $
*
* @author Morgan Delagrange
* @author Stephen Colebourne
@ -141,6 +141,13 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
return true;
}
/**
* Allows subclasses to add complex cross verification
*/
protected void verify() {
// do nothing
}
//-----------------------------------------------------------------------
/**
* Test the empty iterator.
@ -161,6 +168,7 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
fail("NoSuchElementException must be thrown when Iterator is exhausted");
} catch (NoSuchElementException e) {
}
verify();
}
/**
@ -186,6 +194,7 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
// iterate through
while (it.hasNext()) {
it.next();
verify();
}
// next() must throw NoSuchElementException now
@ -215,16 +224,19 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
it.remove();
fail();
} catch (IllegalStateException ex) {}
verify();
// 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.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/AbstractTestMapIterator.java,v 1.2 2003/11/02 19:47:10 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -73,7 +73,7 @@ import java.util.Map.Entry;
* overriding the supportsXxx() methods if necessary.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/11/02 18:29:59 $
* @version $Revision: 1.2 $ $Date: 2003/11/02 19:47:10 $
*
* @author Stephen Colebourne
*/
@ -166,6 +166,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
}
MapIterator it = makeEmptyMapIterator();
Map map = getMap();
assertEquals(false, it.hasNext());
// next() should throw a NoSuchElementException
@ -253,6 +254,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
lastEntry = entry;
lastKey = key;
lastValue = value;
verify();
}
}
@ -290,6 +292,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
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
assertSame("Key must not change after setValue", key, it.getKey());
@ -302,6 +305,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
assertTrue("Value must be in map", map.containsValue(newValue));
assertSame("Value must be mapped to key", map.get(key), newValue);
}
verify();
}
//-----------------------------------------------------------------------
@ -338,6 +342,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
assertTrue("Value must be in map", map.containsValue(newValue));
assertSame("Value must be mapped to key", map.get(key), newValue);
}
verify();
entry.setValue(newValue); // same value - should be OK
assertSame("Key must not change after setValue", key, it.getKey());
@ -350,6 +355,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
assertTrue("Value must be in map", map.containsValue(newValue));
assertSame("Value must be mapped to key", map.get(key), newValue);
}
verify();
}
//-----------------------------------------------------------------------
@ -360,16 +366,19 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
Object newValue = addSetValue();
MapIterator it = makeFullMapIterator();
Map map = getMap();
assertEquals(true, it.hasNext());
Object key = it.next();
it.setValue(newValue);
it.remove();
verify();
try {
it.setValue(newValue);
fail();
} catch (IllegalStateException ex) {}
verify();
}
}