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:
parent
792b248c3c
commit
1bec2d62d7
|
@ -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
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -71,7 +71,7 @@ import org.apache.commons.collections.AbstractTestObject;
|
||||||
* overriding the supportsXxx() methods if necessary.
|
* overriding the supportsXxx() methods if necessary.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @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 Morgan Delagrange
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
|
@ -141,6 +141,13 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows subclasses to add complex cross verification
|
||||||
|
*/
|
||||||
|
protected void verify() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* Test the empty iterator.
|
* Test the empty iterator.
|
||||||
|
@ -161,6 +168,7 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
|
||||||
fail("NoSuchElementException must be thrown when Iterator is exhausted");
|
fail("NoSuchElementException must be thrown when Iterator is exhausted");
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
}
|
}
|
||||||
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,6 +194,7 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
|
||||||
// iterate through
|
// iterate through
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
// next() must throw NoSuchElementException now
|
// next() must throw NoSuchElementException now
|
||||||
|
@ -215,16 +224,19 @@ public abstract class AbstractTestIterator extends AbstractTestObject {
|
||||||
it.remove();
|
it.remove();
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException ex) {}
|
} catch (IllegalStateException ex) {}
|
||||||
|
verify();
|
||||||
|
|
||||||
// remove after next should be fine
|
// remove after next should be fine
|
||||||
it.next();
|
it.next();
|
||||||
it.remove();
|
it.remove();
|
||||||
|
verify();
|
||||||
|
|
||||||
// should throw IllegalStateException for second remove()
|
// should throw IllegalStateException for second remove()
|
||||||
try {
|
try {
|
||||||
it.remove();
|
it.remove();
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException ex) {}
|
} catch (IllegalStateException ex) {}
|
||||||
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -73,7 +73,7 @@ import java.util.Map.Entry;
|
||||||
* overriding the supportsXxx() methods if necessary.
|
* overriding the supportsXxx() methods if necessary.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @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
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
|
@ -166,6 +166,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
MapIterator it = makeEmptyMapIterator();
|
MapIterator it = makeEmptyMapIterator();
|
||||||
|
Map map = getMap();
|
||||||
assertEquals(false, it.hasNext());
|
assertEquals(false, it.hasNext());
|
||||||
|
|
||||||
// next() should throw a NoSuchElementException
|
// next() should throw a NoSuchElementException
|
||||||
|
@ -253,6 +254,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
|
||||||
lastEntry = entry;
|
lastEntry = entry;
|
||||||
lastKey = key;
|
lastKey = key;
|
||||||
lastValue = value;
|
lastValue = value;
|
||||||
|
verify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +292,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
|
||||||
assertTrue("Value must be in map", map.containsValue(newValue));
|
assertTrue("Value must be in map", map.containsValue(newValue));
|
||||||
assertSame("Value must be mapped to key", map.get(key), newValue);
|
assertSame("Value must be mapped to key", map.get(key), newValue);
|
||||||
}
|
}
|
||||||
|
verify();
|
||||||
|
|
||||||
it.setValue(newValue); // same value - should be OK
|
it.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, it.getKey());
|
||||||
|
@ -302,6 +305,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
|
||||||
assertTrue("Value must be in map", map.containsValue(newValue));
|
assertTrue("Value must be in map", map.containsValue(newValue));
|
||||||
assertSame("Value must be mapped to key", map.get(key), 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));
|
assertTrue("Value must be in map", map.containsValue(newValue));
|
||||||
assertSame("Value must be mapped to key", map.get(key), newValue);
|
assertSame("Value must be mapped to key", map.get(key), newValue);
|
||||||
}
|
}
|
||||||
|
verify();
|
||||||
|
|
||||||
entry.setValue(newValue); // same value - should be OK
|
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, it.getKey());
|
||||||
|
@ -350,6 +355,7 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator {
|
||||||
assertTrue("Value must be in map", map.containsValue(newValue));
|
assertTrue("Value must be in map", map.containsValue(newValue));
|
||||||
assertSame("Value must be mapped to key", map.get(key), 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();
|
Object newValue = addSetValue();
|
||||||
|
|
||||||
MapIterator it = makeFullMapIterator();
|
MapIterator it = makeFullMapIterator();
|
||||||
|
Map map = getMap();
|
||||||
assertEquals(true, it.hasNext());
|
assertEquals(true, it.hasNext());
|
||||||
Object key = it.next();
|
Object key = it.next();
|
||||||
|
|
||||||
it.setValue(newValue);
|
it.setValue(newValue);
|
||||||
it.remove();
|
it.remove();
|
||||||
|
verify();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
it.setValue(newValue);
|
it.setValue(newValue);
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException ex) {}
|
} catch (IllegalStateException ex) {}
|
||||||
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue