public abstract class ComparabilityTestCase
extends junit.framework.TestCase
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.
Comparable| Constructor and Description |
|---|
ComparabilityTestCase(java.lang.String name)
Creates a new test.
|
| Modifier and Type | Method and Description |
|---|---|
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. |
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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, tearDown, toStringpublic ComparabilityTestCase(java.lang.String name)
name - name of the testprotected abstract java.lang.Comparable createLessInstance()
throws java.lang.Exception
createEqualInstance()java.lang.Exceptionprotected abstract java.lang.Comparable createEqualInstance()
throws java.lang.Exception
java.lang.Exceptionprotected abstract java.lang.Comparable createGreaterInstance()
throws java.lang.Exception
createEqualInstance()java.lang.Exceptionprotected void setUp()
throws java.lang.Exception
setUp in class junit.framework.TestCasejava.lang.Exceptionprotected void checkForEquality(java.lang.Comparable c1,
java.lang.Comparable c2)
createEqualInstance() return distinct but
equivalent objects.public final void testForReverseSigns()
sgn(x.compareTo(y)) == -sgn(y.compareTo(x))
for all x and y given to this test.public final void testForSameSigns()
sgn(x.compareTo(z)) == sgn(y.compareTo(z))
for all z when x.compareTo(y) == 0.public final void testReturnValues()
compareTo method. Doing so effectively tests the
transitivity of compareTo also--
(x.compareTo(y)>0 && y.compareTo(z)>0) implies
x.compareTo(z)>0.public final void testForClassCastException()
throws java.lang.Exception
compareTo throws a ClassCastException when
appropriate.java.lang.ExceptionCopyright © ${project.year} ${project.holder}. All Rights Reserved.