@Deprecated
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
Deprecated.
Thrown if condition is still false after a given timeout.
|
Constructor and Description |
---|
TestCondition()
Deprecated.
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<? extends T> supplier,
java.util.function.Predicate<? super T> predicate)
Deprecated.
Construct a new
TestCondition where one function will supply a result and a second
function will test that result to see if the condition is met. |
TestCondition(java.util.function.Supplier<java.lang.Boolean> condition)
Deprecated.
Construct a new
TestCondition with a provided supplier for when the state changes. |
Modifier and Type | Method and Description |
---|---|
void |
blockTillTrue()
Deprecated.
Blocks till condition is true, useful for asynchronism operations, waiting for them to
complete in other threads during unit tests.
|
void |
blockTillTrue(int timeoutInMillis)
Deprecated.
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)
Deprecated.
Blocks till condition is true, useful for asynchronism operations, waiting for them to
complete in other threads during unit tests.
|
boolean |
get()
Deprecated.
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
with a provided supplier for when the state changes.
Alternatively this can be constructed with TestCondition()
and then the condition can
be reported by overriding get()
.condition
- Condition to check forpublic TestCondition(java.util.function.Supplier<? extends T> supplier, java.util.function.Predicate<? super T> predicate)
TestCondition
where one function will supply a result and a second
function will test that result to see if the condition is met.T
- the type of object returned from the supplier and tested by the predicatesupplier
- The function to provide a result to testpredicate
- The predicate a result is provided to for checking the test conditionpublic 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