Rename TestComparator to AbstractTestComparator

Tidy comparator test classes licenses/javadoc


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131211 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-10-01 22:14:48 +00:00
parent dd7f7aca14
commit 513ef0ae75
8 changed files with 437 additions and 248 deletions

View File

@ -0,0 +1,276 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java,v 1.1 2003/10/01 22:14:48 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-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 acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements 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.comparators;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.collections.TestObject;
/**
* Abstract test class for testing the Comparator interface.
* <p>
* Concrete subclasses declare the comparator to be tested.
* They also declare certain aspects of the tests.
*
* @author Stephen Colebourne
*/
public abstract class AbstractTestComparator extends TestObject {
/**
* JUnit constructor.
*
* @param testName the test class name
*/
public AbstractTestComparator(String testName) {
super(testName);
}
//-----------------------------------------------------------------------
/**
* Implement this method to return the comparator to test.
*
* @return the comparator to test
*/
protected abstract Comparator makeComparator();
/**
* Implement this method to return a list of sorted objects.
*
* @return sorted objects
*/
protected abstract List getComparableObjectsOrdered();
//-----------------------------------------------------------------------
/**
* Implements the abstract superclass method to return the comparator.
*
* @return a full iterator
*/
protected Object makeObject() {
return makeComparator();
}
/**
* Overrides superclass to block tests.
*/
public boolean supportsEmptyCollections() {
return false;
}
/**
* Overrides superclass to block tests.
*/
public boolean supportsFullCollections() {
return false;
}
/**
* Overrides superclass to set the compatability to version 2
* as there were no Comparators in version 1.x.
*/
protected String getCompatibilityVersion() {
return "2";
}
//-----------------------------------------------------------------------
/**
* Reverse the list.
*/
protected void reverseObjects(List list) {
Collections.reverse(list);
}
/**
* Randomize the list.
*/
protected void randomizeObjects(List list) {
Collections.shuffle(list);
}
/**
* Sort the list.
*/
protected void sortObjects(List list, Comparator comparator) {
Collections.sort(list,comparator);
}
//-----------------------------------------------------------------------
/**
* Test sorting an empty list
*/
public void testEmptyListSort() {
List list = new LinkedList();
sortObjects(list, makeComparator());
List list2 = new LinkedList();
assertTrue("Comparator cannot sort empty lists",
list2.equals(list));
}
/**
* Test sorting a reversed list.
*/
public void testReverseListSort() {
Comparator comparator = makeComparator();
List randomList = getComparableObjectsOrdered();
reverseObjects(randomList);
sortObjects(randomList,comparator);
List orderedList = getComparableObjectsOrdered();
assertTrue("Comparator did not reorder the List correctly",
orderedList.equals(randomList));
}
/**
* Test sorting a random list.
*/
public void testRandomListSort() {
Comparator comparator = makeComparator();
List randomList = getComparableObjectsOrdered();
randomizeObjects(randomList);
sortObjects(randomList,comparator);
List orderedList = getComparableObjectsOrdered();
/* debug
Iterator i = randomList.iterator();
while (i.hasNext()) {
System.out.println(i.next());
}
*/
assertTrue("Comparator did not reorder the List correctly",
orderedList.equals(randomList));
}
/**
* Nearly all Comparators should be Serializable.
*/
public void testComparatorIsSerializable() {
Comparator comparator = makeComparator();
assertTrue("This comparator should be Serializable.",
comparator instanceof Serializable);
}
public String getCanonicalComparatorName(Object object) {
StringBuffer retval = new StringBuffer();
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
retval.append(colName);
retval.append(".version");
retval.append(getCompatibilityVersion());
retval.append(".obj");
return retval.toString();
}
/**
* Compare the current serialized form of the Comparator
* against the canonical version in CVS.
*/
public void testComparatorCompatibility() throws IOException, ClassNotFoundException {
if(!skipSerializedCanonicalTests()) {
Comparator comparator = null;
// test to make sure the canonical form has been preserved
try {
comparator = (Comparator) readExternalFormFromDisk(getCanonicalComparatorName(makeComparator()));
} catch (FileNotFoundException exception) {
boolean autoCreateSerialized = false;
if(autoCreateSerialized) {
comparator = makeComparator();
String fileName = getCanonicalComparatorName(comparator);
writeExternalFormToDisk((Serializable) comparator, fileName);
fail("Serialized form could not be found. A serialized version " +
"has now been written (and should be added to CVS): " + fileName);
} else {
fail("The Serialized form could be located to test serialization " +
"compatibility: " + exception.getMessage());
}
}
// make sure the canonical form produces the ordering we currently
// expect
List randomList = getComparableObjectsOrdered();
reverseObjects(randomList);
sortObjects(randomList,comparator);
List orderedList = getComparableObjectsOrdered();
assertTrue("Comparator did not reorder the List correctly",
orderedList.equals(randomList));
}
}
}

View File

@ -1,9 +1,10 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/TestBooleanComparator.java,v 1.3 2003/08/31 17:28:46 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/TestBooleanComparator.java,v 1.4 2003/10/01 22:14:48 scolebourne Exp $
* ==================================================================== * ====================================================================
*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2003 The Apache Software Foundation. All rights * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -18,21 +19,21 @@
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, * 3. The end-user documentation included with the redistribution, if
* if any, must include the following acknowledgement: * any, must include the following acknowledgement:
* "This product includes software developed by the * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself, * Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear. * if and wherever such third-party acknowledgements normally appear.
* *
* 4. The names "Apache" and "Apache Software Foundation" and * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* "Apache Commons" must not be used to endorse or promote products * Foundation" must not be used to endorse or promote products derived
* derived from this software without prior written permission. For * from this software without prior written permission. For written
* written permission, please contact apache@apache.org. * permission, please contact apache@apache.org.
* *
* 5. Products derived from this software may not be called "Apache", * 5. Products derived from this software may not be called "Apache"
* "Apache Turbine", nor may "Apache" appear in their name, without * nor may "Apache" appear in their names without prior written
* prior written permission of the Apache Software Foundation. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -52,6 +53,7 @@
* individuals on behalf of the Apache Software Foundation. For more * individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*
*/ */
package org.apache.commons.collections.comparators; package org.apache.commons.collections.comparators;
@ -65,13 +67,11 @@ import junit.framework.TestSuite;
/** /**
* Tests for {@link BooleanComparator}. * Tests for {@link BooleanComparator}.
* *
* @since Commons Collections 2.2 * @version $Revision: 1.4 $ $Date: 2003/10/01 22:14:48 $
*
* @version $Revision: 1.3 $ $Date: 2003/08/31 17:28:46 $
* *
* @author Rodney Waldhoff * @author Rodney Waldhoff
*/ */
public class TestBooleanComparator extends TestComparator { public class TestBooleanComparator extends AbstractTestComparator {
// conventional // conventional
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -87,11 +87,11 @@ public class TestBooleanComparator extends TestComparator {
// collections testing framework // collections testing framework
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
public Comparator makeComparator() { protected Comparator makeComparator() {
return new BooleanComparator(); return new BooleanComparator();
} }
public List getComparableObjectsOrdered() { protected List getComparableObjectsOrdered() {
List list = new ArrayList(); List list = new ArrayList();
list.add(new Boolean(false)); list.add(new Boolean(false));
list.add(Boolean.FALSE); list.add(Boolean.FALSE);

View File

@ -1,3 +1,60 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/TestComparableComparator.java,v 1.3 2003/10/01 22:14:48 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-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 acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements 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.comparators; package org.apache.commons.collections.comparators;
import java.util.Comparator; import java.util.Comparator;
@ -7,7 +64,14 @@ import java.util.List;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
public class TestComparableComparator extends TestComparator { /**
* Tests for ComparableComparator.
*
* @version $Revision: 1.3 $ $Date: 2003/10/01 22:14:48 $
*
* @author Unknown
*/
public class TestComparableComparator extends AbstractTestComparator {
public TestComparableComparator(String testName) { public TestComparableComparator(String testName) {
super(testName); super(testName);
@ -17,11 +81,11 @@ public class TestComparableComparator extends TestComparator {
return new TestSuite(TestComparableComparator.class); return new TestSuite(TestComparableComparator.class);
} }
public Comparator makeComparator() { protected Comparator makeComparator() {
return new ComparableComparator(); return new ComparableComparator();
} }
public List getComparableObjectsOrdered() { protected List getComparableObjectsOrdered() {
List list = new LinkedList(); List list = new LinkedList();
list.add(new Integer(1)); list.add(new Integer(1));
list.add(new Integer(2)); list.add(new Integer(2));

View File

@ -1,170 +0,0 @@
package org.apache.commons.collections.comparators;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.collections.TestObject;
public abstract class TestComparator extends TestObject {
public TestComparator(String testName) {
super(testName);
}
public abstract Comparator makeComparator();
public abstract List getComparableObjectsOrdered();
public Object makeObject() {
return makeComparator();
}
/**
* There were no Comparators in version 1.x.
*
* @return 2
*/
public String getCompatibilityVersion() {
return "2";
}
public void reverseObjects(List list) {
Collections.reverse(list);
}
public void randomizeObjects(List list) {
Collections.shuffle(list);
}
/**
* Sort object according to the given Comparator.
*
* @param list List to sort
* @param comparator sorting comparator
*/
public void sortObjects(List list, Comparator comparator) {
Collections.sort(list,comparator);
}
public boolean supportsEmptyCollections() {
return false;
}
public boolean supportsFullCollections() {
return false;
}
public void testEmptyListSort() {
List list = new LinkedList();
sortObjects(list,makeComparator());
List list2 = new LinkedList();
assertTrue("Comparator cannot sort empty lists",
list2.equals(list));
}
public void testReverseListSort() {
Comparator comparator = makeComparator();
List randomList = getComparableObjectsOrdered();
reverseObjects(randomList);
sortObjects(randomList,comparator);
List orderedList = getComparableObjectsOrdered();
assertTrue("Comparator did not reorder the List correctly",
orderedList.equals(randomList));
}
public void testRandomListSort() {
Comparator comparator = makeComparator();
List randomList = getComparableObjectsOrdered();
randomizeObjects(randomList);
sortObjects(randomList,comparator);
List orderedList = getComparableObjectsOrdered();
/* debug
Iterator i = randomList.iterator();
while (i.hasNext()) {
System.out.println(i.next());
}
*/
assertTrue("Comparator did not reorder the List correctly",
orderedList.equals(randomList));
}
/**
* Nearly all Comparators should be Serializable.
*/
public void testComparatorIsSerializable() {
Comparator comparator = makeComparator();
assertTrue("This comparator should be Serializable.",
comparator instanceof Serializable);
}
public String getCanonicalComparatorName(Object object) {
StringBuffer retval = new StringBuffer();
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
retval.append(colName);
retval.append(".version");
retval.append(getCompatibilityVersion());
retval.append(".obj");
return retval.toString();
}
/**
* Compare the current serialized form of the Comparator
* against the canonical version in CVS.
*/
public void testComparatorCompatibility() throws IOException, ClassNotFoundException {
if(!skipSerializedCanonicalTests()) {
Comparator comparator = null;
// test to make sure the canonical form has been preserved
try {
comparator = (Comparator) readExternalFormFromDisk(getCanonicalComparatorName(makeComparator()));
} catch (FileNotFoundException exception) {
boolean autoCreateSerialized = false;
if(autoCreateSerialized) {
comparator = makeComparator();
String fileName = getCanonicalComparatorName(comparator);
writeExternalFormToDisk((Serializable) comparator, fileName);
fail("Serialized form could not be found. A serialized version " +
"has now been written (and should be added to CVS): " + fileName);
} else {
fail("The Serialized form could be located to test serialization " +
"compatibility: " + exception.getMessage());
}
}
// make sure the canonical form produces the ordering we currently
// expect
List randomList = getComparableObjectsOrdered();
reverseObjects(randomList);
sortObjects(randomList,comparator);
List orderedList = getComparableObjectsOrdered();
assertTrue("Comparator did not reorder the List correctly",
orderedList.equals(randomList));
}
}
}

View File

@ -1,6 +1,7 @@
/* /*
* $Id: TestComparatorChain.java,v 1.6 2003/08/31 17:28:46 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/TestComparatorChain.java,v 1.7 2003/10/01 22:14:48 scolebourne Exp $
* ==================================================================== * ====================================================================
*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
@ -18,21 +19,21 @@
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, * 3. The end-user documentation included with the redistribution, if
* if any, must include the following acknowledgement: * any, must include the following acknowledgement:
* "This product includes software developed by the * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself, * Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear. * if and wherever such third-party acknowledgements normally appear.
* *
* 4. The names "Apache" and "Apache Software Foundation" and * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* "Apache Commons" must not be used to endorse or promote products * Foundation" must not be used to endorse or promote products derived
* derived from this software without prior written permission. For * from this software without prior written permission. For written
* written permission, please contact apache@apache.org. * permission, please contact apache@apache.org.
* *
* 5. Products derived from this software may not be called "Apache", * 5. Products derived from this software may not be called "Apache"
* "Apache Turbine", nor may "Apache" appear in their name, without * nor may "Apache" appear in their names without prior written
* prior written permission of the Apache Software Foundation. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -52,8 +53,8 @@
* individuals on behalf of the Apache Software Foundation. For more * individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*
*/ */
package org.apache.commons.collections.comparators; package org.apache.commons.collections.comparators;
import java.io.Serializable; import java.io.Serializable;
@ -64,7 +65,14 @@ import java.util.List;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
public class TestComparatorChain extends TestComparator { /**
* Tests for ComparatorChain.
*
* @version $Revision: 1.7 $ $Date: 2003/10/01 22:14:48 $
*
* @author Unknown
*/
public class TestComparatorChain extends AbstractTestComparator {
public TestComparatorChain(String testName) { public TestComparatorChain(String testName) {
super(testName); super(testName);
@ -74,7 +82,7 @@ public class TestComparatorChain extends TestComparator {
return new TestSuite(TestComparatorChain.class); return new TestSuite(TestComparatorChain.class);
} }
public Comparator makeComparator() { protected Comparator makeComparator() {
ComparatorChain chain = new ComparatorChain(new ColumnComparator(0)); ComparatorChain chain = new ComparatorChain(new ColumnComparator(0));
chain.addComparator(new ColumnComparator(1),true); // reverse the second column chain.addComparator(new ColumnComparator(1),true); // reverse the second column
chain.addComparator(new ColumnComparator(2),false); chain.addComparator(new ColumnComparator(2),false);
@ -151,7 +159,7 @@ public class TestComparatorChain extends TestComparator {
assertTrue(chain.compare(new Integer(4), new Integer(4)) == 0); assertTrue(chain.compare(new Integer(4), new Integer(4)) == 0);
} }
public List getComparableObjectsOrdered() { protected List getComparableObjectsOrdered() {
List list = new LinkedList(); List list = new LinkedList();
// this is the correct order assuming a // this is the correct order assuming a
// "0th forward, 1st reverse, 2nd forward" sort // "0th forward, 1st reverse, 2nd forward" sort

View File

@ -1,13 +1,10 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/TestFixedOrderComparator.java,v 1.3 2003/08/31 17:28:46 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/TestFixedOrderComparator.java,v 1.4 2003/10/01 22:14:48 scolebourne Exp $
* $Revision: 1.3 $
* $Date: 2003/08/31 17:28:46 $
*
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -36,7 +33,7 @@
* *
* 5. Products derived from this software may not be called "Apache" * 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written * nor may "Apache" appear in their names without prior written
* permission of the Apache Group. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -73,6 +70,8 @@ import junit.framework.TestSuite;
/** /**
* Test class for FixedOrderComparator. * Test class for FixedOrderComparator.
* *
* @version $Revision: 1.4 $ $Date: 2003/10/01 22:14:48 $
*
* @author David Leppik * @author David Leppik
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */

View File

@ -1,9 +1,10 @@
package org.apache.commons.collections.comparators; /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/TestNullComparator.java,v 1.6 2003/10/01 22:14:48 scolebourne Exp $
/* ==================================================================== * ====================================================================
*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -18,21 +19,21 @@ package org.apache.commons.collections.comparators;
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, * 3. The end-user documentation included with the redistribution, if
* if any, must include the following acknowledgement: * any, must include the following acknowledgement:
* "This product includes software developed by the * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself, * Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear. * if and wherever such third-party acknowledgements normally appear.
* *
* 4. The names "Apache" and "Apache Software Foundation" and * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* "Apache Commons" must not be used to endorse or promote products * Foundation" must not be used to endorse or promote products derived
* derived from this software without prior written permission. For * from this software without prior written permission. For written
* written permission, please contact apache@apache.org. * permission, please contact apache@apache.org.
* *
* 5. Products derived from this software may not be called "Apache", * 5. Products derived from this software may not be called "Apache"
* "Apache Turbine", nor may "Apache" appear in their name, without * nor may "Apache" appear in their names without prior written
* prior written permission of the Apache Software Foundation. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -52,7 +53,9 @@ package org.apache.commons.collections.comparators;
* individuals on behalf of the Apache Software Foundation. For more * individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*
*/ */
package org.apache.commons.collections.comparators;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedList; import java.util.LinkedList;
@ -62,12 +65,13 @@ import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
/** /**
* Test the NullComparator * Test the NullComparator.
* *
* @author <a href="mailto:mas@apache.org">Michael A. Smith</a> * @version $Revision: 1.6 $ $Date: 2003/10/01 22:14:48 $
* @version $Id: TestNullComparator.java,v 1.5 2003/08/31 17:28:46 scolebourne Exp $ *
**/ * @author Michael A. Smith
public abstract class TestNullComparator extends TestComparator { */
public abstract class TestNullComparator extends AbstractTestComparator {
public TestNullComparator(String testName) { public TestNullComparator(String testName) {
super(testName); super(testName);
@ -89,11 +93,11 @@ public abstract class TestNullComparator extends TestComparator {
super(testName); super(testName);
} }
public Comparator makeComparator() { protected Comparator makeComparator() {
return new NullComparator(); return new NullComparator();
} }
public List getComparableObjectsOrdered() { protected List getComparableObjectsOrdered() {
List list = new LinkedList(); List list = new LinkedList();
list.add(new Integer(1)); list.add(new Integer(1));
list.add(new Integer(2)); list.add(new Integer(2));

View File

@ -1,6 +1,7 @@
/* /*
* $Id: TestReverseComparator.java,v 1.5 2003/08/31 17:28:46 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/comparators/TestReverseComparator.java,v 1.6 2003/10/01 22:14:48 scolebourne Exp $
* ==================================================================== * ====================================================================
*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
@ -18,21 +19,21 @@
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, * 3. The end-user documentation included with the redistribution, if
* if any, must include the following acknowledgement: * any, must include the following acknowledgement:
* "This product includes software developed by the * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself, * Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear. * if and wherever such third-party acknowledgements normally appear.
* *
* 4. The names "Apache" and "Apache Software Foundation" and * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* "Apache Commons" must not be used to endorse or promote products * Foundation" must not be used to endorse or promote products derived
* derived from this software without prior written permission. For * from this software without prior written permission. For written
* written permission, please contact apache@apache.org. * permission, please contact apache@apache.org.
* *
* 5. Products derived from this software may not be called "Apache", * 5. Products derived from this software may not be called "Apache"
* "Apache Turbine", nor may "Apache" appear in their name, without * nor may "Apache" appear in their names without prior written
* prior written permission of the Apache Software Foundation. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -52,8 +53,8 @@
* individuals on behalf of the Apache Software Foundation. For more * individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*
*/ */
package org.apache.commons.collections.comparators; package org.apache.commons.collections.comparators;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -68,7 +69,14 @@ import java.util.List;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
public class TestReverseComparator extends TestComparator { /**
* Tests for ReverseComparator.
*
* @version $Revision: 1.6 $ $Date: 2003/10/01 22:14:48 $
*
* @author Unknown
*/
public class TestReverseComparator extends AbstractTestComparator {
public TestReverseComparator(String testName) { public TestReverseComparator(String testName) {
super(testName); super(testName);
@ -88,11 +96,11 @@ public class TestReverseComparator extends TestComparator {
* *
* @return Comparator that returns "natural" order * @return Comparator that returns "natural" order
*/ */
public Comparator makeComparator() { protected Comparator makeComparator() {
return new ReverseComparator(Collections.reverseOrder()); return new ReverseComparator(Collections.reverseOrder());
} }
public List getComparableObjectsOrdered() { protected List getComparableObjectsOrdered() {
List list = new LinkedList(); List list = new LinkedList();
list.add(new Integer(1)); list.add(new Integer(1));
list.add(new Integer(2)); list.add(new Integer(2));