com.bm.utils
Class BeanEqualsTester

java.lang.Object
  extended by junit.framework.Assert
      extended by com.bm.utils.BeanEqualsTester

public final class BeanEqualsTester
extends junit.framework.Assert

Helper method to test the equality of beans.

Author:
Daniel Wiese

Method Summary
static
<T> void
testColletionsForEqual(java.util.Collection<? extends T> firstColl, java.util.Collection<? extends T> secondColl)
          Assert that the two collections are the same irrespective of order.
static
<T> void
testEqualsImplementationForEntityBeans(java.util.List<T> original, java.util.List<T> readed)
          Test the collection for equality by calling the equals method (if not equal a runntime excetion is thrown).
static
<T> void
testEqualsOnPersistentFields(java.util.List<T> original, java.util.List<T> readed, Introspector<T> intro)
          Test the collection for equality on persistent fields (if not equal a runntime excetion is thrown).
static
<T> void
testEqualsOnSize(java.util.List<T> original, java.util.List<T> readed)
          Test the collection for the size (if not equal a runntime excetion is.
 
Methods inherited from class junit.framework.Assert
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, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

testEqualsOnSize

public static <T> void testEqualsOnSize(java.util.List<T> original,
                                        java.util.List<T> readed)
Test the collection for the size (if not equal a runntime excetion is. thrown)

Type Parameters:
T - - the type of the bean
Parameters:
original - - the original collsecion ob beans
readed - - the readed collection from the DB

testEqualsOnPersistentFields

public static <T> void testEqualsOnPersistentFields(java.util.List<T> original,
                                                    java.util.List<T> readed,
                                                    Introspector<T> intro)
Test the collection for equality on persistent fields (if not equal a runntime excetion is thrown).

Type Parameters:
T - - the type of the bean
Parameters:
original - - the original collsecion ob beans
readed - - the readed collection from the DB
intro - - the introspector

testColletionsForEqual

public static <T> void testColletionsForEqual(java.util.Collection<? extends T> firstColl,
                                              java.util.Collection<? extends T> secondColl)
Assert that the two collections are the same irrespective of order.

Type Parameters:
T - - the type of the collection
Parameters:
firstColl - The first collection
secondColl - The second collection

testEqualsImplementationForEntityBeans

public static <T> void testEqualsImplementationForEntityBeans(java.util.List<T> original,
                                                              java.util.List<T> readed)
Test the collection for equality by calling the equals method (if not equal a runntime excetion is thrown). The preconditions are: We expect that the list do not contain duplicate elements - every element should represent a different row in the database!
Additional preconditions are:
- 2 Entitybeans representing different database-rows are NEVER equal.
- Every bean instance representing the same DB row is always equal.
- 2 equal beans MUST have the same hash code.
- N bans (e.g 30) should have different hash codes.

Type Parameters:
T - - the type of the bean
Parameters:
original - - the original collection ob beans
readed - - the readed collection from the DB


Copyright © 2008. All Rights Reserved.