S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.A - the type of the "actual" value.public abstract class AbstractThrowableAssert<S extends AbstractThrowableAssert<S,A>,A extends java.lang.Throwable> extends AbstractAssert<S,A>
Throwables.| Modifier and Type | Field and Description |
|---|---|
(package private) Throwables |
throwables |
actual, conditions, info, myself, objects| Modifier | Constructor and Description |
|---|---|
protected |
AbstractThrowableAssert(A actual,
java.lang.Class<?> selfType) |
| Modifier and Type | Method and Description |
|---|---|
protected S |
hasBeenThrown() |
S |
hasCause(java.lang.Throwable cause)
Verifies that the actual
Throwable has a cause similar to the given one, that is with same type and message
(it does not use equals method for comparison). |
S |
hasCauseExactlyInstanceOf(java.lang.Class<? extends java.lang.Throwable> type)
Verifies that the cause of the actual
Throwable is exactly an instance of the given type. |
S |
hasCauseInstanceOf(java.lang.Class<? extends java.lang.Throwable> type)
Verifies that the cause of the actual
Throwable is an instance of the given type. |
S |
hasMessage(java.lang.String message)
Verifies that the message of the actual
Throwable is equal to the given one. |
S |
hasMessageContaining(java.lang.String description)
Verifies that the message of the actual
Throwable contains with the given description. |
S |
hasMessageEndingWith(java.lang.String description)
Verifies that the message of the actual
Throwable ends with the given description. |
S |
hasMessageMatching(java.lang.String regex)
Verifies that the message of the actual
Throwable matches with the given regular expression. |
S |
hasMessageStartingWith(java.lang.String description)
Verifies that the message of the actual
Throwable starts with the given description. |
S |
hasNoCause()
Verifies that the actual
Throwable does not have a cause. |
S |
hasRootCauseExactlyInstanceOf(java.lang.Class<? extends java.lang.Throwable> type)
Verifies that the root cause of the actual
Throwable is exactly an instance of the given type. |
S |
hasRootCauseInstanceOf(java.lang.Class<? extends java.lang.Throwable> type)
Verifies that the root cause of the actual
Throwable is an instance of the given type. |
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator, withFailMessage, withThreadDumpOnErrorThrowables throwables
protected AbstractThrowableAssert(A actual, java.lang.Class<?> selfType)
protected S hasBeenThrown()
public S hasMessage(java.lang.String message)
Throwable is equal to the given one.message - the expected message.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the message of the actual Throwable is not equal to the given one.public S hasCause(java.lang.Throwable cause)
Throwable has a cause similar to the given one, that is with same type and message
(it does not use equals method for comparison).
Example:
Throwable invalidArgException = new IllegalArgumentException("invalid arg");
Throwable throwable = new Throwable(invalidArgException);
// This assertion succeeds:
assertThat(throwable).hasCause(invalidArgException);
// These assertions fail:
assertThat(throwable).hasCause(new IllegalArgumentException("bad arg"));
assertThat(throwable).hasCause(new NullPointerException());
assertThat(throwable).hasCause(null); // prefer hasNoCause()java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the actual Throwable has not the given cause.public S hasNoCause()
Throwable does not have a cause.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the actual Throwable has a cause.public S hasMessageStartingWith(java.lang.String description)
Throwable starts with the given description.description - the description expected to start the actual Throwable's message.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the message of the actual Throwable does not start with the given description.public S hasMessageContaining(java.lang.String description)
Throwable contains with the given description.description - the description expected to be contained in the actual Throwable's message.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the message of the actual Throwable does not contain the given description.public S hasMessageMatching(java.lang.String regex)
Throwable matches with the given regular expression.
Examples:
Throwable throwable = new IllegalArgumentException("wrong amount 123");
// assertion will pass
assertThat(throwable).hasMessageMatching("wrong amount [0-9]*");
// assertion will fail
assertThat(throwable).hasMessageMatching("wrong amount [0-9]* euros");regex - the regular expression of value expected to be matched the actual Throwable's message.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the message of the actual Throwable does not match the given regular expression.java.lang.NullPointerException - if the regex is nullpublic S hasMessageEndingWith(java.lang.String description)
Throwable ends with the given description.description - the description expected to end the actual Throwable's message.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the message of the actual Throwable does not end with the given description.public S hasCauseInstanceOf(java.lang.Class<? extends java.lang.Throwable> type)
Throwable is an instance of the given type.
Example:
Throwable throwable = new Throwable(new NullPointerException());
// assertion will pass
assertThat(throwable).hasCauseInstanceOf(NullPointerException.class);
assertThat(throwable).hasCauseInstanceOf(RuntimeException.class);
// assertion will fail
assertThat(throwable).hasCauseInstanceOf(IllegalArgumentException.class);type - the expected cause type.java.lang.NullPointerException - if given type is null.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the actual Throwable has no cause.java.lang.AssertionError - if the cause of the actual Throwable is not an instance of the given type.public S hasCauseExactlyInstanceOf(java.lang.Class<? extends java.lang.Throwable> type)
Throwable is exactly an instance of the given type.
Example:
Throwable throwable = new Throwable(new NullPointerException());
// assertion will pass
assertThat(throwable).hasCauseExactlyInstanceOf(NullPointerException.class);
// assertions will fail (even if NullPointerException is a RuntimeException since we want an exact match)
assertThat(throwable).hasCauseExactlyInstanceOf(RuntimeException.class);
assertThat(throwable).hasCauseExactlyInstanceOf(IllegalArgumentException.class);
type - the expected cause type.java.lang.NullPointerException - if given type is null.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the actual Throwable has no cause.java.lang.AssertionError - if the cause of the actual Throwable is not exactly an instance of the given
type.public S hasRootCauseInstanceOf(java.lang.Class<? extends java.lang.Throwable> type)
Throwable is an instance of the given type.
Example:
Throwable throwable = new Throwable(new IllegalStateException(new NullPointerException()));
// assertion will pass
assertThat(throwable).hasRootCauseInstanceOf(NullPointerException.class);
assertThat(throwable).hasRootCauseInstanceOf(RuntimeException.class);
// assertion will fail
assertThat(throwable).hasRootCauseInstanceOf(IllegalStateException.class);
type - the expected cause type.java.lang.NullPointerException - if given type is null.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the actual Throwable has no cause.java.lang.AssertionError - if the cause of the actual Throwable is not an instance of the given type.public S hasRootCauseExactlyInstanceOf(java.lang.Class<? extends java.lang.Throwable> type)
Throwable is exactly an instance of the given type.
Example:
Throwable throwable = new Throwable(new IllegalStateException(new NullPointerException()));
// assertion will pass
assertThat(throwable).hasRootCauseExactlyInstanceOf(NullPointerException.class);
// assertion will fail (even if NullPointerException is a RuntimeException since we want an exact match)
assertThat(throwable).hasRootCauseExactlyInstanceOf(RuntimeException.class);
assertThat(throwable).hasRootCauseExactlyInstanceOf(IllegalStateException.class);
type - the expected cause type.java.lang.NullPointerException - if given type is null.java.lang.AssertionError - if the actual Throwable is null.java.lang.AssertionError - if the actual Throwable has no cause.java.lang.AssertionError - if the root cause of the actual Throwable is not exactly an instance of the
given type.