Package generic.test

Class AbstractGTest

  • Direct Known Subclasses:
    AbstractGenericTest

    public abstract class AbstractGTest
    extends java.lang.Object
    A root for system tests that provides known system information.

    This class exists so that fast unit tests have a place to share data without having the slowness of more heavy weight concepts like Application, logging, etc.

    !! WARNING !! This test is meant to initialize quickly. All file I/O should be avoided.

    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractGTest()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertArraysEqualOrdered​(java.lang.String message, java.lang.Object[] expected, java.lang.Object[] actual)
      Compares the contents of two arrays to determine if they are equal.
      static void assertArraysEqualUnordered​(java.lang.String[] expected, java.lang.String[] actual)
      Compares the contents of two arrays to determine if they are equal
      static void assertArraysEqualUnordered​(java.lang.String message, java.lang.Object[] expected, java.lang.Object[] actual)
      Compares the contents of two arrays to determine if they are equal.
      static <T> void assertContainsExactly​(java.util.Collection<T> expected, java.util.Collection<T> actual)  
      static <T> void assertContainsExactly​(java.util.Collection<T> collection, T... expected)  
      static void assertListEqualOrdered​(java.lang.String message, java.util.List<?> expected, java.util.List<?> actual)  
      static void assertListEqualOrdered​(java.util.List<?> expected, java.util.List<?> actual)  
      static <T> void assertListEqualsArrayOrdered​(java.util.List<T> actual, T... expected)  
      static void assertListEqualsArrayUnordered​(java.util.List<?> actual, java.lang.Object... expected)  
      static void assertListEqualUnordered​(java.lang.String message, java.util.List<?> expected, java.util.List<?> actual)  
      static byte[] bytes​(int... unsignedBytes)
      Friendly way to create an array of bytes with static values.
      static void failWithException​(java.lang.String message, java.lang.Throwable e)  
      java.lang.String getName()
      Returns the current test method name
      static int getRandomInt()  
      static int getRandomInt​(int min, int max)  
      static java.lang.String getRandomString()  
      static java.lang.String getRandomString​(int min, int max)  
      static java.lang.String getTestDirectoryPath()  
      static long sleep​(long timeMs)  
      static void waitFor​(java.util.concurrent.atomic.AtomicBoolean ab)
      Waits for the given AtomicBoolean to return true.
      static void waitFor​(java.util.concurrent.CountDownLatch latch)
      Waits for the given latch to be counted-down
      static void waitFor​(java.util.function.BooleanSupplier condition)
      Waits for the given condition to return true
      static <T> T waitFor​(java.util.function.Supplier<T> supplier)
      Waits for the value returned by the supplier to be non-null, throwing an exception if that does not happen by the default timeout.
      static <T> T waitFor​(java.util.function.Supplier<T> supplier, java.lang.String failureMessage)
      Waits for the value returned by the supplier to be non-null, throwing an exception if that does not happen by the default timeout.
      static void waitForCondition​(java.util.function.BooleanSupplier condition)
      Waits for the given condition to return true
      static void waitForCondition​(java.util.function.BooleanSupplier condition, java.lang.String failureMessage)
      Waits for the given condition to return true
      static void waitForCondition​(java.util.function.BooleanSupplier condition, java.util.function.Supplier<java.lang.String> failureMessageSupplier)
      Waits for the given condition to return true
      static void waitForConditionWithoutFailing​(java.util.function.BooleanSupplier supplier)
      Waits for the given condition to return true.
      static <T> T waitForValue​(java.util.function.Supplier<T> supplier)
      Waits for the value returned by the supplier to be non-null, throwing an exception if that does not happen by the default timeout.
      static <T> T waitForValueWithoutFailing​(java.util.function.Supplier<T> supplier)
      Waits for the value returned by the supplier to be non-null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BATCH_MODE

        public static final boolean BATCH_MODE
      • PARALLEL_MODE

        protected static final boolean PARALLEL_MODE
      • DEFAULT_WAIT_DELAY

        public static final int DEFAULT_WAIT_DELAY
      • DEFAULT_WAIT_TIMEOUT

        public static final int DEFAULT_WAIT_TIMEOUT
      • DEFAULT_WINDOW_TIMEOUT

        public static final int DEFAULT_WINDOW_TIMEOUT
      • PRIVATE_LONG_WAIT_TIMEOUT

        protected static final int PRIVATE_LONG_WAIT_TIMEOUT
      • testName

        public org.junit.rules.TestName testName
    • Constructor Detail

      • AbstractGTest

        public AbstractGTest()
    • Method Detail

      • getTestDirectoryPath

        public static java.lang.String getTestDirectoryPath()
      • getRandomInt

        public static int getRandomInt()
      • getRandomInt

        public static int getRandomInt​(int min,
                                       int max)
      • getRandomString

        public static java.lang.String getRandomString()
      • getRandomString

        public static java.lang.String getRandomString​(int min,
                                                       int max)
      • assertArraysEqualOrdered

        public static void assertArraysEqualOrdered​(java.lang.String message,
                                                    java.lang.Object[] expected,
                                                    java.lang.Object[] actual)
        Compares the contents of two arrays to determine if they are equal. The contents must match in the same order. If message is null, then a generic error message will be printed.
        Parameters:
        message - The message to print upon failure; can be null
        expected - The expected array.
        actual - The actual array.
      • assertArraysEqualUnordered

        public static void assertArraysEqualUnordered​(java.lang.String message,
                                                      java.lang.Object[] expected,
                                                      java.lang.Object[] actual)
        Compares the contents of two arrays to determine if they are equal. The contents do not have to be in the same order. If message is null, then a generic error message will be printed.
        Parameters:
        message - The message to print upon failure; can be null
        expected - The expected array.
        actual - The actual array.
      • assertListEqualOrdered

        public static void assertListEqualOrdered​(java.util.List<?> expected,
                                                  java.util.List<?> actual)
      • assertListEqualOrdered

        public static void assertListEqualOrdered​(java.lang.String message,
                                                  java.util.List<?> expected,
                                                  java.util.List<?> actual)
      • assertListEqualUnordered

        public static void assertListEqualUnordered​(java.lang.String message,
                                                    java.util.List<?> expected,
                                                    java.util.List<?> actual)
      • assertListEqualsArrayOrdered

        @SafeVarargs
        public static <T> void assertListEqualsArrayOrdered​(java.util.List<T> actual,
                                                            T... expected)
      • assertListEqualsArrayUnordered

        public static void assertListEqualsArrayUnordered​(java.util.List<?> actual,
                                                          java.lang.Object... expected)
      • assertArraysEqualUnordered

        public static void assertArraysEqualUnordered​(java.lang.String[] expected,
                                                      java.lang.String[] actual)
        Compares the contents of two arrays to determine if they are equal
        Parameters:
        expected - The expected array.
        actual - The actual array.
      • assertContainsExactly

        @SafeVarargs
        public static <T> void assertContainsExactly​(java.util.Collection<T> collection,
                                                     T... expected)
      • assertContainsExactly

        public static <T> void assertContainsExactly​(java.util.Collection<T> expected,
                                                     java.util.Collection<T> actual)
      • failWithException

        public static void failWithException​(java.lang.String message,
                                             java.lang.Throwable e)
      • getName

        public java.lang.String getName()
        Returns the current test method name
        Returns:
        the current test method name
      • bytes

        public static byte[] bytes​(int... unsignedBytes)
        Friendly way to create an array of bytes with static values.
        Parameters:
        unsignedBytes - var-args list of unsigned byte values (ie. 0..255)
        Returns:
        array of bytes
      • sleep

        public static long sleep​(long timeMs)
      • waitFor

        public static void waitFor​(java.util.concurrent.CountDownLatch latch)
        Waits for the given latch to be counted-down
        Parameters:
        latch - the latch to await
        Throws:
        junit.framework.AssertionFailedError - if the condition is not met within the timeout period
      • waitFor

        public static void waitFor​(java.util.concurrent.atomic.AtomicBoolean ab)
                            throws junit.framework.AssertionFailedError
        Waits for the given AtomicBoolean to return true. This is a convenience method for waitFor(BooleanSupplier).
        Parameters:
        ab - the atomic boolean
        Throws:
        junit.framework.AssertionFailedError - if the condition is not met within the timeout period
      • waitFor

        public static void waitFor​(java.util.function.BooleanSupplier condition)
                            throws junit.framework.AssertionFailedError
        Waits for the given condition to return true
        Parameters:
        condition - the condition that returns true when satisfied
        Throws:
        junit.framework.AssertionFailedError - if the condition is not met within the timeout period
      • waitForCondition

        public static void waitForCondition​(java.util.function.BooleanSupplier condition)
                                     throws junit.framework.AssertionFailedError
        Waits for the given condition to return true
        Parameters:
        condition - the condition that returns true when satisfied
        Throws:
        junit.framework.AssertionFailedError - if the condition is not met within the timeout period
      • waitForCondition

        public static void waitForCondition​(java.util.function.BooleanSupplier condition,
                                            java.lang.String failureMessage)
                                     throws junit.framework.AssertionFailedError
        Waits for the given condition to return true
        Parameters:
        condition - the condition that returns true when satisfied
        failureMessage - the message to print upon the timeout being reached
        Throws:
        junit.framework.AssertionFailedError - if the condition is not met within the timeout period
      • waitForCondition

        public static void waitForCondition​(java.util.function.BooleanSupplier condition,
                                            java.util.function.Supplier<java.lang.String> failureMessageSupplier)
                                     throws junit.framework.AssertionFailedError
        Waits for the given condition to return true
        Parameters:
        condition - the condition that returns true when satisfied
        failureMessageSupplier - the function that will supply the failure message in the event of a timeout.
        Throws:
        junit.framework.AssertionFailedError - if the condition is not met within the timeout period
      • waitForConditionWithoutFailing

        public static void waitForConditionWithoutFailing​(java.util.function.BooleanSupplier supplier)
        Waits for the given condition to return true. Most of the waitForCondition() methods throw an AssertionFailedError if the timeout period expires. This method allows you to setup a longer wait period by repeatedly calling this method.

        Most clients should use waitForCondition(BooleanSupplier).

        Parameters:
        supplier - the supplier that returns true when satisfied
      • waitFor

        public static <T> T waitFor​(java.util.function.Supplier<T> supplier,
                                    java.lang.String failureMessage)
        Waits for the value returned by the supplier to be non-null, throwing an exception if that does not happen by the default timeout.
        Parameters:
        supplier - the supplier of the value
        failureMessage - the message to print upon the timeout being reached
        Returns:
        the non-null value
        Throws:
        junit.framework.AssertionFailedError - if a non-null value is not returned within the timeout period
      • waitFor

        public static <T> T waitFor​(java.util.function.Supplier<T> supplier)
        Waits for the value returned by the supplier to be non-null, throwing an exception if that does not happen by the default timeout.
        Parameters:
        supplier - the supplier of the value
        Returns:
        the non-null value
        Throws:
        junit.framework.AssertionFailedError - if a non-null value is not returned within the timeout period
      • waitForValue

        public static <T> T waitForValue​(java.util.function.Supplier<T> supplier)
        Waits for the value returned by the supplier to be non-null, throwing an exception if that does not happen by the default timeout.
        Parameters:
        supplier - the supplier of the value
        Returns:
        the non-null value
        Throws:
        junit.framework.AssertionFailedError - if a non-null value is not returned within the timeout period
      • waitForValueWithoutFailing

        public static <T> T waitForValueWithoutFailing​(java.util.function.Supplier<T> supplier)
        Waits for the value returned by the supplier to be non-null. If the timeout period expires, then null will be returned. Most of the waitXyz() methods throw an AssertionFailedError if the timeout period expires. This method allows you to setup a longer wait period by repeatedly calling this method.

        Most clients should use waitForValue(Supplier).

        Parameters:
        supplier - the supplier of the value
        Returns:
        the value; may be null
        See Also:
        waitForValue(Supplier)