public class TestCondition
extends java.lang.Object
TestCondition in unit test, designed to check a condition for something that is
happening in a different thread. Allowing a test to efficiently block till the testable
action has finished.
This tool is used often within threadly's own unit tests. Please use those as examples using this class.
| Modifier and Type | Class and Description |
|---|---|
static class |
TestCondition.ConditionTimeoutException
Thrown if condition is still false after a given timeout.
|
| Constructor and Description |
|---|
TestCondition()
This constructor is expected to have
get() overridden, otherwise an exception will be
thrown when this condition is checked/used. |
TestCondition(java.util.function.Supplier<java.lang.Boolean> condition)
Construct a new test condition with a provided supplier for when the state changes.
|
| Modifier and Type | Method and Description |
|---|---|
void |
blockTillTrue()
Blocks till condition is true, useful for asynchronism operations, waiting for them to
complete in other threads during unit tests.
|
void |
blockTillTrue(int timeoutInMillis)
Blocks till condition is true, useful for asynchronism operations, waiting for them to
complete in other threads during unit tests.
|
void |
blockTillTrue(int timeoutInMillis,
int pollIntervalInMillis)
Blocks till condition is true, useful for asynchronism operations, waiting for them to
complete in other threads during unit tests.
|
boolean |
get()
Getter for the conditions current state.
|
public TestCondition()
get() overridden, otherwise an exception will be
thrown when this condition is checked/used.public TestCondition(java.util.function.Supplier<java.lang.Boolean> condition)
TestCondition() and then the condition can
be reported by overriding get().condition - Condition to checkpublic boolean get()
TestCondition() this
must be overridden. Otherwise this will return the result from the provided supplier at
construction.true if readypublic void blockTillTrue()
This uses a default timeout of 10 seconds, and a poll interval of 10ms
public void blockTillTrue(int timeoutInMillis)
This uses the default poll interval of 10ms
timeoutInMillis - time to wait for value to become truepublic void blockTillTrue(int timeoutInMillis,
int pollIntervalInMillis)
timeoutInMillis - time to wait for value to become truepollIntervalInMillis - time to sleep between checks