commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/iterators TestIterator.java
Date Fri, 13 Dec 2002 12:03:46 GMT
scolebourne    2002/12/13 04:03:46

  Modified:    collections/src/test/org/apache/commons/collections/iterators
                        TestIterator.java
  Log:
  Add test for remove on an iterator
  
  Revision  Changes    Path
  1.2       +52 -16    jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestIterator.java
  
  Index: TestIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestIterator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestIterator.java	15 Aug 2002 23:13:52 -0000	1.1
  +++ TestIterator.java	13 Dec 2002 12:03:46 -0000	1.2
  @@ -58,17 +58,16 @@
    * <http://www.apache.org/>.
    *
    */
  -     
   package org.apache.commons.collections.iterators;
   
   import java.util.Iterator;
   import java.util.NoSuchElementException;
   import org.apache.commons.collections.TestObject;
  -
   /**
    * Base class for tetsing Iterator interface
    * 
    * @author Morgan Delagrange
  + * @author Stephen Colebourne
    */
   public abstract class TestIterator extends TestObject {
   
  @@ -101,6 +100,16 @@
       }
   
       /**
  +     * Whether or not we are testing an iterator that supports
  +     * remove().  Default is true.
  +     * 
  +     * @return true if Iterators can be empty
  +     */
  +    public boolean supportsRemove() {
  +        return true;
  +    }
  +
  +    /**
        * Should throw a NoSuchElementException.
        */
       public void testEmptyIterator() {
  @@ -109,12 +118,12 @@
           }
   
           Iterator iter = makeEmptyIterator();
  -        assertTrue("hasNext() should return false for empty iterators",iter.hasNext() ==
false);
  +        assertTrue("hasNext() should return false for empty iterators", iter.hasNext()
== false);
           try {
  -	    iter.next();
  +            iter.next();
               fail("NoSuchElementException must be thrown when Iterator is exhausted");
  -	} catch (NoSuchElementException e) {
  -	}
  +        } catch (NoSuchElementException e) {
  +        }
       }
   
       /**
  @@ -130,23 +139,50 @@
   
           Iterator iter = makeFullIterator();
   
  -        assertTrue("hasNext() should return true for at least one element",iter.hasNext());
  +        assertTrue("hasNext() should return true for at least one element", iter.hasNext());
   
           try {
  -	    iter.next();
  -	} catch (NoSuchElementException e) {
  +            iter.next();
  +        } catch (NoSuchElementException e) {
               fail("Full iterators must have at least one element");
  -	}
  +        }
   
           while (iter.hasNext()) {
               iter.next();
           }
   
           try {
  -	    iter.next();
  +            iter.next();
               fail("NoSuchElementException must be thrown when Iterator is exhausted");
  -	} catch (NoSuchElementException e) {
  -	}
  +        } catch (NoSuchElementException e) {
  +        }
       }
   
  +    /**
  +     * Test remove
  +     */
  +    public void testRemove() {
  +        Iterator it = makeFullIterator();
  +        
  +        if (supportsRemove() == false) {
  +            try {
  +                it.remove();
  +            } catch (UnsupportedOperationException ex) {}
  +            return;
  +        }
  +        
  +        try {
  +            it.remove();
  +            fail();
  +        } catch (IllegalStateException ex) {}
  +        
  +        it.next();
  +        it.remove();
  +        
  +        try {
  +            it.remove();
  +            fail();
  +        } catch (IllegalStateException ex) {}
  +    }
  +    
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message