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
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final intstatic final intstatic final intorg.junit.rules.TestRuleThis rule handles theIgnoreUnfinishedannotationprotected static final booleanprotected static final intorg.junit.rules.TestRuleThis rule handles theRepeatedannotationorg.junit.rules.TestName -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertArraysEqualOrdered(String message, Object[] expected, Object[] actual) Compares the contents of two arrays to determine if they are equal.static voidassertArraysEqualUnordered(String[] expected, String[] actual) Compares the contents of two arrays to determine if they are equalstatic voidassertArraysEqualUnordered(String message, Object[] expected, Object[] actual) Compares the contents of two arrays to determine if they are equal.static <T> voidassertContainsExactly(Collection<T> expected, Collection<T> actual) static <T> voidassertContainsExactly(Collection<T> collection, T... expected) static <T> voidassertContainsString(String expected, String actual) static <T> voidassertContainsStringIgnoringCase(String expected, String actual) static voidassertListEqualOrdered(String message, List<?> expected, List<?> actual) static voidassertListEqualOrdered(List<?> expected, List<?> actual) static <T> voidassertListEqualsArrayOrdered(List<T> actual, T... expected) static voidassertListEqualsArrayUnordered(List<?> actual, Object... expected) static voidassertListEqualUnordered(String message, List<?> expected, List<?> actual) static byte[]bytes(int... unsignedBytes) Friendly way to create an array of bytes with static values.static voidfailWithException(String message, Throwable e) getName()Returns the current test method namestatic intstatic intgetRandomInt(int min, int max) static Stringstatic StringgetRandomString(int min, int max) static Stringstatic longsleep(long timeMs) static voidwaitFor(AtomicBoolean ab) Waits for the given AtomicBoolean to return true.static voidwaitFor(CountDownLatch latch) Waits for the given latch to be counted-downstatic voidwaitFor(BooleanSupplier condition) Waits for the given condition to return truestatic <T> TWaits 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> TWaits for the value returned by the supplier to be non-null, throwing an exception if that does not happen by the default timeout.static voidwaitForCondition(BooleanSupplier condition) Waits for the given condition to return truestatic voidwaitForCondition(BooleanSupplier condition, String failureMessage) Waits for the given condition to return truestatic voidwaitForCondition(BooleanSupplier condition, Supplier<String> failureMessageSupplier) Waits for the given condition to return truestatic voidWaits for the given condition to return true.static <T> TwaitForValue(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> TwaitForValueWithoutFailing(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 -
repeatedRule
public org.junit.rules.TestRule repeatedRuleThis rule handles theRepeatedannotationDuring batch mode, this rule should never be needed. This rule is included here as a convenience, in case a developer wants to use the
Repeatedannotation to diagnose a non-deterministic test failure. Without this rule, the annotation would be silently ignored. -
ignoreUnfinishedRule
public org.junit.rules.TestRule ignoreUnfinishedRuleThis rule handles theIgnoreUnfinishedannotation
-
-
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. Ifmessageisnull, 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. Ifmessageisnull, 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 anAssertionFailedErrorif 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 anAssertionFailedErrorif 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:
-