From 1bec2d62d76e9ca47236be297ff452ff850dd3f8 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 2 Nov 2003 19:47:10 +0000 Subject: [PATCH] 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 --- .../iterators/AbstractTestIterator.java | 16 ++++++++++++++-- .../iterators/AbstractTestMapIterator.java | 13 +++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java b/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java index fa32ea8fa..b421ddfe7 100644 --- a/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java +++ b/src/test/org/apache/commons/collections/iterators/AbstractTestIterator.java @@ -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(); } } diff --git a/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java b/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java index c66d3d529..2044e3a23 100644 --- a/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java +++ b/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java @@ -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(); } }