public static class Assert.AssertWithRetrySupport<S extends RetryingStrategy<java.lang.Void>>
extends java.lang.Object
| Constructor and Description |
|---|
AssertWithRetrySupport(S retryingStrategy)
Creates an assertion with a
RetryingStrategy to satisfiy a condition. |
| Modifier and Type | Method and Description |
|---|---|
protected S |
getRetryingStrategy() |
<T> void |
that(java.util.concurrent.Callable<T> fetchActual,
org.hamcrest.Matcher<T> matcher) |
<T> void |
that(java.lang.String reason,
java.util.concurrent.Callable<T> fetchActual,
org.hamcrest.Matcher<T> matcher)
Asserts that the return value of a
Callable fetchActual satisfies the condition specified by the matcher. |
public AssertWithRetrySupport(@Nonnull
S retryingStrategy)
RetryingStrategy to satisfiy a condition. For better readability
use Assert's factory methods assertWithTimeout or assertWithRetries.retryingStrategy - the RetryingStrategy that will be used to satisfy a given condition@Nonnull protected S getRetryingStrategy()
public <T> void that(@Nonnull
java.util.concurrent.Callable<T> fetchActual,
@Nonnull
org.hamcrest.Matcher<T> matcher)
throws java.lang.Exception
java.lang.Exceptionpublic <T> void that(@Nullable
java.lang.String reason,
@Nonnull
java.util.concurrent.Callable<T> fetchActual,
@Nonnull
org.hamcrest.Matcher<T> matcher)
throws java.lang.Exception
Callable fetchActual satisfies the condition specified by the matcher. If it doesn't, the
given RetryingStrategy is used to try to satisfy the condition. If it cannot succeed, an
AssertionError is thrown.
For instance, if we await an integer x to become 5 within five seconds, we could write:
assertWithTimeout("5s").that("some reasons", new Callable() {
@Override
public Boolean call() throws Exception {
return null;
}
}, equalTo(5));
With Java 1.8 or later, we can use the more straightforward lamba notation:
assertWithTimeout("5s").that("some reasons", () -> x, equalTo(5));
reason - additional information about the errorfetchActual - a callable that return the value to be compared
compile-time problems such as assertThat(1, is("a"))matcher - an expression, built of Matchers, specifying allowedjava.lang.ExceptionCopyright © 2015 echocat. All Rights Reserved.