public class Assert
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Assert.AssertWithRetry |
static class |
Assert.AssertWithRetryRespectingException |
static class |
Assert.AssertWithRetrySupport<S extends RetryingStrategy<java.lang.Void>> |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ASSERT_CLASSNAME |
| Modifier | Constructor and Description |
|---|---|
protected |
Assert() |
| Modifier and Type | Method and Description |
|---|---|
static void |
assertThat(boolean actual) |
static void |
assertThat(java.lang.String reason,
boolean actual) |
static <T> void |
assertThat(java.lang.String reason,
T actual,
org.hamcrest.Matcher<T> matcher)
Asserts that
actual satisfies the condition specified by
matcher. |
static <T> void |
assertThat(T actual,
org.hamcrest.Matcher<T> matcher)
Asserts that
actual satisfies the condition specified by
matcher. |
static Assert.AssertWithRetryRespectingException |
assertWithRetries(int maxNumbersOfRetries)
Creates an
Assert.AssertWithRetry that allows to test the assertion at most maxNumbersOfRetries times until it must succeed. |
static Assert.AssertWithRetry |
assertWithRetry(RetryingStrategy<java.lang.Void> retryingStrategy)
Creates an
Assert.AssertWithRetry that uses a custom RetryingStrategy to satisfy a given assertion. |
static Assert.AssertWithRetryRespectingException |
assertWithTimeout(Duration duration)
Creates an
Assert.AssertWithRetry that allows a timeout in which the assertion must be satisfied. |
static Assert.AssertWithRetryRespectingException |
assertWithTimeout(java.lang.String duration)
Creates an
Assert.AssertWithRetry that allows a timeout in which the assertion must be satisfied. |
static void |
fail() |
static void |
fail(java.lang.String message) |
protected static java.lang.StackTraceElement[] |
getCleanStackTrace() |
public static void assertThat(boolean actual)
public static void assertThat(@Nullable
java.lang.String reason,
boolean actual)
public static <T> void assertThat(@Nullable
T actual,
@Nonnull
org.hamcrest.Matcher<T> matcher)
actual satisfies the condition specified by
matcher. If not, an AssertionError is thrown with
information about the matcher and failing value. Example:
assertThat(0, is(1)); // fails:
// failure message:
// expected: is <1>
// got value: <0>
assertThat(0, is(not(1))) // passes
T - the static type accepted by the matcher (this can flag obvious
compile-time problems such as assertThat(1, is("a"))actual - the computed value being comparedmatcher - an expression, built of Matchers, specifying allowed
valuesCoreMatchers,
JUnitMatcherspublic static <T> void assertThat(@Nullable
java.lang.String reason,
@Nullable
T actual,
@Nonnull
org.hamcrest.Matcher<T> matcher)
actual satisfies the condition specified by
matcher. If not, an AssertionError is thrown with
the reason and information about the matcher and failing value. Example:
:
assertThat("Help! Integers don't work", 0, is(1)); // fails:
// failure message:
// Help! Integers don't work
// expected: is <1>
// got value: <0>
assertThat("Zero is one", 0, is(not(1))) // passes
T - the static type accepted by the matcher (this can flag obvious
compile-time problems such as assertThat(1, is("a"))reason - additional information about the erroractual - the computed value being comparedmatcher - an expression, built of Matchers, specifying allowed
valuesCoreMatchers,
JUnitMatcherspublic static void fail()
public static void fail(@Nullable
java.lang.String message)
@Nonnull protected static java.lang.StackTraceElement[] getCleanStackTrace()
@Nonnull public static Assert.AssertWithRetryRespectingException assertWithRetries(@Nonnegative int maxNumbersOfRetries)
Assert.AssertWithRetry that allows to test the assertion at most maxNumbersOfRetries times until it must succeed.
Otherwise an AssertionError is thrown.
This method allows a chained notation, e.g.:
assertWithRetry(3).that("some reasons", new Callable() {
@Override
public Boolean call() throws Exception {
return readValue();
}
}, equalTo(5));
With Java 1.8 or later, we can use the more straightforward lamba notation:
assertWithRetry(3).that(() -> readValue(), equalTo(5));
@Nonnull public static Assert.AssertWithRetryRespectingException assertWithTimeout(@Nonnull java.lang.String duration)
Assert.AssertWithRetry that allows a timeout in which the assertion must be satisfied. If the assertion still fails after this timeout
an {link AssertionError} is thrown.
This method allows a chained notation, e.g.:
assertWithRetry("3s").that("some reasons", new Callable() {
@Override
public Boolean call() throws Exception {
return readValue();
}
}, equalTo(5));
With Java 1.8 or later, we can use the more straightforward lamba notation:
assertWithRetry("3s").that(() -> readValue(), equalTo(5));
duration - the maximum time in Duration nation in which an assertion must succeed@Nonnull public static Assert.AssertWithRetryRespectingException assertWithTimeout(@Nonnull Duration duration)
Assert.AssertWithRetry that allows a timeout in which the assertion must be satisfied. If the assertion still fails after this timeout
an {link AssertionError} is thrown.
This method allows a chained notation, e.g.:
assertWithRetry(new Duration("3s")).that("some reasons", new Callable() {
@Override
public Boolean call() throws Exception {
return readValue();
}
}, equalTo(5));
With Java 1.8 or later, we can use the more straightforward lamba notation:
assertWithRetry(new Duration("3s")).that(() -> readValue(), equalTo(5));
duration - the maximum time as a Duration in which an assertion must succeed@Nonnull public static Assert.AssertWithRetry assertWithRetry(@Nonnull RetryingStrategy<java.lang.Void> retryingStrategy)
Assert.AssertWithRetry that uses a custom RetryingStrategy to satisfy a given assertion.
This method allows a chained notation, e.g.:
assertWithRetry(new RetryForSpecifiedTimeStrategy("5s")).that("some reasons", new Callable() {
@Override
public Boolean call() throws Exception {
return readValue();
}
}, equalTo(5));
With Java 1.8 or later, we can use the more straightforward lamba notation:
assertWithRetry(new RetryForSpecifiedTimeStrategy("5s")).that(() -> readValue(), equalTo(5));
retryingStrategy - the strategy to retry the assertion until is either succeeds or the strategy declines a retryCopyright © 2015 echocat. All Rights Reserved.