From 05c0b3a792892ab667261c53738dfa9b63fc8c2f Mon Sep 17 00:00:00 2001 From: Rodney Waldhoff Date: Thu, 31 Oct 2002 21:55:23 +0000 Subject: [PATCH] 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 --- .../collections/iterators/IteratorChain.java | 9 +++---- .../iterators/TestIteratorChain.java | 25 ++++++++++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/commons/collections/iterators/IteratorChain.java b/src/java/org/apache/commons/collections/iterators/IteratorChain.java index ebbc33c74..cc46be07b 100644 --- a/src/java/org/apache/commons/collections/iterators/IteratorChain.java +++ b/src/java/org/apache/commons/collections/iterators/IteratorChain.java @@ -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 Stephen Colebourne - * @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)) { diff --git a/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java b/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java index 7c3627d2d..ccd3f4bcb 100644 --- a/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java +++ b/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java @@ -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()); + } }