public class WaitCondition extends Object
true
or a timeout to expire. The
condition is checked at regular interval. Both the timeout and polling interval can be configured
using the within(long, TimeUnit)
and checkEvery(long, TimeUnit)
methods
respectively.
Usage examples (using Java 8 lambda expressions):
expect("Query response contains 5 elements").until(() -> runQuery(), hasSize(5)); expect("Configuration object exists"). within(30, SECONDS). checkEvery(1, SECONDS). until(() -> configAdmin.getConfiguration(pid, null) != null);
Modifier and Type | Method and Description |
---|---|
WaitCondition |
checkEvery(long pollingInterval,
TimeUnit unit)
Sets the polling interval this
WaitCondition will use to re-evaluate the wait
condition. |
static WaitCondition |
expect(String description)
Creates a instance of this class using the default timeout (5s) and polling interval (500ms).
|
<R> R |
lastResult() |
WaitCondition |
until(Callable<Boolean> condition)
Waits until the value returned by the condition is
true , or the timeout expires. |
<T> WaitCondition |
until(Callable<T> currentValueRetriever,
org.hamcrest.Matcher<T> matchCondition)
Waits until the value returned by the
Callable satisfies the Matcher 's
condition, or the timeout expires. |
WaitCondition |
within(long timeout,
TimeUnit unit)
Sets the timeout on this
WaitCondition . |
public static WaitCondition expect(String description)
description
- short description of what the wait condition is expectingWaitCondition
instancepublic WaitCondition within(long timeout, TimeUnit unit)
WaitCondition
.timeout
- timeout to useunit
- timeout unitWaitCondition
objectpublic WaitCondition checkEvery(long pollingInterval, TimeUnit unit)
WaitCondition
will use to re-evaluate the wait
condition.pollingInterval
- polling interval to useunit
- polling interval unitWaitCondition
objectpublic <T> WaitCondition until(Callable<T> currentValueRetriever, org.hamcrest.Matcher<T> matchCondition)
Callable
satisfies the Matcher
's
condition, or the timeout expires. The wait condition will be re-evaluated every polling
interval. If the timeout expires or an exception occurs while waiting, the current test will be
failed.T
- type of the value returned by the Callable
currentValueRetriever
- object to call to retrieve the value to wait onmatchCondition
- matcher used to determine whether the condition has been met or notpublic WaitCondition until(Callable<Boolean> condition)
true
, or the timeout expires. The
wait condition will be re-evaluated every polling interval. If the timeout expires or an
exception occurs while waiting, the current test will be failed.condition
- object that indicates whether the wait condition has been met or notpublic <R> R lastResult()
This work is licensed under a Creative Commons Attribution 4.0 International License.