Package generic.test

Class AbstractGTest

java.lang.Object
generic.test.AbstractGTest
Direct Known Subclasses:
AbstractGenericTest

public abstract class AbstractGTest extends 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.

  • Field Details

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

    • AbstractGTest

      public AbstractGTest()
  • Method Details

    • getTestDirectoryPath

      public static String getTestDirectoryPath()
    • getRandomInt

      public static int getRandomInt()
    • getRandomInt

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

      public static String getRandomString()
    • getRandomString

      public static String getRandomString(int min, int max)
    • assertArraysEqualOrdered

      public static void assertArraysEqualOrdered(String message, Object[] expected, 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(String message, Object[] expected, 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(List<?> expected, List<?> actual)
    • assertListEqualOrdered

      public static void assertListEqualOrdered(String message, List<?> expected, List<?> actual)
    • assertListEqualUnordered

      public static void assertListEqualUnordered(String message, List<?> expected, List<?> actual)
    • assertListEqualsArrayOrdered

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

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

      public static void assertArraysEqualUnordered(String[] expected, 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(Collection<T> collection, T... expected)
    • assertContainsExactly

      public static <T> void assertContainsExactly(Collection<T> expected, Collection<T> actual)
    • assertContainsString

      public static <T> void assertContainsString(String expected, String actual)
    • assertContainsStringIgnoringCase

      public static <T> void assertContainsStringIgnoringCase(String expected, String actual)
    • failWithException

      public static void failWithException(String message, Throwable e)
    • getName

      public 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(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(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(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(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(BooleanSupplier condition, 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(BooleanSupplier condition, Supplier<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(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(Supplier<T> supplier, 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(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(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(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: