Package com.helger.commons.mock
Class CommonsTestHelper
- java.lang.Object
-
- com.helger.commons.mock.CommonsTestHelper
-
@Immutable public final class CommonsTestHelper extends Object
This class contains default test methods to test the correctness of implementations of standard methods.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> void_assertEquals(String sMsg, T aObj1, T aObj2)static voidtestClone(IExplicitlyCloneable aCloneable)Test if the implementationIExplicitlyCloneableis OK.static <DATATYPE> voidtestDefaultImplementationWithDifferentContentObject(DATATYPE aObject1, DATATYPE aObject2)Check if two different objects are different to each other.static <DATATYPE> voidtestDefaultImplementationWithEqualContentObject(DATATYPE aObject1, DATATYPE aObject2)Check if two different objects (who may not be the same) are equal to each other.static <DATATYPE extends Serializable>
DATATYPEtestDefaultSerialization(DATATYPE aSerializable)Test the serializability of objects.static <DATATYPE> voidtestEqualsImplementationWithDifferentContentObject(DATATYPE aObject, DATATYPE aObject2)static <DATATYPE> voidtestEqualsImplementationWithEqualContentObject(DATATYPE aObject, DATATYPE aObject2)static voidtestGetClone(ICloneable<?> aCloneable)Test if the implementationICloneableis OK.static <DATATYPE> voidtestHashcodeImplementationWithDifferentContentObject(DATATYPE aObject1, DATATYPE aObject2)static <DATATYPE> voidtestHashcodeImplementationWithEqualContentObject(DATATYPE aObject, DATATYPE aObject2)static voidtestInParallel(int nCalls, IThrowingRunnable<? extends Exception> aRunnable)Run something in parallelstatic voidtestToStringImplementation(Object aObject)Test the toString implementation of the passed object.static <DATATYPE> voidtestToStringImplementationWithDifferentContentObject(DATATYPE aObject, DATATYPE aObject2)static <DATATYPE> voidtestToStringImplementationWithEqualContentObject(DATATYPE aObject, DATATYPE aObject2)
-
-
-
Method Detail
-
_assertEquals
public static <T> void _assertEquals(@Nonnull String sMsg, @Nullable T aObj1, @Nullable T aObj2)
-
testEqualsImplementationWithEqualContentObject
public static <DATATYPE> void testEqualsImplementationWithEqualContentObject(@Nonnull DATATYPE aObject, @Nonnull DATATYPE aObject2)
-
testEqualsImplementationWithDifferentContentObject
public static <DATATYPE> void testEqualsImplementationWithDifferentContentObject(@Nonnull DATATYPE aObject, @Nonnull DATATYPE aObject2)
-
testHashcodeImplementationWithEqualContentObject
public static <DATATYPE> void testHashcodeImplementationWithEqualContentObject(@Nonnull DATATYPE aObject, @Nonnull DATATYPE aObject2)
-
testHashcodeImplementationWithDifferentContentObject
public static <DATATYPE> void testHashcodeImplementationWithDifferentContentObject(@Nonnull DATATYPE aObject1, @Nonnull DATATYPE aObject2)
-
testToStringImplementation
public static void testToStringImplementation(@Nonnull Object aObject)
Test the toString implementation of the passed object. It may not be empty, and consistent.- Parameters:
aObject- The object to be tested.
-
testToStringImplementationWithEqualContentObject
public static <DATATYPE> void testToStringImplementationWithEqualContentObject(@Nonnull DATATYPE aObject, @Nonnull DATATYPE aObject2)
-
testToStringImplementationWithDifferentContentObject
public static <DATATYPE> void testToStringImplementationWithDifferentContentObject(@Nonnull DATATYPE aObject, @Nonnull DATATYPE aObject2)
-
testDefaultImplementationWithEqualContentObject
public static <DATATYPE> void testDefaultImplementationWithEqualContentObject(@Nonnull DATATYPE aObject1, @Nonnull DATATYPE aObject2)
Check if two different objects (who may not be the same) are equal to each other. Checks toString, equals and hashCode.- Type Parameters:
DATATYPE- The data type to be used- Parameters:
aObject1- First object. May not benull.aObject2- Second object. May not benull.
-
testDefaultImplementationWithDifferentContentObject
public static <DATATYPE> void testDefaultImplementationWithDifferentContentObject(@Nonnull DATATYPE aObject1, @Nonnull DATATYPE aObject2)
Check if two different objects are different to each other. Checks toString, equals and hashCode.- Type Parameters:
DATATYPE- The data type to be used- Parameters:
aObject1- First object. May not benull.aObject2- Second object. May not benull.
-
testDefaultSerialization
@Nonnull public static <DATATYPE extends Serializable> DATATYPE testDefaultSerialization(@Nonnull DATATYPE aSerializable)
Test the serializability of objects. First writes the object to a byte array stream, and then tries to rebuild it from there. After reading it performs an equals check usingtestDefaultImplementationWithEqualContentObject(Object, Object)- Type Parameters:
DATATYPE- The type of object to be serialized.- Parameters:
aSerializable- The object to be written and read- Returns:
- The newly read object
-
testGetClone
public static void testGetClone(@Nonnull ICloneable<?> aCloneable)
Test if the implementationICloneableis OK. It creates a clone and than usestestDefaultImplementationWithEqualContentObject(Object, Object)to check for equality.- Parameters:
aCloneable- The cloneable object to test
-
testClone
public static void testClone(@Nonnull IExplicitlyCloneable aCloneable)
Test if the implementationIExplicitlyCloneableis OK. It creates a clone and than usestestDefaultImplementationWithEqualContentObject(Object, Object)to check for equality.- Parameters:
aCloneable- The cloneable object to test- Since:
- 9.4.5
-
testInParallel
public static void testInParallel(@Nonnegative int nCalls, @Nonnull IThrowingRunnable<? extends Exception> aRunnable)
Run something in parallel- Parameters:
nCalls- The number of invocations of the passed runnable. Must be ≥ 0.aRunnable- The runnable to execute. May not benull.
-
-