org.apache.commons.collections.comparators
Class AbstractTestComparator

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.commons.collections.BulkTest
              extended byorg.apache.commons.collections.AbstractTestObject
                  extended byorg.apache.commons.collections.comparators.AbstractTestComparator
All Implemented Interfaces:
java.lang.Cloneable, junit.framework.Test

public abstract class AbstractTestComparator
extends AbstractTestObject

Abstract test class for testing the Comparator interface.

Concrete subclasses declare the comparator to be tested. They also declare certain aspects of the tests.


Field Summary
 
Fields inherited from class org.apache.commons.collections.AbstractTestObject
COLLECTIONS_MAJOR_VERSION
 
Constructor Summary
AbstractTestComparator(java.lang.String testName)
          JUnit constructor.
 
Method Summary
 java.lang.String getCanonicalComparatorName(java.lang.Object object)
           
abstract  java.util.List getComparableObjectsOrdered()
          Implement this method to return a list of sorted objects.
 java.lang.String getCompatibilityVersion()
          Overrides superclass to set the compatability to version 2 as there were no Comparators in version 1.x.
abstract  java.util.Comparator makeComparator()
          Implement this method to return the comparator to test.
 java.lang.Object makeObject()
          Implements the abstract superclass method to return the comparator.
protected  void randomizeObjects(java.util.List list)
          Randomize the list.
protected  void reverseObjects(java.util.List list)
          Reverse the list.
protected  void sortObjects(java.util.List list, java.util.Comparator comparator)
          Sort the list.
 boolean supportsEmptyCollections()
          Overrides superclass to block tests.
 boolean supportsFullCollections()
          Overrides superclass to block tests.
 void testComparatorCompatibility()
          Compare the current serialized form of the Comparator against the canonical version in CVS.
 void testComparatorIsSerializable()
          Nearly all Comparators should be Serializable.
 void testEmptyListSort()
          Test sorting an empty list
 void testRandomListSort()
          Test sorting a random list.
 void testReverseListSort()
          Test sorting a reversed list.
 
Methods inherited from class org.apache.commons.collections.AbstractTestObject
getCanonicalEmptyCollectionName, getCanonicalFullCollectionName, isEqualsCheckable, isTestSerialization, readExternalFormFromBytes, readExternalFormFromDisk, skipSerializedCanonicalTests, testCanonicalEmptyCollectionExists, testCanonicalFullCollectionExists, testEqualsNull, testObjectEqualsSelf, testObjectHashCodeEqualsContract, testObjectHashCodeEqualsSelfHashCode, testSerializeDeserializeThenCompare, testSimpleSerialization, writeExternalFormToBytes, writeExternalFormToDisk
 
Methods inherited from class org.apache.commons.collections.BulkTest
clone, ignoredTests, makeSuite, toString
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractTestComparator

public AbstractTestComparator(java.lang.String testName)
JUnit constructor.

Parameters:
testName - the test class name
Method Detail

makeComparator

public abstract java.util.Comparator makeComparator()
Implement this method to return the comparator to test.

Returns:
the comparator to test

getComparableObjectsOrdered

public abstract java.util.List getComparableObjectsOrdered()
Implement this method to return a list of sorted objects.

Returns:
sorted objects

makeObject

public java.lang.Object makeObject()
Implements the abstract superclass method to return the comparator.

Specified by:
makeObject in class AbstractTestObject
Returns:
a full iterator

supportsEmptyCollections

public boolean supportsEmptyCollections()
Overrides superclass to block tests.

Overrides:
supportsEmptyCollections in class AbstractTestObject
Returns:
true

supportsFullCollections

public boolean supportsFullCollections()
Overrides superclass to block tests.

Overrides:
supportsFullCollections in class AbstractTestObject
Returns:
true

getCompatibilityVersion

public java.lang.String getCompatibilityVersion()
Overrides superclass to set the compatability to version 2 as there were no Comparators in version 1.x.

Overrides:
getCompatibilityVersion in class AbstractTestObject
Returns:
The version, or null if this object shouldn't be tested for compatibility with previous versions.

reverseObjects

protected void reverseObjects(java.util.List list)
Reverse the list.


randomizeObjects

protected void randomizeObjects(java.util.List list)
Randomize the list.


sortObjects

protected void sortObjects(java.util.List list,
                           java.util.Comparator comparator)
Sort the list.


testEmptyListSort

public void testEmptyListSort()
Test sorting an empty list


testReverseListSort

public void testReverseListSort()
Test sorting a reversed list.


testRandomListSort

public void testRandomListSort()
Test sorting a random list.


testComparatorIsSerializable

public void testComparatorIsSerializable()
Nearly all Comparators should be Serializable.


getCanonicalComparatorName

public java.lang.String getCanonicalComparatorName(java.lang.Object object)

testComparatorCompatibility

public void testComparatorCompatibility()
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
Compare the current serialized form of the Comparator against the canonical version in CVS.

Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright © 2001-2007 Apache Software Foundation. All Rights Reserved.