Package generic.test
Class AbstractGTest
java.lang.Object
generic.test.AbstractGTest
- Direct Known Subclasses:
AbstractGenericTest
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 Summary
Modifier and TypeFieldDescriptionstatic final boolean
static final int
static final int
static final int
protected static final boolean
protected static final int
org.junit.rules.TestName
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertArraysEqualOrdered
(String message, Object[] expected, Object[] actual) Compares the contents of two arrays to determine if they are equal.static void
assertArraysEqualUnordered
(String[] expected, String[] actual) Compares the contents of two arrays to determine if they are equalstatic void
assertArraysEqualUnordered
(String message, Object[] expected, Object[] actual) Compares the contents of two arrays to determine if they are equal.static <T> void
assertContainsExactly
(Collection<T> expected, Collection<T> actual) static <T> void
assertContainsExactly
(Collection<T> collection, T... expected) static <T> void
assertContainsString
(String expected, String actual) static <T> void
assertContainsStringIgnoringCase
(String expected, String actual) static void
assertListEqualOrdered
(String message, List<?> expected, List<?> actual) static void
assertListEqualOrdered
(List<?> expected, List<?> actual) static <T> void
assertListEqualsArrayOrdered
(List<T> actual, T... expected) static void
assertListEqualsArrayUnordered
(List<?> actual, Object... expected) static void
assertListEqualUnordered
(String message, List<?> expected, List<?> actual) static byte[]
bytes
(int... unsignedBytes) Friendly way to create an array of bytes with static values.static void
failWithException
(String message, Throwable e) getName()
Returns the current test method namestatic int
static int
getRandomInt
(int min, int max) static String
static String
getRandomString
(int min, int max) static String
static long
sleep
(long timeMs) static void
waitFor
(AtomicBoolean ab) Waits for the given AtomicBoolean to return true.static void
waitFor
(CountDownLatch latch) Waits for the given latch to be counted-downstatic void
waitFor
(BooleanSupplier condition) Waits for the given condition to return truestatic <T> T
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
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
(BooleanSupplier condition) Waits for the given condition to return truestatic void
waitForCondition
(BooleanSupplier condition, String failureMessage) Waits for the given condition to return truestatic void
waitForCondition
(BooleanSupplier condition, Supplier<String> failureMessageSupplier) Waits for the given condition to return truestatic void
Waits for the given condition to return true.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.static <T> T
waitForValueWithoutFailing
(Supplier<T> supplier) Waits for the value returned by the supplier to be non-null.
-
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
-
getRandomInt
public static int getRandomInt() -
getRandomInt
public static int getRandomInt(int min, int max) -
getRandomString
-
getRandomString
-
assertArraysEqualOrdered
Compares the contents of two arrays to determine if they are equal. The contents must match in the same order. Ifmessage
isnull
, then a generic error message will be printed.- Parameters:
message
- The message to print upon failure; can be nullexpected
- The expected array.actual
- The actual array.
-
assertArraysEqualUnordered
Compares the contents of two arrays to determine if they are equal. The contents do not have to be in the same order. Ifmessage
isnull
, then a generic error message will be printed.- Parameters:
message
- The message to print upon failure; can be nullexpected
- The expected array.actual
- The actual array.
-
assertListEqualOrdered
-
assertListEqualOrdered
-
assertListEqualUnordered
-
assertListEqualsArrayOrdered
-
assertListEqualsArrayUnordered
-
assertArraysEqualUnordered
Compares the contents of two arrays to determine if they are equal- Parameters:
expected
- The expected array.actual
- The actual array.
-
assertContainsExactly
-
assertContainsExactly
-
assertContainsString
-
assertContainsStringIgnoringCase
-
failWithException
-
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
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
Waits for the given AtomicBoolean to return true. This is a convenience method forwaitFor(BooleanSupplier)
.- Parameters:
ab
- the atomic boolean- Throws:
junit.framework.AssertionFailedError
- if the condition is not met within the timeout period
-
waitFor
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 satisfiedfailureMessage
- 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 satisfiedfailureMessageSupplier
- 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
Waits for the given condition to return true. Most of thewaitForCondition()
methods throw anAssertionFailedError
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
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 valuefailureMessage
- 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
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
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
Waits for the value returned by the supplier to be non-null. If the timeout period expires, then null will be returned. Most of thewaitXyz()
methods throw anAssertionFailedError
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:
-