|
JUnit-addons version 1.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--junit.framework.Assert | +--junit.framework.TestCase | +--junitx.extensions.EqualsHashCodeTestCase
Extend me in order to test a class's functional compliance with the
equals
and hashCode
contract.
Override my createInstance
and
createNotEqualInstance
methods to
provide me with objects to test against. Both methods should return
objects that are of the same class.
WARNING: Extend me only if your class overrides
equals
to test for equivalence. If your class's
equals
tests for identity or preserves the behavior from
Object
, I'm not interested, because I expect
createInstance
to return equivalent but distinct objects.
Object.equals(Object)
,
Object.hashCode()
Constructor Summary | |
EqualsHashCodeTestCase(java.lang.String name)
Creates a new test. |
Method Summary | |
protected abstract java.lang.Object |
createInstance()
Creates and returns an instance of the class under test. |
protected abstract java.lang.Object |
createNotEqualInstance()
Creates and returns an instance of the class under test. |
protected void |
setUp()
Sets up the test fixture. |
void |
testEqualsAgainstNewObject()
Tests whether equals holds up against a new
Object (should always be false ). |
void |
testEqualsAgainstNull()
Tests whether equals holds up against null . |
void |
testEqualsAgainstUnequalObjects()
Tests whether equals holds up against objects that should
not compare equal. |
void |
testEqualsIsConsistentAcrossInvocations()
Tests whether equals is consistent. |
void |
testEqualsIsReflexive()
Tests whether equals is reflexive. |
void |
testEqualsIsSymmetricAndTransitive()
Tests whether equals is symmetric and
transitive. |
void |
testHashCodeContract()
Tests the hashCode contract. |
void |
testHashCodeIsConsistentAcrossInvocations()
Tests the consistency of hashCode . |
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 |
public EqualsHashCodeTestCase(java.lang.String name)
name
- name of the testMethod Detail |
protected abstract java.lang.Object createInstance() throws java.lang.Exception
java.lang.Exception
protected abstract java.lang.Object createNotEqualInstance() throws java.lang.Exception
createInstance
.
java.lang.Exception
protected void setUp() throws java.lang.Exception
setUp
in class junit.framework.TestCase
java.lang.Exception
public final void testEqualsAgainstNewObject()
equals
holds up against a new
Object
(should always be false
).
public final void testEqualsAgainstNull()
equals
holds up against null
.
public final void testEqualsAgainstUnequalObjects()
equals
holds up against objects that should
not compare equal.
public final void testEqualsIsConsistentAcrossInvocations()
equals
is consistent.
public final void testEqualsIsReflexive()
equals
is reflexive.
public final void testEqualsIsSymmetricAndTransitive()
equals
is symmetric and
transitive.
public final void testHashCodeContract()
hashCode
contract.
public final void testHashCodeIsConsistentAcrossInvocations()
hashCode
.
|
JUnit-addons version 1.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |