Add transformed decorators tests

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131072 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-05-11 13:18:27 +00:00
parent 530e458fb7
commit 611120275c
8 changed files with 907 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestAll.java,v 1.2 2003/05/10 15:50:14 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestAll.java,v 1.3 2003/05/11 13:18:27 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -64,7 +64,8 @@ import junit.framework.TestSuite;
/**
* Entry point for all collections decorators tests.
*
* @version $Revision: 1.2 $ $Date: 2003/05/10 15:50:14 $
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/05/11 13:18:27 $
*
* @author Stephen Colebourne
*/
@ -85,6 +86,13 @@ public class TestAll extends TestCase {
suite.addTest(TestFixedSizeMap.suite());
suite.addTest(TestFixedSizeSortedMap.suite());
suite.addTest(TestSequencedSet.suite());
suite.addTest(TestTransformedBag.suite());
suite.addTest(TestTransformedBuffer.suite());
suite.addTest(TestTransformedCollection.suite());
suite.addTest(TestTransformedList.suite());
suite.addTest(TestTransformedSet.suite());
suite.addTest(TestTransformedSortedBag.suite());
suite.addTest(TestTransformedSortedSet.suite());
return suite;
}

View File

@ -0,0 +1,110 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedBag.java,v 1.1 2003/05/11 13:18:27 scolebourne 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 apache@apache.org.
*
* 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.decorators;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.Bag;
import org.apache.commons.collections.HashBag;
import org.apache.commons.collections.TestBag;
/**
* Extension of {@link TestBag} for exercising the {@link TransformedBag}
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/05/11 13:18:27 $
*
* @author Stephen Colebourne
*/
public class TestTransformedBag extends TestBag {
public TestTransformedBag(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestTransformedBag.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestTransformedBag.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
public Bag makeBag() {
return TransformedBag.decorate(new HashBag(), TestTransformedCollection.NOOP_TRANSFORMER);
}
public void testTransformedBag() {
Bag bag = TransformedBag.decorate(new HashBag(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, bag.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
bag.add(els[i]);
assertEquals(i + 1, bag.size());
assertEquals(true, bag.contains(new Integer((String) els[i])));
assertEquals(false, bag.contains(els[i]));
}
assertEquals(false, bag.remove(els[0]));
assertEquals(true, bag.remove(new Integer((String) els[0])));
}
}

View File

@ -0,0 +1,106 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedBuffer.java,v 1.1 2003/05/11 13:18:27 scolebourne 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 apache@apache.org.
*
* 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.decorators;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.collections.ArrayStack;
import org.apache.commons.collections.Buffer;
/**
* Extension of {@link TestBuffer} for exercising the {@link TransformedBuffer}
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/05/11 13:18:27 $
*
* @author Stephen Colebourne
*/
public class TestTransformedBuffer extends TestCase {
public TestTransformedBuffer(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestTransformedBuffer.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestTransformedBuffer.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
public void testTransformedBuffer() {
Buffer buffer = TransformedBuffer.decorate(new ArrayStack(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, buffer.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
buffer.add(els[i]);
assertEquals(i + 1, buffer.size());
assertEquals(true, buffer.contains(new Integer((String) els[i])));
assertEquals(false, buffer.contains(els[i]));
}
assertEquals(false, buffer.remove(els[0]));
assertEquals(true, buffer.remove(new Integer((String) els[0])));
}
}

View File

@ -0,0 +1,153 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedCollection.java,v 1.1 2003/05/11 13:18:27 scolebourne 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 apache@apache.org.
*
* 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.decorators;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.TestCollection;
import org.apache.commons.collections.Transformer;
/**
* Extension of {@link TestCollection} for exercising the {@link TransformedCollection}
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/05/11 13:18:27 $
*
* @author Stephen Colebourne
*/
public class TestTransformedCollection extends TestCollection {
private static class Noop implements Transformer, Serializable {
public Object transform(Object input) {
return input;
}
}
private static class StringToInteger implements Transformer, Serializable {
public Object transform(Object input) {
return new Integer((String) input);
}
}
static final Transformer NOOP_TRANSFORMER = new Noop();
static final Transformer STRING_TO_INTEGER_TRANSFORMER = new StringToInteger();
public TestTransformedCollection(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestTransformedCollection.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestTransformedCollection.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
public Collection makeConfirmedCollection() {
return new ArrayList();
}
protected Collection makeConfirmedFullCollection() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
public Collection makeCollection() {
return TransformedCollection.decorate(new ArrayList(), NOOP_TRANSFORMER);
}
protected Collection makeFullCollection() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return TransformedCollection.decorate(list, NOOP_TRANSFORMER);
}
protected Object[] getFullElements() {
return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
}
protected Object[] getOtherElements() {
return new Object[] {"9", "88", "678", "87", "98", "78", "99"};
}
public void testTransformedCollection() {
Collection coll = TransformedCollection.decorate(new ArrayList(), STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, coll.size());
Object[] els = getFullElements();
for (int i = 0; i < els.length; i++) {
coll.add(els[i]);
assertEquals(i + 1, coll.size());
assertEquals(true, coll.contains(new Integer((String) els[i])));
assertEquals(false, coll.contains(els[i]));
}
assertEquals(true, coll.remove(new Integer((String) els[0])));
}
}

View File

@ -0,0 +1,161 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedList.java,v 1.1 2003/05/11 13:18:27 scolebourne 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 apache@apache.org.
*
* 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.decorators;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.TestList;
/**
* Extension of {@link TestList} for exercising the {@link TransformedList}
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/05/11 13:18:27 $
*
* @author Stephen Colebourne
*/
public class TestTransformedList extends TestList {
public TestTransformedList(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestTransformedList.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestTransformedList.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
public Collection makeConfirmedCollection() {
return new ArrayList();
}
protected Collection makeConfirmedFullCollection() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
public List makeEmptyList() {
return TransformedList.decorate(new ArrayList(), TestTransformedCollection.NOOP_TRANSFORMER);
}
protected List makeFullList() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return TransformedList.decorate(list, TestTransformedCollection.NOOP_TRANSFORMER);
}
public void testTransformedList() {
List list = TransformedList.decorate(new ArrayList(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, list.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
list.add(els[i]);
assertEquals(i + 1, list.size());
assertEquals(true, list.contains(new Integer((String) els[i])));
assertEquals(false, list.contains(els[i]));
}
assertEquals(false, list.remove(els[0]));
assertEquals(true, list.remove(new Integer((String) els[0])));
list.clear();
for (int i = 0; i < els.length; i++) {
list.add(0, els[i]);
assertEquals(i + 1, list.size());
assertEquals(new Integer((String) els[i]), list.get(0));
}
list.set(0, "22");
assertEquals(new Integer(22), list.get(0));
ListIterator it = list.listIterator();
it.next();
it.set("33");
assertEquals(new Integer(33), list.get(0));
it.add("44");
assertEquals(new Integer(44), list.get(1));
List adds = new ArrayList();
adds.add("1");
adds.add("2");
list.clear();
list.addAll(adds);
assertEquals(new Integer(1), list.get(0));
assertEquals(new Integer(2), list.get(1));
adds.clear();
adds.add("3");
list.addAll(1, adds);
assertEquals(new Integer(1), list.get(0));
assertEquals(new Integer(3), list.get(1));
assertEquals(new Integer(2), list.get(2));
}
}

View File

@ -0,0 +1,129 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedSet.java,v 1.1 2003/05/11 13:18:27 scolebourne 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 apache@apache.org.
*
* 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.decorators;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.TestSet;
/**
* Extension of {@link TestSet} for exercising the {@link TransformedSet}
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/05/11 13:18:27 $
*
* @author Stephen Colebourne
*/
public class TestTransformedSet extends TestSet {
public TestTransformedSet(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestTransformedSet.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestTransformedSet.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
public Collection makeConfirmedCollection() {
return new HashSet();
}
protected Collection makeConfirmedFullCollection() {
Set set = new HashSet();
set.addAll(Arrays.asList(getFullElements()));
return set;
}
public Set makeEmptySet() {
return TransformedSet.decorate(new HashSet(), TestTransformedCollection.NOOP_TRANSFORMER);
}
protected Set makeFullSet() {
Set list = new HashSet();
list.addAll(Arrays.asList(getFullElements()));
return TransformedSet.decorate(list, TestTransformedCollection.NOOP_TRANSFORMER);
}
public void testTransformedSet() {
Set set = TransformedSet.decorate(new HashSet(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, set.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
set.add(els[i]);
assertEquals(i + 1, set.size());
assertEquals(true, set.contains(new Integer((String) els[i])));
assertEquals(false, set.contains(els[i]));
}
assertEquals(false, set.remove(els[0]));
assertEquals(true, set.remove(new Integer((String) els[0])));
}
}

View File

@ -0,0 +1,108 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedSortedBag.java,v 1.1 2003/05/11 13:18:27 scolebourne 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 apache@apache.org.
*
* 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.decorators;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.Bag;
import org.apache.commons.collections.TestBag;
import org.apache.commons.collections.TreeBag;
/**
* Extension of {@link TestSortedBag} for exercising the {@link TransformedSortedBag}
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/05/11 13:18:27 $
*
* @author Stephen Colebourne
*/
public class TestTransformedSortedBag extends TestBag {
public TestTransformedSortedBag(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestTransformedSortedBag.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestTransformedSortedBag.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
public Bag makeBag() {
return TransformedSortedBag.decorate(new TreeBag(), TestTransformedCollection.NOOP_TRANSFORMER);
}
public void testTransformedBag() {
Bag bag = TransformedSortedBag.decorate(new TreeBag(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, bag.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
bag.add(els[i]);
assertEquals(i + 1, bag.size());
assertEquals(true, bag.contains(new Integer((String) els[i])));
}
assertEquals(true, bag.remove(new Integer((String) els[0])));
}
}

View File

@ -0,0 +1,130 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedSortedSet.java,v 1.1 2003/05/11 13:18:27 scolebourne 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 apache@apache.org.
*
* 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.decorators;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.TestSortedSet;
/**
* Extension of {@link TestSortedSet} for exercising the {@link TransformedSortedSet}
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/05/11 13:18:27 $
*
* @author Stephen Colebourne
*/
public class TestTransformedSortedSet extends TestSortedSet {
public TestTransformedSortedSet(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestTransformedSortedSet.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestTransformedSortedSet.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
public Collection makeConfirmedCollection() {
return new TreeSet();
}
protected Collection makeConfirmedFullCollection() {
Set set = new TreeSet();
set.addAll(Arrays.asList(getFullElements()));
return set;
}
public Set makeEmptySet() {
return TransformedSortedSet.decorate(new HashSet(), TestTransformedCollection.NOOP_TRANSFORMER);
}
protected Set makeFullSet() {
Set list = new TreeSet();
list.addAll(Arrays.asList(getFullElements()));
return TransformedSortedSet.decorate(list, TestTransformedCollection.NOOP_TRANSFORMER);
}
public void testTransformedSet() {
Set set = TransformedSortedSet.decorate(new HashSet(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, set.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
set.add(els[i]);
assertEquals(i + 1, set.size());
assertEquals(true, set.contains(new Integer((String) els[i])));
assertEquals(false, set.contains(els[i]));
}
assertEquals(false, set.remove(els[0]));
assertEquals(true, set.remove(new Integer((String) els[0])));
}
}