Package com.helger.commons.mock
Class CommonsTestHelper
java.lang.Object
com.helger.commons.mock.CommonsTestHelper
This class contains default test methods to test the correctness of
implementations of standard methods.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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 Details
-
_assertEquals
-
testEqualsImplementationWithEqualContentObject
-
testEqualsImplementationWithDifferentContentObject
-
testHashcodeImplementationWithEqualContentObject
-
testHashcodeImplementationWithDifferentContentObject
-
testToStringImplementation
Test the toString implementation of the passed object. It may not be empty, and consistent.- Parameters:
aObject- The object to be tested.
-
testToStringImplementationWithEqualContentObject
-
testToStringImplementationWithDifferentContentObject
-
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
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
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.
-