JUnit-addons
version 1.4

junitx.extensions
Class EqualsHashCodeTestCase

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

public abstract class EqualsHashCodeTestCase
extends junit.framework.TestCase

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.

Version:
$Revision: 1.2 $ $Date: 2003/02/06 20:43:52 $
Author:
Paul Holser
See Also:
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

EqualsHashCodeTestCase

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

Parameters:
name - name of the test
Method Detail

createInstance

protected abstract java.lang.Object createInstance()
                                            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

createNotEqualInstance

protected abstract java.lang.Object createNotEqualInstance()
                                                    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, but not to the objects returned from createInstance.
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

testEqualsAgainstNewObject

public final void testEqualsAgainstNewObject()
Tests whether equals holds up against a new Object (should always be false).


testEqualsAgainstNull

public final void testEqualsAgainstNull()
Tests whether equals holds up against null.


testEqualsAgainstUnequalObjects

public final void testEqualsAgainstUnequalObjects()
Tests whether equals holds up against objects that should not compare equal.


testEqualsIsConsistentAcrossInvocations

public final void testEqualsIsConsistentAcrossInvocations()
Tests whether equals is consistent.


testEqualsIsReflexive

public final void testEqualsIsReflexive()
Tests whether equals is reflexive.


testEqualsIsSymmetricAndTransitive

public final void testEqualsIsSymmetricAndTransitive()
Tests whether equals is symmetric and transitive.


testHashCodeContract

public final void testHashCodeContract()
Tests the hashCode contract.


testHashCodeIsConsistentAcrossInvocations

public final void testHashCodeIsConsistentAcrossInvocations()
Tests the consistency of hashCode.


JUnit-addons
version 1.4

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