Test Unmodifiable/Resetable combination iterators

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130954 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-01-15 22:02:33 +00:00
parent 7c3665288a
commit 4f55140322
1 changed files with 39 additions and 9 deletions

View File

@ -1,13 +1,10 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestIteratorUtils.java,v 1.3 2002/12/08 15:42:35 scolebourne Exp $
* $Revision: 1.3 $
* $Date: 2002/12/08 15:42:35 $
*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestIteratorUtils.java,v 1.4 2003/01/15 22:02:33 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -23,11 +20,11 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
@ -36,7 +33,7 @@
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -67,6 +64,9 @@ import java.util.List;
import java.util.ListIterator;
import junit.framework.Test;
import org.apache.commons.collections.iterators.ResetableIterator;
import org.apache.commons.collections.iterators.ResetableListIterator;
/**
* Tests for IteratorUtils.
*/
@ -160,6 +160,21 @@ public class TestIteratorUtils extends BulkTest {
assertTrue(!iterator.hasNext());
}
/**
* Test resetability
*/
public void testResetableUnmodifiableIterator() {
Integer four = new Integer(4);
ResetableIterator it = (ResetableIterator)
IteratorUtils.unmodifiableIterator(IteratorUtils.singletonIterator(four));
assertEquals(true, it.hasNext());
assertSame(four, it.next());
assertEquals(false, it.hasNext());
it.reset();
assertEquals(true, it.hasNext());
}
/**
* Test next(), hasNext(), previous() and hasPrevious() for an immutable
* ListIterator.
@ -211,6 +226,21 @@ public class TestIteratorUtils extends BulkTest {
assertTrue(listIterator.hasNext());
}
/**
* Test resetability
*/
public void testResetableUnmodifiableListIterator() {
Integer four = new Integer(4);
ResetableListIterator it = (ResetableListIterator)
IteratorUtils.unmodifiableListIterator(IteratorUtils.singletonListIterator(four));
assertEquals(true, it.hasNext());
assertSame(four, it.next());
assertEquals(false, it.hasNext());
it.reset();
assertEquals(true, it.hasNext());
}
/**
* Test remove() for an immutable Iterator.
*/