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 Details

    • _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 be null.
      aObject2 - Second object. May not be null.
    • 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 be null.
      aObject2 - Second object. May not be null.
    • 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 using testDefaultImplementationWithEqualContentObject(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 implementation ICloneable is OK. It creates a clone and than uses testDefaultImplementationWithEqualContentObject(Object, Object) to check for equality.
      Parameters:
      aCloneable - The cloneable object to test
    • testClone

      public static void testClone(@Nonnull IExplicitlyCloneable aCloneable)
      Test if the implementation IExplicitlyCloneable is OK. It creates a clone and than uses testDefaultImplementationWithEqualContentObject(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 be null.