JUnit-addons
version 1.4

junitx.extensions
Class ComparabilityTestCase

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--junit.framework.TestCase
              |
              +--junitx.extensions.ComparabilityTestCase
All Implemented Interfaces:
junit.framework.Test

public abstract class ComparabilityTestCase
extends junit.framework.TestCase

Extend me in order to test a class's functional compliance with the Comparable interface.

Override my createLessInstance, createEqualInstance, and createGreaterInstance methods to provide me with objects to test against. These methods should return objects that are of the same class.

Version:
$Revision: 1.3 $ $Date: 2003/03/21 06:13:47 $
Author:
Paul Holser
See Also:
Comparable

Constructor Summary
ComparabilityTestCase(java.lang.String name)
          Creates a new test.
 
Method Summary
protected  void checkForEquality(java.lang.Comparable c1, java.lang.Comparable c2)
          Override as a no-op if you do not require that createEqualInstance() return distinct but equivalent objects.
protected abstract  java.lang.Comparable createEqualInstance()
          Creates and returns an instance of the class under test.
protected abstract  java.lang.Comparable createGreaterInstance()
          Creates and returns an instance of the class under test.
protected abstract  java.lang.Comparable createLessInstance()
          Creates and returns an instance of the class under test.
protected  void setUp()
          Sets up the test fixture.
 void testForClassCastException()
          Tests whether compareTo throws a ClassCastException when appropriate.
 void testForReverseSigns()
          Tests whether sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y given to this test.
 void testForSameSigns()
          Tests whether sgn(x.compareTo(z)) == sgn(y.compareTo(z)) for all z when x.compareTo(y) == 0.
 void testReturnValues()
          Tests for sensible return values from the class under test's compareTo method.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, name, run, run, runBare, runTest, setName, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, 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
 

Constructor Detail

ComparabilityTestCase

public ComparabilityTestCase(java.lang.String name)
Creates a new test.

Parameters:
name - name of the test
Method Detail

createLessInstance

protected abstract java.lang.Comparable createLessInstance()
                                                    throws java.lang.Exception
Creates and returns an instance of the class under test.

Returns:
a new instance of the class under test; each object returned from this method should compare less than the objects returned from createEqualInstance()
Throws:
java.lang.Exception

createEqualInstance

protected abstract java.lang.Comparable createEqualInstance()
                                                     throws java.lang.Exception
Creates and returns an instance of the class under test.

Returns:
a new instance of the class under test; each object returned from this method should compare equal to each other
Throws:
java.lang.Exception

createGreaterInstance

protected abstract java.lang.Comparable createGreaterInstance()
                                                       throws java.lang.Exception
Creates and returns an instance of the class under test.

Returns:
a new instance of the class under test; each object returned from this method should compare greater than the objects returned from createEqualInstance()
Throws:
java.lang.Exception

setUp

protected void setUp()
              throws java.lang.Exception
Sets up the test fixture.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception

checkForEquality

protected void checkForEquality(java.lang.Comparable c1,
                                java.lang.Comparable c2)
Override as a no-op if you do not require that createEqualInstance() return distinct but equivalent objects.


testForReverseSigns

public final void testForReverseSigns()
Tests whether sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y given to this test.


testForSameSigns

public final void testForSameSigns()
Tests whether sgn(x.compareTo(z)) == sgn(y.compareTo(z)) for all z when x.compareTo(y) == 0.


testReturnValues

public final void testReturnValues()
Tests for sensible return values from the class under test's compareTo method. Doing so effectively tests the transitivity of compareTo also-- (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.


testForClassCastException

public final void testForClassCastException()
                                     throws java.lang.Exception
Tests whether compareTo throws a ClassCastException when appropriate.

java.lang.Exception

JUnit-addons
version 1.4

Copyright © 2002-2003 Vladimir R. Bossicard. All Rights Reserved.