rwaldhoff    2003/03/03 15:23:40

  Modified:    collections/src/java/org/apache/commons/collections/primitives
                        AbstractIntCollection.java
                        AbstractRandomAccessIntList.java
               collections/src/test/org/apache/commons/collections/primitives
                        TestAll.java TestIntList.java
               collections/src/test/org/apache/commons/collections/primitives/adapters
                        TestIntListIteratorListIterator.java
  Added:       collections/src/test/org/apache/commons/collections/primitives
                        TestAbstractIntCollection.java
                        TestAbstractRandomAccessIntList.java
  Log:
  add tests, make 'em pass ;)
  
  Revision  Changes    Path
  1.5       +2 -17     
jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractIntCollection.java
  
  Index: AbstractIntCollection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractIntCollection.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractIntCollection.java        13 Jan 2003 23:07:08 -0000      1.4
  +++ AbstractIntCollection.java        3 Mar 2003 23:23:39 -0000       1.5
  @@ -78,21 +78,6 @@
       public abstract int size();
             
       protected AbstractIntCollection() { }
  -
  -    /** 
  -     * Constructs a collection containing the elements of 
  -     * the given collection, added in the order they are 
  -     * returned by that collection's iterator.
  -     * 
  -     * @see #addAll
  -     * @param that the non-<code>null</code> collection of <code>int</code>s 
  -     *        to add
  -     * @throws NullPointerException if <i>that</i> is <code>null</code>
  -     * @throws UnsupportedOperationException if [EMAIL PROTECTED] #addAll addAll} 
does
  -     */
  -    protected AbstractIntCollection(IntCollection that) { 
  -        addAll(that);
  -    }    
                 
       /** Unsupported in this base implementation. */
       public boolean add(int element) {
  
  
  
  1.14      +3 -21     
jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java
  
  Index: AbstractRandomAccessIntList.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AbstractRandomAccessIntList.java  1 Mar 2003 00:47:28 -0000       1.13
  +++ AbstractRandomAccessIntList.java  3 Mar 2003 23:23:39 -0000       1.14
  @@ -87,20 +87,6 @@
       protected AbstractRandomAccessIntList() { 
       }    
   
  -    /** 
  -     * Constructs a list containing the elements of the given collection, 
  -     * in the order they are returned by that collection's iterator.
  -     * 
  -     * @see #addAll
  -     * @param that the non-<code>null</code> collection of <code>int</code>s 
  -     *        to add
  -     * @throws NullPointerException if <i>that</i> is <code>null</code>
  -     * @throws UnsupportedOperationException if [EMAIL PROTECTED] #addAll addAll} 
does
  -     */
  -    protected AbstractRandomAccessIntList(IntCollection that) { 
  -        super(that);
  -    }    
  -
       // fully abstract methods
       //-------------------------------------------------------------------------
       
  @@ -275,14 +261,10 @@
       }
       
       protected static class RandomAccessIntListIterator extends ComodChecker 
implements IntListIterator {
  -        RandomAccessIntListIterator(AbstractRandomAccessIntList list) {
  -            this(list,0);
  -        }
  -            
           RandomAccessIntListIterator(AbstractRandomAccessIntList list, int index) {
               super(list);
               if(index < 0 || index > getList().size()) {
  -                throw new IllegalArgumentException("Index " + index + " not in [0," 
+ getList().size() + ")");
  +                throw new IndexOutOfBoundsException("Index " + index + " not in 
[0," + getList().size() + ")");
               } else {
                   _nextIndex = index;
                   resyncModCount();
  
  
  
  1.9       +5 -2      
jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAll.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestAll.java      26 Feb 2003 19:17:23 -0000      1.8
  +++ TestAll.java      3 Mar 2003 23:23:40 -0000       1.9
  @@ -77,6 +77,9 @@
   
       public static Test suite() {
           TestSuite suite = new TestSuite();
  +
  +        suite.addTest(TestAbstractIntCollection.suite());
  +        suite.addTest(TestAbstractRandomAccessIntList.suite());
           
           suite.addTest(TestArrayIntList.suite());
           suite.addTest(TestArrayUnsignedShortList.suite());
  
  
  
  1.8       +48 -3     
jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntList.java
  
  Index: TestIntList.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntList.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestIntList.java  1 Mar 2003 00:47:28 -0000       1.7
  +++ TestIntList.java  3 Mar 2003 23:23:40 -0000       1.8
  @@ -58,6 +58,7 @@
   package org.apache.commons.collections.primitives;
   
   import java.io.Serializable;
  +import java.util.AbstractCollection;
   import java.util.ArrayList;
   import java.util.List;
   
  @@ -297,7 +298,6 @@
           assertEquals(50,list.size());        
       }
       
  -
       public void testAddGet() {
           IntList list = makeEmptyIntList();
           for (int i = 0; i < 1000; i++) {
  @@ -374,6 +374,51 @@
               makeFullIntList().subList(2,makeFullIntList().size()+2);
               fail("Expected IndexOutOfBoundsException");
           } catch(IndexOutOfBoundsException e) {
  +            // expected
  +        }
  +    }
  +
  +    public void testListIteratorOutOfBounds() throws Exception {
  +        try {
  +            makeEmptyIntList().listIterator(2);
  +            fail("Expected IndexOutOfBoundsException");
  +        } catch(IndexOutOfBoundsException e) {
  +            // expected
  +        }
  +
  +        try {
  +            makeFullIntList().listIterator(-1);
  +            fail("Expected IndexOutOfBoundsException");
  +        } catch(IndexOutOfBoundsException e) {
  +            // expected
  +        }
  +
  +        try {
  +            makeFullIntList().listIterator(makeFullIntList().size()+2);
  +            fail("Expected IndexOutOfBoundsException");
  +        } catch(IndexOutOfBoundsException e) {
  +            // expected
  +        }
  +    }
  +
  +    public void testListIteratorSetWithoutNext() throws Exception {
  +        IntListIterator iter = makeFullIntList().listIterator();
  +        try {
  +            iter.set(3);
  +            fail("Expected IllegalStateException");
  +        } catch(IllegalStateException e) {
  +            // expected
  +        }
  +    }
  +
  +    public void testListIteratorSetAfterRemove() throws Exception {
  +        IntListIterator iter = makeFullIntList().listIterator();
  +        iter.next();
  +        iter.remove();
  +        try {            
  +            iter.set(3);
  +            fail("Expected IllegalStateException");
  +        } catch(IllegalStateException e) {
               // expected
           }
       }
  
  
  
  1.1                  
jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAbstractIntCollection.java
  
  Index: TestAbstractIntCollection.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAbstractIntCollection.java,v
 1.1 2003/03/03 23:23:40 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    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
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 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 Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.primitives;
  
  import java.util.Collections;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.commons.collections.primitives.adapters.IteratorIntIterator;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/03 23:23:40 $
   * @author Rodney Waldhoff
   */
  public class TestAbstractIntCollection extends TestCase {
  
      // conventional
      // ------------------------------------------------------------------------
  
      public TestAbstractIntCollection(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestAbstractIntCollection.class);
      }
  
      // tests
      // ------------------------------------------------------------------------
      
      public void testAddIsUnsupportedByDefault() {
          IntCollection col = new IntCollectionImpl();
          try {
              col.add(1);
              fail("Expected UnsupportedOperationException");
          } catch(UnsupportedOperationException e) {
              // expected
          }        
      }
      // inner classes
      // ------------------------------------------------------------------------
  
  
      static class IntCollectionImpl extends AbstractIntCollection {
          public IntCollectionImpl() {
          }
          
          public IntIterator iterator() {
              return new IteratorIntIterator(Collections.EMPTY_LIST.iterator());
          }
  
          public int size() {
              return 0;
          }
      }
  }
  
  
  
  1.1                  
jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAbstractRandomAccessIntList.java
  
  Index: TestAbstractRandomAccessIntList.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAbstractRandomAccessIntList.java,v
 1.1 2003/03/03 23:23:40 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    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
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 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 Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.primitives;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/03 23:23:40 $
   * @author Rodney Waldhoff
   */
  public class TestAbstractRandomAccessIntList extends TestCase {
  
      // conventional
      // ------------------------------------------------------------------------
  
      public TestAbstractRandomAccessIntList(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestAbstractRandomAccessIntList.class);
      }
  
      // tests
      // ------------------------------------------------------------------------
      
      public void testAddIsUnsupportedByDefault() {
          AbstractRandomAccessIntList list = new AbstractRandomAccessIntListImpl();
          try {
              list.add(1);
              fail("Expected UnsupportedOperationException");
          } catch(UnsupportedOperationException e) {
              // expected
          }        
          try {
              list.set(0,1);
              fail("Expected UnsupportedOperationException");
          } catch(UnsupportedOperationException e) {
              // expected
          }               
      }
  
      public void testAddAllIsUnsupportedByDefault() {
          AbstractRandomAccessIntList list = new AbstractRandomAccessIntListImpl();
          IntList list2 = new ArrayIntList();
          list2.add(3);
          try {
              list.addAll(list2);
              fail("Expected UnsupportedOperationException");
          } catch(UnsupportedOperationException e) {
              // expected
          }               
      }
      
      public void testSetIsUnsupportedByDefault() {
          AbstractRandomAccessIntList list = new AbstractRandomAccessIntListImpl();
          try {
              list.set(0,1);
              fail("Expected UnsupportedOperationException");
          } catch(UnsupportedOperationException e) {
              // expected
          }               
      }
      
      public void testRemoveElementIsUnsupportedByDefault() {
          AbstractRandomAccessIntList list = new AbstractRandomAccessIntListImpl();
          try {
              list.removeElementAt(0);
              fail("Expected UnsupportedOperationException");
          } catch(UnsupportedOperationException e) {
              // expected
          }               
      }
      
      // inner classes
      // ------------------------------------------------------------------------
  
  
      static class AbstractRandomAccessIntListImpl extends AbstractRandomAccessIntList 
{
          public AbstractRandomAccessIntListImpl() {
          }
  
          /**
           * @see org.apache.commons.collections.primitives.IntList#get(int)
           */
          public int get(int index) {
              throw new IndexOutOfBoundsException();
          }
  
          /**
           * @see org.apache.commons.collections.primitives.IntCollection#size()
           */
          public int size() {
              return 0;
          }
  
      }
  }
  
  
  
  1.2       +3 -3      
jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntListIteratorListIterator.java
  
  Index: TestIntListIteratorListIterator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntListIteratorListIterator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestIntListIteratorListIterator.java      1 Mar 2003 00:47:29 -0000       1.1
  +++ TestIntListIteratorListIterator.java      3 Mar 2003 23:23:40 -0000       1.2
  @@ -82,7 +82,7 @@
       }
   
       public static Test suite() {
  -        return new TestSuite(TestIntIteratorIterator.class);
  +        return new TestSuite(TestIntListIteratorListIterator.class);
       }
   
       // collections testing framework
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to