Class 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 Detail

      • 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
      • 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.