Share

JUnit-addons

Tracker: Patches

5 POJO attribute equailty test - ID: 2849935
Last Update: Attachment added ( onemanbucket )

I created an extension to the EqualsHashCodeTestCase that uses reflections
to test equality for all attributes in a POJO. It's used in exactly the
same way as EqualsHashCodeTestCase.

This is what it does:
1) assert equalObj1.equals(equalObj2) and !equalObj1.equals(differentObj)
2) for all attributes in the class not annotated by ExcludeFromEquals
3a) change the attributes' value the value in equalObj1
3b) assert !equalObj1.equals(equalObj2) && equalObj1.hashCode() !=
equalObj2.hashCode()
3c) restore original value to the attribute in equalObj1.

I use it at work for most POJOS. If a developer adds/removes attributes and
forgets to update the equality and hashcode methods our test suite will
fail.
Attached tarball with the testsuite, annotation and a test case.

Depends on JRE 1.5, junit-3.8.1 and junit-addons-1.4


Erik Lindblad ( onemanbucket ) - 2009-09-03 13:15

5

Open

None

Nobody/Anonymous

None

None

Public


Comments




Log in to comment.

No follow-up comments have been posted.

Attached File ( 1 )

Filename Description Download
junit-addons-attribute-equality-patch.tar.gz .java files Download

Change ( 1 )

Field Old Value Date By
File Added 341624: junit-addons-attribute-equality-patch.tar.gz 2009-09-03 13:15 onemanbucket