public class Asserts
extends java.lang.Object
NOTE Selected routines in this class are originally copied from TestNG, to allow us to make assertions without having to introduce a runtime dependency on TestNG.
Modifier and Type | Class and Description |
---|---|
static class |
Asserts.BooleanWithMessage |
static class |
Asserts.ShouldHaveFailedPreviouslyAssertionError
Subclass of
AssertionError which indicates that code which should have thrown did not,
so that callers can disambiguate expected errors from this one. |
Modifier and Type | Field and Description |
---|---|
static Duration |
DEFAULT_LONG_TIMEOUT
Timeout for use when something should happen.
|
static Duration |
DEFAULT_SHORT_TIMEOUT
Timeout for use when waiting for other threads to (normally) finish.
|
static long |
THIRTY_SECONDS_TIMEOUT_MS |
Modifier and Type | Method and Description |
---|---|
static void |
assertEquals(boolean actual,
boolean expected)
Asserts that two booleans are equal.
|
static void |
assertEquals(boolean actual,
boolean expected,
java.lang.String message)
Asserts that two booleans are equal.
|
static void |
assertEquals(byte actual,
byte expected)
Asserts that two bytes are equal.
|
static void |
assertEquals(byte actual,
byte expected,
java.lang.String message)
Asserts that two bytes are equal.
|
static void |
assertEquals(char actual,
char expected)
Asserts that two chars are equal.
|
static void |
assertEquals(char actual,
char expected,
java.lang.String message)
Asserts that two chars are equal.
|
static void |
assertEquals(java.util.Collection<?> actual,
java.util.Collection<?> expected)
Asserts that two collections contain the same elements in the same order.
|
static void |
assertEquals(java.util.Collection<?> actual,
java.util.Collection<?> expected,
java.lang.String message)
Asserts that two collections contain the same elements in the same order.
|
static void |
assertEquals(double actual,
double expected,
double delta)
Asserts that two doubles are equal within a delta.
|
static void |
assertEquals(double actual,
double expected,
double delta,
java.lang.String message)
Asserts that two doubles are equal within a delta.
|
static void |
assertEquals(float actual,
float expected,
float delta)
Asserts that two floats are equal within a delta.
|
static void |
assertEquals(float actual,
float expected,
float delta,
java.lang.String message)
Asserts that two floats are equal within a delta.
|
static void |
assertEquals(int actual,
int expected)
Asserts that two ints are equal.
|
static void |
assertEquals(int actual,
int expected,
java.lang.String message)
Asserts that two ints are equal.
|
static void |
assertEquals(java.lang.Iterable<?> actual,
java.lang.Iterable<?> expected)
Asserts that two iterables return iterators with the same elements in the same order.
|
static void |
assertEquals(java.lang.Iterable<?> actual,
java.lang.Iterable<?> expected,
java.lang.String message)
Asserts that two iterables return iterators with the same elements in the same order.
|
static void |
assertEquals(java.util.Iterator<?> actual,
java.util.Iterator<?> expected)
Asserts that two iterators return the same elements in the same order.
|
static void |
assertEquals(java.util.Iterator<?> actual,
java.util.Iterator<?> expected,
java.lang.String message)
Asserts that two iterators return the same elements in the same order.
|
static void |
assertEquals(long actual,
long expected)
Asserts that two longs are equal.
|
static void |
assertEquals(long actual,
long expected,
java.lang.String message)
Asserts that two longs are equal.
|
static void |
assertEquals(java.util.Map<?,?> actual,
java.util.Map<?,?> expected)
Asserts that two maps are equal.
|
static void |
assertEquals(java.lang.Object[] actual,
java.lang.Object[] expected)
Asserts that two arrays contain the same elements in the same order.
|
static void |
assertEquals(java.lang.Object[] actual,
java.lang.Object[] expected,
java.lang.String message)
Asserts that two arrays contain the same elements in the same order.
|
static void |
assertEquals(java.lang.Object actual,
java.lang.Object expected)
Asserts that two objects are equal.
|
static void |
assertEquals(java.lang.Object actual,
java.lang.Object expected,
java.lang.String message)
Asserts that two objects are equal.
|
static void |
assertEquals(java.util.Set<?> actual,
java.util.Set<?> expected)
Asserts that two sets are equal.
|
static void |
assertEquals(java.util.Set<?> actual,
java.util.Set<?> expected,
java.lang.String message)
Assert set equals
|
static void |
assertEquals(short actual,
short expected)
Asserts that two shorts are equal.
|
static void |
assertEquals(short actual,
short expected,
java.lang.String message)
Asserts that two shorts are equal.
|
static void |
assertEquals(java.lang.String actual,
java.lang.String expected)
Asserts that two Strings are equal.
|
static void |
assertEquals(java.lang.String actual,
java.lang.String expected,
java.lang.String message)
Asserts that two Strings are equal.
|
static void |
assertEqualsIgnoringOrder(java.lang.Iterable<?> actual,
java.lang.Iterable<?> expected) |
static void |
assertEqualsIgnoringOrder(java.lang.Iterable<?> actual,
java.lang.Iterable<?> expected,
boolean logDuplicates,
java.lang.String errmsg) |
static void |
assertFails(java.util.concurrent.Callable<?> c) |
static void |
assertFails(java.lang.Runnable r) |
static void |
assertFailsWith(java.util.concurrent.Callable<?> c,
<any> exceptionChecker) |
static void |
assertFailsWith(java.util.concurrent.Callable<?> c,
groovy.lang.Closure<java.lang.Boolean> exceptionChecker)
Deprecated.
since 0.11.0; explicit groovy utilities/support will be deleted.
|
static void |
assertFailsWith(java.lang.Runnable r,
<any> exceptionChecker) |
static void |
assertFailsWith(java.lang.Runnable c,
java.lang.Class<? extends java.lang.Throwable> validException,
java.lang.Class<? extends java.lang.Throwable>... otherValidExceptions) |
static void |
assertFalse(boolean condition) |
static void |
assertFalse(boolean condition,
java.lang.String message)
Asserts that a condition is false.
|
static void |
assertInstanceOf(java.lang.Object obj,
java.lang.Class<?> type) |
static void |
assertNotNull(java.lang.Object object)
Assert that an object reference is not null.
|
static void |
assertNotNull(java.lang.Object object,
java.lang.String message)
Assert that an object reference is not null.
|
static <T> void |
assertNotPresent(Maybe<T> candidate) |
static void |
assertNull(java.lang.Object object)
Assert that an object reference is null.
|
static void |
assertNull(java.lang.Object object,
java.lang.String message)
Assert that an object reference is null.
|
static <T> void |
assertPresent(Maybe<T> candidate) |
static void |
assertReturnsEventually(java.lang.Runnable r,
Duration timeout) |
static void |
assertSameUnorderedContents(java.lang.Iterable<?> i1,
java.lang.Iterable<?> i2)
Ignores duplicates and order
|
static void |
assertSize(java.lang.Iterable<?> list,
int expectedSize) |
static void |
assertSize(java.util.Map<?,?> map,
int expectedSize) |
static void |
assertStringContains(java.lang.String input,
java.lang.String phrase1ToContain,
java.lang.String... optionalOtherPhrasesToContain) |
static void |
assertStringContainsAtLeastOne(java.lang.String input,
java.lang.String possiblePhrase1ToContain,
java.lang.String... optionalOtherPossiblePhrasesToContain) |
static void |
assertStringContainsIgnoreCase(java.lang.String input,
java.lang.String phrase1ToContain,
java.lang.String... optionalOtherPhrasesToContain) |
static void |
assertStringDoesNotContain(java.lang.String input,
java.lang.String phrase1ToNotContain,
java.lang.String... optionalOtherPhrasesToNotContain) |
static void |
assertStringMatchesRegex(java.lang.String input,
java.lang.String regex1ToMatch,
java.lang.String... optionalOtherRegexesToMatch) |
static <T> void |
assertThat(T object,
<any> condition) |
static <T> void |
assertThat(T object,
<any> condition,
java.lang.String message) |
static void |
assertTrue(boolean condition)
Asserts that a condition is true.
|
static void |
assertTrue(boolean condition,
java.lang.String message)
Asserts that a condition is true.
|
static <T> void |
continually(<any> supplier,
<any> predicate)
As
#continually(Supplier, Predicate, Duration, Duration, String) with defaults. |
static <T> void |
continually(<any> supplier,
<any> predicate,
Duration duration,
Duration period,
java.lang.String errMsg)
Asserts that continually the supplier gives a value accepted by the predicate.
|
static <T> void |
eventually(<any> supplier,
<any> predicate)
As
#eventually(Supplier, Predicate, Duration, Duration, String) with defaults. |
static <T> void |
eventually(<any> supplier,
<any> predicate,
Duration timeout)
As
#eventually(Supplier, Predicate, Duration, Duration, String) with default. |
static <T> void |
eventually(<any> supplier,
<any> predicate,
Duration timeout,
Duration period,
java.lang.String errMsg)
As
#eventually(Supplier, Predicate, Duration, Duration, String) when no object is going to be notified. |
static <T> void |
eventually(<any> supplier,
<any> predicate,
Duration timeout,
Duration period,
java.lang.String errMsg,
java.lang.Object notifyObject)
Asserts that eventually the supplier gives a value accepted by the predicate.
|
static <T> void |
eventuallyOnNotify(java.lang.Object notifyTarget,
<any> supplier,
<any> predicate)
As
#eventuallyOnNotify(Object, Supplier, Predicate, Duration, boolean) with default timeout. |
static <T> void |
eventuallyOnNotify(java.lang.Object notifyTarget,
<any> supplier,
<any> predicate,
Duration timeout)
as
#eventually(Supplier, Predicate) for cases where an object is notified;
more efficient as it waits on the notify target object. |
static <T> void |
eventuallyOnNotify(T object,
<any> predicate)
As
#eventuallyOnNotify(Object, Predicate, Duration) with the default duration of #eventuallyOnNotify(Object, Supplier, Predicate) . |
static <T> void |
eventuallyOnNotify(T object,
<any> predicate,
Duration timeout)
Convenience for
#eventuallyOnNotify(Object, Supplier, Predicate, Duration, boolean)
when the notify target and the value under test are the same. |
static void |
expectedFailure(java.lang.Throwable e)
Tests that an exception is not
Asserts.ShouldHaveFailedPreviouslyAssertionError . |
static void |
expectedFailureContains(java.lang.Throwable e,
java.lang.String phrase1ToContain,
java.lang.String... optionalOtherPhrasesToContain)
Tests
expectedFailure(Throwable) and that the toString
satisfies assertStringContains(String, String, String...) . |
static void |
expectedFailureContainsIgnoreCase(java.lang.Throwable e,
java.lang.String phrase1ToContain,
java.lang.String... optionalOtherPhrasesToContain)
As
expectedFailureContains(Throwable, String, String...) but case insensitive |
static void |
expectedFailureDoesNotContain(java.lang.Throwable e,
java.lang.String phrase1ToNotContain,
java.lang.String... optionalOtherPhrasesToNotContain)
Tests
expectedFailure(Throwable) and that the toString
satisfies assertStringContains(String, String, String...) . |
static void |
expectedFailureOfType(java.lang.String message,
java.lang.Throwable e,
java.lang.Class<?> permittedSupertype,
java.lang.Class<?>... permittedSupertypeExtras) |
static void |
expectedFailureOfType(java.lang.Throwable e,
java.lang.Class<?> permittedSupertype,
java.lang.Class<?>... permittedSupertypes)
Tests that an exception is not
Asserts.ShouldHaveFailedPreviouslyAssertionError
and is either one of the given types, or has a caused-by of one of the given types. |
static java.lang.AssertionError |
fail() |
static java.lang.AssertionError |
fail(java.lang.String message)
Fails a test with the given message.
|
static java.lang.AssertionError |
fail(java.lang.Throwable error) |
static java.lang.RuntimeException |
shouldHaveFailedPreviously()
Throws a
Asserts.ShouldHaveFailedPreviouslyAssertionError exception,
to more easily distinguish this failure from other fails. |
static void |
shouldHaveFailedPreviously(java.lang.String message)
As
shouldHaveFailedPreviously() but allowing detail,
for example a value which was received when it shouldn't have been. |
static <T> T |
succeedsContinually(java.util.concurrent.Callable<T> c) |
static <T> T |
succeedsContinually(java.util.Map<?,?> flags,
java.util.concurrent.Callable<T> job) |
static <T> void |
succeedsContinually(java.util.Map<?,?> flags,
java.lang.Runnable r) |
static <T> void |
succeedsContinually(java.lang.Runnable r) |
static <T> T |
succeedsEventually(java.util.concurrent.Callable<T> c) |
static <T> T |
succeedsEventually(java.util.Map<java.lang.String,?> flags,
java.util.concurrent.Callable<T> c)
Convenience method for cases where we need to test until something is true.
|
static void |
succeedsEventually(java.util.Map<java.lang.String,?> flags,
java.lang.Runnable r) |
static void |
succeedsEventually(java.lang.Runnable r) |
public static final long THIRTY_SECONDS_TIMEOUT_MS
public static final Duration DEFAULT_LONG_TIMEOUT
-Dbrooklyn.test.defaultTimeout=1s
.public static final Duration DEFAULT_SHORT_TIMEOUT
Long enough for parallel execution to (normally!) catch up, even on overloaded mediocre
test boxes most of the time, but short enough not to irritate too much when waiting
this long.
Never use this for asserting that a condition is satisfied within a given length of time.
Instead use DEFAULT_LONG_TIMEOUT
to avoid the false-negatives that have
historically littered our jenkins builds.
Use this constant for asserting that something does *not* happen. If it was going to happen,
then it's reasonable to expect it would normally have happened within this time. For
example, if we are asserting that no more events are received after unsubscribing, then
this would be an appropriate timeout to use (perhaps by using
succeedsContinually(Runnable)
, which defaults to this timeout).
public static void assertNull(java.lang.Object object)
object
- The object reference.java.lang.AssertionError
- if the assertion fails.public static void assertNotNull(java.lang.Object object)
object
- The object reference.java.lang.AssertionError
- if the assertion fails.public static void assertNull(java.lang.Object object, java.lang.String message)
object
- The object reference.message
- The assertion error message.java.lang.AssertionError
- if the assertion fails.public static void assertNotNull(java.lang.Object object, java.lang.String message)
object
- The object reference.message
- The assertion error message.java.lang.AssertionError
- if the assertion fails.public static void assertEquals(java.util.Collection<?> actual, java.util.Collection<?> expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(java.util.Collection<?> actual, java.util.Collection<?> expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(java.util.Iterator<?> actual, java.util.Iterator<?> expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(java.util.Iterator<?> actual, java.util.Iterator<?> expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(java.lang.Iterable<?> actual, java.lang.Iterable<?> expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(java.lang.Iterable<?> actual, java.lang.Iterable<?> expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(java.util.Set<?> actual, java.util.Set<?> expected)
public static void assertEquals(java.util.Set<?> actual, java.util.Set<?> expected, java.lang.String message)
public static void assertEquals(java.util.Map<?,?> actual, java.util.Map<?,?> expected)
public static void assertEquals(java.lang.Object[] actual, java.lang.Object[] expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(java.lang.Object[] actual, java.lang.Object[] expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(java.lang.Object actual, java.lang.Object expected)
actual
- the actual valueexpected
- the expected valuejava.lang.AssertionError
- if the values are not equal.public static void assertEquals(java.lang.Object actual, java.lang.Object expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagejava.lang.AssertionError
- if the values are not equal.public static void assertEquals(java.lang.String actual, java.lang.String expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(java.lang.String actual, java.lang.String expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(double actual, double expected, double delta, java.lang.String message)
actual
- the actual valueexpected
- the expected valuedelta
- the absolute tolerable difference between the actual and expected valuesmessage
- the assertion error messagepublic static void assertEquals(double actual, double expected, double delta)
actual
- the actual valueexpected
- the expected valuedelta
- the absolute tolerable difference between the actual and expected valuespublic static void assertEquals(float actual, float expected, float delta, java.lang.String message)
actual
- the actual valueexpected
- the expected valuedelta
- the absolute tolerable difference between the actual and expected valuesmessage
- the assertion error messagepublic static void assertEquals(float actual, float expected, float delta)
actual
- the actual valueexpected
- the expected valuedelta
- the absolute tolerable difference between the actual and expected valuespublic static void assertEquals(long actual, long expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(long actual, long expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(boolean actual, boolean expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(boolean actual, boolean expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(byte actual, byte expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(byte actual, byte expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(char actual, char expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(char actual, char expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(short actual, short expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(short actual, short expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertEquals(int actual, int expected, java.lang.String message)
actual
- the actual valueexpected
- the expected valuemessage
- the assertion error messagepublic static void assertEquals(int actual, int expected)
actual
- the actual valueexpected
- the expected valuepublic static void assertTrue(boolean condition)
condition
- the condition to evaluatepublic static void assertTrue(boolean condition, java.lang.String message)
condition
- the condition to evaluatemessage
- the assertion error messagepublic static void assertFalse(boolean condition, java.lang.String message)
condition
- the condition to evaluatemessage
- the assertion error messagepublic static void assertFalse(boolean condition)
public static java.lang.AssertionError fail(java.lang.String message)
message
- the assertion error messagepublic static java.lang.AssertionError fail(java.lang.Throwable error)
public static java.lang.AssertionError fail()
public static void assertEqualsIgnoringOrder(java.lang.Iterable<?> actual, java.lang.Iterable<?> expected)
public static void assertEqualsIgnoringOrder(java.lang.Iterable<?> actual, java.lang.Iterable<?> expected, boolean logDuplicates, java.lang.String errmsg)
public static <T> void eventually(<any> supplier, <any> predicate)
#eventually(Supplier, Predicate, Duration, Duration, String)
with defaults.public static <T> void eventually(<any> supplier, <any> predicate, Duration timeout)
#eventually(Supplier, Predicate, Duration, Duration, String)
with default.public static <T> void eventually(<any> supplier, <any> predicate, Duration timeout, Duration period, java.lang.String errMsg)
#eventually(Supplier, Predicate, Duration, Duration, String)
when no object is going to be notified.public static <T> void eventually(<any> supplier, <any> predicate, Duration timeout, Duration period, java.lang.String errMsg, java.lang.Object notifyObject)
supplier
- supplies the value to test, such as Suppliers#ofInstance(Object)
for a constantpredicate
- the Predicate
to apply to each value given by the suppliertimeout
- how long to wait, default DEFAULT_LONG_TIMEOUT
period
- how often to check, default quite often so you won't notice but letting the CPU do workerrMsg
- optional error message to display if not satisfied, in addition to the last-tested supplied value and the predicatenotifyObject
- optional object that will be notified of change and should pre-empt the period to redo the checkpublic static <T> void continually(<any> supplier, <any> predicate)
#continually(Supplier, Predicate, Duration, Duration, String)
with defaults.public static <T> void continually(<any> supplier, <any> predicate, Duration duration, Duration period, java.lang.String errMsg)
supplier
- supplies the value to test, such as Suppliers#ofInstance(Object)
for a constantpredicate
- the Predicate
to apply to each value given by the supplierduration
- how long to test for, default DEFAULT_SHORT_TIMEOUT
period
- how often to check, default quite often to minimise chance of missing a flashing violation but letting the CPU do workerrMsg
- an error message to display if not satisfied, in addition to the last-tested supplied value and the predicatepublic static void succeedsEventually(java.lang.Runnable r)
succeedsEventually(Map, Callable)
public static void succeedsEventually(java.util.Map<java.lang.String,?> flags, java.lang.Runnable r)
succeedsEventually(Map, Callable)
public static <T> T succeedsEventually(java.util.concurrent.Callable<T> c)
succeedsEventually(Map, Callable)
public static <T> T succeedsEventually(java.util.Map<java.lang.String,?> flags, java.util.concurrent.Callable<T> c)
The following flags are supported:
DEFAULT_LONG_TIMEOUT
)
flags,
- accepts the flags listed abovec
- The callable to invokepublic static <T> void succeedsContinually(java.lang.Runnable r)
public static <T> void succeedsContinually(java.util.Map<?,?> flags, java.lang.Runnable r)
public static <T> T succeedsContinually(java.util.concurrent.Callable<T> c)
public static <T> T succeedsContinually(java.util.Map<?,?> flags, java.util.concurrent.Callable<T> job)
public static void assertFails(java.lang.Runnable r)
public static void assertFails(java.util.concurrent.Callable<?> c)
@Deprecated public static void assertFailsWith(java.util.concurrent.Callable<?> c, groovy.lang.Closure<java.lang.Boolean> exceptionChecker)
@SafeVarargs public static void assertFailsWith(java.lang.Runnable c, java.lang.Class<? extends java.lang.Throwable> validException, java.lang.Class<? extends java.lang.Throwable>... otherValidExceptions)
public static void assertFailsWith(java.lang.Runnable r, <any> exceptionChecker)
public static void assertFailsWith(java.util.concurrent.Callable<?> c, <any> exceptionChecker)
public static void assertReturnsEventually(java.lang.Runnable r, Duration timeout) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
public static <T> void assertThat(T object, <any> condition)
public static <T> void assertThat(T object, <any> condition, java.lang.String message)
public static void assertStringContains(java.lang.String input, java.lang.String phrase1ToContain, java.lang.String... optionalOtherPhrasesToContain)
public static void assertStringDoesNotContain(java.lang.String input, java.lang.String phrase1ToNotContain, java.lang.String... optionalOtherPhrasesToNotContain)
public static void assertStringContainsAtLeastOne(java.lang.String input, java.lang.String possiblePhrase1ToContain, java.lang.String... optionalOtherPossiblePhrasesToContain)
public static void assertStringContainsIgnoreCase(java.lang.String input, java.lang.String phrase1ToContain, java.lang.String... optionalOtherPhrasesToContain)
public static void assertStringMatchesRegex(java.lang.String input, java.lang.String regex1ToMatch, java.lang.String... optionalOtherRegexesToMatch)
public static java.lang.RuntimeException shouldHaveFailedPreviously()
Asserts.ShouldHaveFailedPreviouslyAssertionError
exception,
to more easily distinguish this failure from other fails.
In particular, use one of the expectedFailure
methods
in the surrounding catch
block and this error will pass through it.
This method throws, never returning normally, but declares a return type so you can pretend to throw the result, for instance if your calling code otherwise warns about needing to return something.
public static void shouldHaveFailedPreviously(java.lang.String message)
shouldHaveFailedPreviously()
but allowing detail,
for example a value which was received when it shouldn't have been.public static void expectedFailure(java.lang.Throwable e)
Asserts.ShouldHaveFailedPreviouslyAssertionError
.
See shouldHaveFailedPreviously()
public static void expectedFailureOfType(java.lang.Throwable e, java.lang.Class<?> permittedSupertype, java.lang.Class<?>... permittedSupertypes)
Asserts.ShouldHaveFailedPreviouslyAssertionError
and is either one of the given types, or has a caused-by of one of the given types.
If you want *just* the instanceof (without checking the caused-by), then just catch
those exception types, treat that as success, and let any other exception be propagated.public static void expectedFailureOfType(java.lang.String message, java.lang.Throwable e, java.lang.Class<?> permittedSupertype, java.lang.Class<?>... permittedSupertypeExtras)
public static void expectedFailureContains(java.lang.Throwable e, java.lang.String phrase1ToContain, java.lang.String... optionalOtherPhrasesToContain)
expectedFailure(Throwable)
and that the toString
satisfies assertStringContains(String, String, String...)
.public static void expectedFailureContainsIgnoreCase(java.lang.Throwable e, java.lang.String phrase1ToContain, java.lang.String... optionalOtherPhrasesToContain)
expectedFailureContains(Throwable, String, String...)
but case insensitivepublic static void expectedFailureDoesNotContain(java.lang.Throwable e, java.lang.String phrase1ToNotContain, java.lang.String... optionalOtherPhrasesToNotContain)
expectedFailure(Throwable)
and that the toString
satisfies assertStringContains(String, String, String...)
.public static <T> void eventuallyOnNotify(java.lang.Object notifyTarget, <any> supplier, <any> predicate)
#eventuallyOnNotify(Object, Supplier, Predicate, Duration, boolean)
with default timeout.public static <T> void eventuallyOnNotify(java.lang.Object notifyTarget, <any> supplier, <any> predicate, Duration timeout)
#eventually(Supplier, Predicate)
for cases where an object is notified;
more efficient as it waits on the notify target object.
See also the simpler #eventuallyOnNotify(Object, Predicate)
when looking at a collection which is getting notified.
Timeout defaults to DEFAULT_SHORT_TIMEOUT
.
This synchronizes on the notify target for the duration of the wait, including while getting and checking the value, so as not to miss any notification.
public static <T> void eventuallyOnNotify(T object, <any> predicate, Duration timeout)
#eventuallyOnNotify(Object, Supplier, Predicate, Duration, boolean)
when the notify target and the value under test are the same.public static <T> void eventuallyOnNotify(T object, <any> predicate)
#eventuallyOnNotify(Object, Predicate, Duration)
with the default duration of #eventuallyOnNotify(Object, Supplier, Predicate)
.public static void assertSize(java.lang.Iterable<?> list, int expectedSize)
public static void assertSize(java.util.Map<?,?> map, int expectedSize)
public static void assertSameUnorderedContents(java.lang.Iterable<?> i1, java.lang.Iterable<?> i2)
public static void assertInstanceOf(java.lang.Object obj, java.lang.Class<?> type)
public static <T> void assertPresent(Maybe<T> candidate)
public static <T> void assertNotPresent(Maybe<T> candidate)