fix bug pointed out bu Jonathan Carlson

add test that demonstrates


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130856 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rodney Waldhoff 2002-10-31 21:55:23 +00:00
parent 93e25a6291
commit 05c0b3a792
2 changed files with 25 additions and 9 deletions

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/IteratorChain.java,v 1.2 2002/08/17 11:28:36 scolebourne Exp $
* $Revision: 1.2 $
* $Date: 2002/08/17 11:28:36 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/IteratorChain.java,v 1.3 2002/10/31 21:55:23 rwaldhoff Exp $
* $Revision: 1.3 $
* $Date: 2002/10/31 21:55:23 $
*
* ====================================================================
*
@ -88,7 +88,7 @@ import java.util.NoSuchElementException;
* @since 2.1
* @author Morgan Delagrange
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @version $Id: IteratorChain.java,v 1.2 2002/08/17 11:28:36 scolebourne Exp $
* @version $Id: IteratorChain.java,v 1.3 2002/10/31 21:55:23 rwaldhoff Exp $
*/
public class IteratorChain implements Iterator {
@ -268,7 +268,6 @@ public class IteratorChain implements Iterator {
// set last used iterator here, in case the user calls remove
// before calling hasNext() or next() (although they shouldn't)
lastUsedIterator = currentIterator;
return;
}
if (currentIteratorIndex == (iteratorChain.size() - 1)) {

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java,v 1.2 2002/10/12 22:36:23 scolebourne Exp $
* $Revision: 1.2 $
* $Date: 2002/10/12 22:36:23 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java,v 1.3 2002/10/31 21:55:23 rwaldhoff Exp $
* $Revision: 1.3 $
* $Date: 2002/10/31 21:55:23 $
*
* ====================================================================
*
@ -77,7 +77,7 @@ import junit.framework.TestSuite;
* @author James Strachan
* @author Mauricio S. Moura
* @author Morgan Delagrange
* @version $Id: TestIteratorChain.java,v 1.2 2002/10/12 22:36:23 scolebourne Exp $
* @version $Id: TestIteratorChain.java,v 1.3 2002/10/31 21:55:23 rwaldhoff Exp $
*/
public class TestIteratorChain extends TestIterator {
@ -177,5 +177,22 @@ public class TestIteratorChain extends TestIterator {
assertTrue("List is empty",list3.size() == 0);
}
public void testFirstIteratorIsEmptyBug() {
List empty = new ArrayList();
List notEmpty = new ArrayList();
notEmpty.add("A");
notEmpty.add("B");
notEmpty.add("C");
IteratorChain chain = new IteratorChain();
chain.addIterator(empty.iterator());
chain.addIterator(notEmpty.iterator());
assertTrue("should have next",chain.hasNext());
assertEquals("A",chain.next());
assertTrue("should have next",chain.hasNext());
assertEquals("B",chain.next());
assertTrue("should have next",chain.hasNext());
assertEquals("C",chain.next());
assertTrue("should not have next",!chain.hasNext());
}
}