rwaldhoff 2003/02/28 16:47:29 Modified: collections/src/java/org/apache/commons/collections/primitives AbstractRandomAccessIntList.java collections/src/java/org/apache/commons/collections/primitives/adapters CollectionIntCollection.java IntCollectionCollection.java IntListList.java ListIntList.java collections/src/test/org/apache/commons/collections/primitives TestIntList.java collections/src/test/org/apache/commons/collections/primitives/adapters TestAll.java TestIntListList.java TestListIntList.java Added: collections/src/test/org/apache/commons/collections/primitives TestIntIterator.java TestIntListIterator.java collections/src/test/org/apache/commons/collections/primitives/adapters TestCollectionIntCollection.java TestIntCollectionCollection.java TestIntIteratorIterator.java TestIntListIteratorListIterator.java TestIteratorIntIterator.java TestListIteratorIntListIterator.java Log: * add tests * make a few minor changes so that those tests pass Revision Changes Path 1.13 +5 -3 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- AbstractRandomAccessIntList.java 28 Feb 2003 00:17:52 -0000 1.12 +++ AbstractRandomAccessIntList.java 1 Mar 2003 00:47:28 -0000 1.13 @@ -369,8 +369,10 @@ protected static class RandomAccessIntSubList extends AbstractRandomAccessIntList implements IntList { RandomAccessIntSubList(AbstractRandomAccessIntList list, int fromIndex, int toIndex) { - if(fromIndex < 0 || toIndex > list.size() || fromIndex > toIndex) { + if(fromIndex < 0 || toIndex > list.size()) { throw new IndexOutOfBoundsException(); + } else if(fromIndex > toIndex) { + throw new IllegalArgumentException(); } else { _list = list; _offset = fromIndex; 1.7 +2 -8 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/CollectionIntCollection.java Index: CollectionIntCollection.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/CollectionIntCollection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- CollectionIntCollection.java 28 Feb 2003 21:21:51 -0000 1.6 +++ CollectionIntCollection.java 1 Mar 2003 00:47:28 -0000 1.7 @@ -96,12 +96,6 @@ return new NonSerializableCollectionIntCollection(collection); } } - - /** - * No-arg constructor, for serialization purposes. - */ - protected CollectionIntCollection() { - } /** * Creates an [EMAIL PROTECTED] IntCollection IntCollection} wrapping 1.6 +2 -8 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/IntCollectionCollection.java Index: IntCollectionCollection.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/IntCollectionCollection.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- IntCollectionCollection.java 28 Feb 2003 21:21:51 -0000 1.5 +++ IntCollectionCollection.java 1 Mar 2003 00:47:28 -0000 1.6 @@ -100,12 +100,6 @@ } /** - * No-arg constructor, for serialization purposes. - */ - protected IntCollectionCollection() { - } - - /** * Creates a [EMAIL PROTECTED] Collection Collection} wrapping * the specified [EMAIL PROTECTED] IntCollection IntCollection}. * @see #wrap 1.6 +2 -8 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/IntListList.java Index: IntListList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/IntListList.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- IntListList.java 28 Feb 2003 21:21:51 -0000 1.5 +++ IntListList.java 1 Mar 2003 00:47:28 -0000 1.6 @@ -97,12 +97,6 @@ return new NonSerializableIntListList(list); } } - - /** - * No-arg constructor, for serialization purposes. - */ - protected IntListList() { - } /** * Creates a [EMAIL PROTECTED] List List} wrapping 1.7 +2 -8 jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/ListIntList.java Index: ListIntList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/adapters/ListIntList.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ListIntList.java 28 Feb 2003 00:17:53 -0000 1.6 +++ ListIntList.java 1 Mar 2003 00:47:28 -0000 1.7 @@ -99,12 +99,6 @@ } /** - * No-arg constructor, for serialization purposes. - */ - protected ListIntList() { - } - - /** * Creates an [EMAIL PROTECTED] IntList IntList} wrapping * the specified [EMAIL PROTECTED] List List}. * @see #wrap 1.7 +70 -2 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.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- TestIntList.java 28 Feb 2003 00:17:53 -0000 1.6 +++ TestIntList.java 1 Mar 2003 00:47:28 -0000 1.7 @@ -140,6 +140,43 @@ // tests // ------------------------------------------------------------------------ + public void testToJustBigEnoughIntArray() { + IntList list = makeFullIntList(); + int[] dest = new int[list.size()]; + assertSame(dest,list.toArray(dest)); + int i=0; + for(IntIterator iter = list.iterator(); iter.hasNext();i++) { + assertEquals(iter.next(),dest[i]); + } + } + + public void testToLargerThanNeededIntArray() { + IntList list = makeFullIntList(); + int[] dest = new int[list.size()*2]; + for(int i=0;i<dest.length;i++) { + dest[i] = Integer.MAX_VALUE; + } + assertSame(dest,list.toArray(dest)); + int i=0; + for(IntIterator iter = list.iterator(); iter.hasNext();i++) { + assertEquals(iter.next(),dest[i]); + } + for(;i<dest.length;i++) { + assertEquals(Integer.MAX_VALUE,dest[i]); + } + } + + public void testToSmallerThanNeededIntArray() { + IntList list = makeFullIntList(); + int[] dest = new int[list.size()/2]; + int[] dest2 = list.toArray(dest); + assertTrue(dest != dest2); + int i=0; + for(IntIterator iter = list.iterator(); iter.hasNext();i++) { + assertEquals(iter.next(),dest2[i]); + } + } + public void testHashCodeSpecification() { IntList list = makeFullIntList(); int hash = 1; @@ -308,6 +345,37 @@ public void testSubListsAreNotSerializable() throws Exception { IntList list = makeFullIntList().subList(2,3); assertTrue( ! (list instanceof Serializable) ); + } + + public void testSubListOutOfBounds() throws Exception { + try { + makeEmptyIntList().subList(2,3); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } + + try { + makeFullIntList().subList(-1,3); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } + + + try { + makeFullIntList().subList(5,2); + fail("Expected IllegalArgumentException"); + } catch(IllegalArgumentException e) { + // expected + } + + try { + makeFullIntList().subList(2,makeFullIntList().size()+2); + fail("Expected IndexOutOfBoundsException"); + } catch(IndexOutOfBoundsException e) { + // expected + } } } 1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntIterator.java Index: TestIntIterator.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntIterator.java,v 1.1 2003/03/01 00:47:28 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 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.Iterator; import java.util.NoSuchElementException; import org.apache.commons.collections.iterators.TestIterator; import org.apache.commons.collections.primitives.adapters.IntIteratorIterator; /** * @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:28 $ * @author Rodney Waldhoff */ public abstract class TestIntIterator extends TestIterator { // conventional // ------------------------------------------------------------------------ public TestIntIterator(String testName) { super(testName); } // collections testing framework // ------------------------------------------------------------------------ protected Object makeObject() { return makeFullIterator(); } public Iterator makeEmptyIterator() { return IntIteratorIterator.wrap(makeEmptyIntIterator()); } public Iterator makeFullIterator() { return IntIteratorIterator.wrap(makeFullIntIterator()); } protected abstract IntIterator makeEmptyIntIterator(); protected abstract IntIterator makeFullIntIterator(); protected abstract int[] getFullElements(); // tests // ------------------------------------------------------------------------ public void testNextHasNextRemove() { int[] elements = getFullElements(); IntIterator iter = makeFullIntIterator(); for(int i=0;i<elements.length;i++) { assertTrue(iter.hasNext()); assertEquals(elements[i],iter.next()); if(supportsRemove()) { iter.remove(); } } assertTrue(! iter.hasNext() ); } public void testEmptyIntIterator() { assertTrue( ! makeEmptyIntIterator().hasNext() ); try { makeEmptyIntIterator().next(); fail("Expected NoSuchElementException"); } catch(NoSuchElementException e) { // expected } if(supportsRemove()) { try { makeEmptyIntIterator().remove(); fail("Expected IllegalStateException"); } catch(IllegalStateException e) { // expected } } } public void testRemoveBeforeNext() { if(supportsRemove()) { try { makeFullIntIterator().remove(); fail("Expected IllegalStateException"); } catch(IllegalStateException e) { // expected } } } public void testRemoveAfterRemove() { if(supportsRemove()) { IntIterator iter = makeFullIntIterator(); iter.next(); iter.remove(); try { iter.remove(); fail("Expected IllegalStateException"); } catch(IllegalStateException e) { // expected } } } } 1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntListIterator.java Index: TestIntListIterator.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntListIterator.java,v 1.1 2003/03/01 00:47:28 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 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; /** * @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:28 $ * @author Rodney Waldhoff */ public abstract class TestIntListIterator extends TestIntIterator { // conventional // ------------------------------------------------------------------------ public TestIntListIterator(String testName) { super(testName); } // collections testing framework // ------------------------------------------------------------------------ public IntIterator makeEmptyIntIterator() { return makeEmptyIntListIterator(); } public IntIterator makeFullIntIterator() { return makeFullIntListIterator(); } public abstract IntListIterator makeEmptyIntListIterator(); public abstract IntListIterator makeFullIntListIterator(); // tests // ------------------------------------------------------------------------ } 1.2 +8 -2 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestAll.java Index: TestAll.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestAll.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestAll.java 26 Feb 2003 19:17:24 -0000 1.1 +++ TestAll.java 1 Mar 2003 00:47:29 -0000 1.2 @@ -78,8 +78,14 @@ public static Test suite() { TestSuite suite = new TestSuite(); + suite.addTest(TestCollectionIntCollection.suite()); + suite.addTest(TestIntCollectionCollection.suite()); suite.addTest(TestIntListList.suite()); suite.addTest(TestListIntList.suite()); + suite.addTest(TestIteratorIntIterator.suite()); + suite.addTest(TestListIteratorIntListIterator.suite()); + suite.addTest(TestIntIteratorIterator.suite()); + suite.addTest(TestIntListIteratorListIterator.suite()); return suite; } 1.2 +22 -2 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntListList.java Index: TestIntListList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntListList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestIntListList.java 26 Feb 2003 19:17:24 -0000 1.1 +++ TestIntListList.java 1 Mar 2003 00:47:29 -0000 1.2 @@ -57,6 +57,7 @@ package org.apache.commons.collections.primitives.adapters; +import java.io.Serializable; import java.util.List; import junit.framework.Test; @@ -64,6 +65,7 @@ import org.apache.commons.collections.BulkTest; import org.apache.commons.collections.TestList; +import org.apache.commons.collections.primitives.AbstractRandomAccessIntList; import org.apache.commons.collections.primitives.ArrayIntList; /** @@ -134,4 +136,22 @@ // need to add a serialized form to cvs } + public void testWrapNull() { + assertNull(IntListList.wrap(null)); + } + + public void testWrapSerializable() { + List list = IntListList.wrap(new ArrayIntList()); + assertNotNull(list); + assertTrue(list instanceof Serializable); + } + + public void testWrapNonSerializable() { + List list = IntListList.wrap(new AbstractRandomAccessIntList() { + public int get(int i) { throw new IndexOutOfBoundsException(); } + public int size() { return 0; } + }); + assertNotNull(list); + assertTrue(!(list instanceof Serializable)); + } } 1.3 +22 -2 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestListIntList.java Index: TestListIntList.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestListIntList.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestListIntList.java 28 Feb 2003 00:17:56 -0000 1.2 +++ TestListIntList.java 1 Mar 2003 00:47:29 -0000 1.3 @@ -57,6 +57,8 @@ package org.apache.commons.collections.primitives.adapters; +import java.io.Serializable; +import java.util.AbstractList; import java.util.ArrayList; import junit.framework.Test; @@ -133,6 +135,24 @@ public void testFullListCompatibility() { // XXX FIX ME XXX // need to add a serialized form to cvs + } + public void testWrapNull() { + assertNull(ListIntList.wrap(null)); + } + + public void testWrapSerializable() { + IntList list = ListIntList.wrap(new ArrayList()); + assertNotNull(list); + assertTrue(list instanceof Serializable); + } + + public void testWrapNonSerializable() { + IntList list = ListIntList.wrap(new AbstractList() { + public Object get(int i) { throw new IndexOutOfBoundsException(); } + public int size() { return 0; } + }); + assertNotNull(list); + assertTrue(!(list instanceof Serializable)); } } 1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestCollectionIntCollection.java Index: TestCollectionIntCollection.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestCollectionIntCollection.java,v 1.1 2003/03/01 00:47:29 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 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.adapters; import java.io.Serializable; import java.util.AbstractList; import java.util.ArrayList; import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.collections.TestObject; import org.apache.commons.collections.primitives.IntCollection; /** * @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:29 $ * @author Rodney Waldhoff */ public class TestCollectionIntCollection extends TestObject { // conventional // ------------------------------------------------------------------------ public TestCollectionIntCollection(String testName) { super(testName); } public static Test suite() { return new TestSuite(TestCollectionIntCollection.class); } // collections testing framework // ------------------------------------------------------------------------ protected Object makeObject() { List list = new ArrayList(); for(int i=0;i<10;i++) { list.add(new Integer(i)); } return new CollectionIntCollection(list); } public void testSerializeDeserializeThenCompare() { // Collection.equal contract doesn't work that way } /** @todo need to add serialized form to cvs */ public void testCanonicalEmptyCollectionExists() { // XXX FIX ME XXX // need to add a serialized form to cvs } /** @todo need to add serialized form to cvs */ public void testCanonicalFullCollectionExists() { // XXX FIX ME XXX // need to add a serialized form to cvs } // tests // ------------------------------------------------------------------------ public void testWrapNull() { assertNull(CollectionIntCollection.wrap(null)); } public void testWrapSerializable() { IntCollection collection = CollectionIntCollection.wrap(new ArrayList()); assertNotNull(collection); assertTrue(collection instanceof Serializable); } public void testWrapNonSerializable() { IntCollection collection = CollectionIntCollection.wrap(new AbstractList() { public Object get(int i) { throw new IndexOutOfBoundsException(); } public int size() { return 0; } }); assertNotNull(collection); assertTrue(!(collection instanceof Serializable)); } } 1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntCollectionCollection.java Index: TestIntCollectionCollection.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntCollectionCollection.java,v 1.1 2003/03/01 00:47:29 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 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.adapters; import java.io.Serializable; import java.util.Collection; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.collections.TestObject; import org.apache.commons.collections.primitives.AbstractRandomAccessIntList; import org.apache.commons.collections.primitives.ArrayIntList; import org.apache.commons.collections.primitives.IntList; /** * @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:29 $ * @author Rodney Waldhoff */ public class TestIntCollectionCollection extends TestObject { // conventional // ------------------------------------------------------------------------ public TestIntCollectionCollection(String testName) { super(testName); } public static Test suite() { return new TestSuite(TestIntCollectionCollection.class); } // collections testing framework // ------------------------------------------------------------------------ protected Object makeObject() { IntList list = new ArrayIntList(); for(int i=0;i<10;i++) { list.add(i); } return new IntCollectionCollection(list); } public void testSerializeDeserializeThenCompare() { // Collection.equal contract doesn't work that way } /** @todo need to add serialized form to cvs */ public void testCanonicalEmptyCollectionExists() { // XXX FIX ME XXX // need to add a serialized form to cvs } /** @todo need to add serialized form to cvs */ public void testCanonicalFullCollectionExists() { // XXX FIX ME XXX // need to add a serialized form to cvs } // tests // ------------------------------------------------------------------------ public void testWrapNull() { assertNull(IntCollectionCollection.wrap(null)); } public void testWrapSerializable() { Collection collection = IntCollectionCollection.wrap(new ArrayIntList()); assertNotNull(collection); assertTrue(collection instanceof Serializable); } public void testWrapNonSerializable() { Collection collection = IntCollectionCollection.wrap(new AbstractRandomAccessIntList() { public int get(int i) { throw new IndexOutOfBoundsException(); } public int size() { return 0; } }); assertNotNull(collection); assertTrue(!(collection instanceof Serializable)); } } 1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntIteratorIterator.java Index: TestIntIteratorIterator.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntIteratorIterator.java,v 1.1 2003/03/01 00:47:29 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 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.adapters; import java.util.Iterator; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.collections.iterators.TestIterator; import org.apache.commons.collections.primitives.ArrayIntList; import org.apache.commons.collections.primitives.IntList; /** * @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:29 $ * @author Rodney Waldhoff */ public class TestIntIteratorIterator extends TestIterator { // conventional // ------------------------------------------------------------------------ public TestIntIteratorIterator(String testName) { super(testName); } public static Test suite() { return new TestSuite(TestIntIteratorIterator.class); } // collections testing framework // ------------------------------------------------------------------------ public Object makeObject() { return makeFullIterator(); } public Iterator makeEmptyIterator() { return IntIteratorIterator.wrap(makeEmptyIntList().iterator()); } public Iterator makeFullIterator() { return IntIteratorIterator.wrap(makeFullIntList().iterator()); } protected IntList makeEmptyIntList() { return new ArrayIntList(); } protected IntList makeFullIntList() { IntList list = makeEmptyIntList(); int[] elts = getFullElements(); for(int i=0;i<elts.length;i++) { list.add(elts[i]); } return list; } public int[] getFullElements() { return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; } // tests // ------------------------------------------------------------------------ } 1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntListIteratorListIterator.java Index: TestIntListIteratorListIterator.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIntListIteratorListIterator.java,v 1.1 2003/03/01 00:47:29 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 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.adapters; import java.util.Iterator; import java.util.NoSuchElementException; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.collections.iterators.TestIterator; import org.apache.commons.collections.primitives.ArrayIntList; import org.apache.commons.collections.primitives.IntList; /** * @todo should extend TestListIterator when there is one * @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:29 $ * @author Rodney Waldhoff */ public class TestIntListIteratorListIterator extends TestIterator { // conventional // ------------------------------------------------------------------------ public TestIntListIteratorListIterator(String testName) { super(testName); } public static Test suite() { return new TestSuite(TestIntIteratorIterator.class); } // collections testing framework // ------------------------------------------------------------------------ public Object makeObject() { return makeFullIterator(); } public Iterator makeEmptyIterator() { return IntListIteratorListIterator.wrap(makeEmptyIntList().listIterator()); } public Iterator makeFullIterator() { return IntListIteratorListIterator.wrap(makeFullIntList().listIterator()); } protected IntList makeEmptyIntList() { return new ArrayIntList(); } protected IntList makeFullIntList() { IntList list = makeEmptyIntList(); int[] elts = getFullElements(); for(int i=0;i<elts.length;i++) { list.add(elts[i]); } return list; } public int[] getFullElements() { return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; } // tests // ------------------------------------------------------------------------ public void testNextHasNextRemove() { int[] elements = getFullElements(); Iterator iter = makeFullIterator(); for(int i=0;i<elements.length;i++) { assertTrue(iter.hasNext()); assertEquals(new Integer(elements[i]),iter.next()); if(supportsRemove()) { iter.remove(); } } assertTrue(! iter.hasNext() ); } public void testEmptyIterator() { assertTrue( ! makeEmptyIterator().hasNext() ); try { makeEmptyIterator().next(); fail("Expected NoSuchElementException"); } catch(NoSuchElementException e) { // expected } if(supportsRemove()) { try { makeEmptyIterator().remove(); fail("Expected IllegalStateException"); } catch(IllegalStateException e) { // expected } } } public void testRemoveBeforeNext() { if(supportsRemove()) { try { makeFullIterator().remove(); fail("Expected IllegalStateException"); } catch(IllegalStateException e) { // expected } } } public void testRemoveAfterRemove() { if(supportsRemove()) { Iterator iter = makeFullIterator(); iter.next(); iter.remove(); try { iter.remove(); fail("Expected IllegalStateException"); } catch(IllegalStateException e) { // expected } } } } 1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIteratorIntIterator.java Index: TestIteratorIntIterator.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestIteratorIntIterator.java,v 1.1 2003/03/01 00:47:29 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 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.adapters; import java.util.ArrayList; import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.collections.primitives.IntIterator; import org.apache.commons.collections.primitives.TestIntIterator; /** * @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:29 $ * @author Rodney Waldhoff */ public class TestIteratorIntIterator extends TestIntIterator { // conventional // ------------------------------------------------------------------------ public TestIteratorIntIterator(String testName) { super(testName); } public static Test suite() { return new TestSuite(TestIteratorIntIterator.class); } // collections testing framework // ------------------------------------------------------------------------ public IntIterator makeEmptyIntIterator() { return IteratorIntIterator.wrap(makeEmptyList().iterator()); } public IntIterator makeFullIntIterator() { return IteratorIntIterator.wrap(makeFullList().iterator()); } protected List makeEmptyList() { return new ArrayList(); } protected List makeFullList() { List list = makeEmptyList(); int[] elts = getFullElements(); for(int i=0;i<elts.length;i++) { list.add(new Integer(elts[i])); } return list; } public int[] getFullElements() { return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; } // tests // ------------------------------------------------------------------------ } 1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorIntListIterator.java Index: TestListIteratorIntListIterator.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/adapters/TestListIteratorIntListIterator.java,v 1.1 2003/03/01 00:47:29 rwaldhoff Exp $ * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 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.adapters; import java.util.ArrayList; import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.collections.primitives.IntListIterator; import org.apache.commons.collections.primitives.TestIntListIterator; /** * @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:29 $ * @author Rodney Waldhoff */ public class TestListIteratorIntListIterator extends TestIntListIterator { // conventional // ------------------------------------------------------------------------ public TestListIteratorIntListIterator(String testName) { super(testName); } public static Test suite() { return new TestSuite(TestListIteratorIntListIterator.class); } // collections testing framework // ------------------------------------------------------------------------ public IntListIterator makeEmptyIntListIterator() { return ListIteratorIntListIterator.wrap(makeEmptyList().listIterator()); } public IntListIterator makeFullIntListIterator() { return ListIteratorIntListIterator.wrap(makeFullList().listIterator()); } protected List makeEmptyList() { return new ArrayList(); } protected List makeFullList() { List list = makeEmptyList(); int[] elts = getFullElements(); for(int i=0;i<elts.length;i++) { list.add(new Integer(elts[i])); } return list; } public int[] getFullElements() { return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; } // tests // ------------------------------------------------------------------------ }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]