You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/01/31 00:11:58 UTC

cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/iterators TestFilterIterator.java TestUniqueFilterIterator.java

scolebourne    2003/01/30 15:11:58

  Modified:    collections/src/test/org/apache/commons/collections/iterators
                        TestFilterIterator.java
                        TestUniqueFilterIterator.java
  Log:
  Enable remove() in FilterIterator
  from Ralph Wagner
  
  Revision  Changes    Path
  1.5       +30 -21    jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java
  
  Index: TestFilterIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestFilterIterator.java	13 Dec 2002 12:03:06 -0000	1.4
  +++ TestFilterIterator.java	30 Jan 2003 23:11:58 -0000	1.5
  @@ -1,13 +1,10 @@
   /*
    * $Header$
  - * $Revision$
  - * $Date$
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-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
  @@ -58,20 +55,25 @@
    * <http://www.apache.org/>.
    *
    */
  -
  -
  -// TestFilterIterator.java 
   package org.apache.commons.collections.iterators;
   
  -import junit.framework.TestSuite;
  -import junit.framework.Test;
  +import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.Iterator;
  +import java.util.List;
   import java.util.NoSuchElementException;
  +
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +
   import org.apache.commons.collections.Predicate;
   
   /**
  + * Test the filter iterator.
    *
    * @author  Jan Sorensen
  + * @author Ralph Wagner
  + * @version $Revision$ $Date$
    */
   public class TestFilterIterator extends TestIterator {
   
  @@ -81,6 +83,7 @@
       }
   
       private String[] array;
  +    private List list;
       private FilterIterator iterator;
       /**
        * Set up instance variables required by this test case.
  @@ -121,18 +124,15 @@
        * @return 
        */
       public Iterator makeFullIterator() {
  -        return makePassThroughFilter(new ArrayIterator(array));
  +        array = new String[] { "a", "b", "c" };
  +        list = new ArrayList(Arrays.asList(array));
  +        return makePassThroughFilter(list.iterator());
       }
   
       public Object makeObject() {
           return makeFullIterator();
       }
   
  -    public boolean supportsRemove() {
  -        return false;
  -    }
  -
  -
       public void testRepeatedHasNext() {
           for (int i = 0; i <= array.length; i++) {
               assertTrue(iterator.hasNext());
  @@ -184,10 +184,19 @@
               assertTrue(i == elements.length - 1 ? !iterator.hasNext() : iterator.hasNext());
           }
           verifyNoMoreElements();
  +
  +        // test removal
  +        initIterator();
  +        iterator.setPredicate(pred);
  +        if (iterator.hasNext()) {
  +            Object last = iterator.next();
  +            iterator.remove();
  +            assertTrue("Base of FilterIterator still contains removed element.", !list.contains(last));
  +        }
       }
   
       private void initIterator() {
  -        iterator = makePassThroughFilter(new ArrayIterator(array));
  +        iterator = (FilterIterator) makeFullIterator();
       }
   
       /**
  
  
  
  1.3       +8 -23     jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestUniqueFilterIterator.java
  
  Index: TestUniqueFilterIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/iterators/TestUniqueFilterIterator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestUniqueFilterIterator.java	12 Oct 2002 22:36:23 -0000	1.2
  +++ TestUniqueFilterIterator.java	30 Jan 2003 23:11:58 -0000	1.3
  @@ -1,13 +1,10 @@
   /*
    * $Header$
  - * $Revision$
  - * $Date$
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-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
  @@ -58,7 +55,6 @@
    * <http://www.apache.org/>.
    *
    */
  -
   package org.apache.commons.collections.iterators;
   
   import java.util.ArrayList;
  @@ -77,7 +73,8 @@
    * @author James Strachan
    * @author Mauricio S. Moura
    * @author Morgan Delagrange
  - * @version $Id$
  + * @author Stephen Colebourne
  + * @version $Revision$ $Date$
    */
   public class TestUniqueFilterIterator extends TestIterator {
   
  @@ -144,18 +141,6 @@
               assertTrue("NoSuchElementException must be thrown", 
                          e.getClass().equals((new NoSuchElementException()).getClass()));
           }
  -    }
  -
  -    public void testRemove() {
  -        Iterator iter = (Iterator) makeFullIterator();
  -
  -        try {
  -            iter.remove();
  -            fail("FilterIterator does not support the remove() method");
  -        } catch (UnsupportedOperationException e) {
  -
  -        }
  -
       }
   
   }
  
  
  

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