org.gjt.rec.testing
Class ComparatorTest

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--junit.framework.TestCase
              |
              +--org.gjt.rec.testing.ComparatorTest
All Implemented Interfaces:
junit.framework.Test

public abstract class ComparatorTest
extends junit.framework.TestCase

Contains test methods that check that a comparator fulfils its contractual obligations as specified by the javadoc comments on the compare(Object, Object) method of the Comparator interface.

Author:
Neil Stockbridge
See Also:
Comparator

Field Summary
static String REVISION
           
 
Constructor Summary
ComparatorTest(String name, Comparator comp)
          Create a new comparator test with the supplied name, working with the specified comparator.
 
Method Summary
 void addComparableObjects(Object[] objects)
          Adds an array of comparable objects for the comparator to work with.
 void setWrongType(Object wrongType)
           
 void testComparable()
           
 void testIncomparable()
           
 void testNullBoth()
           
 void testNullFirst()
           
 void testNullSecond()
           
 void testWrongTypeBoth()
           
 void testWrongTypeFirst()
           
 void testWrongTypeSecond()
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values
Constructor Detail

ComparatorTest

public ComparatorTest(String name,
                      Comparator comp)
Create a new comparator test with the supplied name, working with the specified comparator.

Method Detail

addComparableObjects

public void addComparableObjects(Object[] objects)
Adds an array of comparable objects for the comparator to work with. The supplied objects must be ordered in the order that the comparator under test imposes. More specifically: o1 must be less than o2. o2 must be less than o3. if o4 is present, it must a different instance than o3 but be equal to o3. If this method is invoked multiple times, each new set of objects must be comparable with themselves, but not with any objects supplied in previous invocations. Most comparators only compare objects of one class, and this method has only to be invoked once to test them. Invoking this method multiply is only required for bizarre comparators like this: compares only instances of Person. There exist Two subclasses of Person: Teacher & Pupil. Teachers are equal to other teachers if they teach the same subject and pupils are equal to each other if they study the same subjects but teachers are never equal to pupils. Arguably there should be seperate comparators, but the contract of Comparator doesn't forbid this.


setWrongType

public void setWrongType(Object wrongType)

testComparable

public void testComparable()

testIncomparable

public void testIncomparable()

testWrongTypeFirst

public void testWrongTypeFirst()

testWrongTypeSecond

public void testWrongTypeSecond()

testWrongTypeBoth

public void testWrongTypeBoth()

testNullFirst

public void testNullFirst()

testNullSecond

public void testNullSecond()

testNullBoth

public void testNullBoth()