Package generic.test
Class AbstractGTest
- java.lang.Object
-
- generic.test.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.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
BATCH_MODE
static int
DEFAULT_WAIT_DELAY
static int
DEFAULT_WAIT_TIMEOUT
static int
DEFAULT_WINDOW_TIMEOUT
protected static boolean
PARALLEL_MODE
protected static int
PRIVATE_LONG_WAIT_TIMEOUT
org.junit.rules.TestName
testName
-
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 equalstatic 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 void
failWithException(java.lang.String message, java.lang.Throwable e)
java.lang.String
getName()
Returns the current test method namestatic 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.CountDownLatch latch)
Waits for the given latch to be counted-downstatic void
waitFor(java.util.function.BooleanSupplier condition)
Waits for the given condition to return truestatic <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 truestatic void
waitForCondition(java.util.function.BooleanSupplier condition, java.lang.String failureMessage)
Waits for the given condition to return truestatic void
waitForCondition(java.util.function.BooleanSupplier condition, java.util.function.Supplier<java.lang.String> failureMessageSupplier)
Waits for the given condition to return truestatic 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.
-
-
-
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
-
-
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. 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
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. 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
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
-
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.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 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(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 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
public static void waitForConditionWithoutFailing(java.util.function.BooleanSupplier supplier)
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
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 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
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 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:
waitForValue(Supplier)
-
-