SELF - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.ACTUAL - the type of the "actual" value.public abstract class AbstractThrowableAssert<SELF extends AbstractThrowableAssert<SELF,ACTUAL>,ACTUAL extends Throwable> extends AbstractObjectAssert<SELF,ACTUAL>
Throwables.actual, info, myself, throwUnsupportedExceptionOnEquals| Constructor and Description |
|---|
AbstractThrowableAssert(ACTUAL actual,
Class<?> selfType) |
| Modifier and Type | Method and Description |
|---|---|
void |
doesNotThrowAnyException()
Verifies that the
ThrowableAssert.ThrowingCallable didn't raise a throwable. |
protected SELF |
hasBeenThrown() |
SELF |
hasCause(Throwable cause)
Verifies that the actual
Throwable has a cause similar to the given one, that is with the same type and message
(it does not use the equals method for comparison). |
SELF |
hasCauseExactlyInstanceOf(Class<? extends Throwable> type)
Verifies that the cause of the actual
Throwable is exactly an instance of the given type. |
SELF |
hasCauseInstanceOf(Class<? extends Throwable> type)
Verifies that the cause of the actual
Throwable is an instance of the given type. |
SELF |
hasMessage(String message)
Verifies that the message of the actual
Throwable is equal to the given one. |
SELF |
hasMessage(String message,
Object... parameters)
Verifies that the message of the actual (@code Throwable) is equal to the given one, after being formatted using
the
String.format(java.lang.String, java.lang.Object...) method. |
SELF |
hasMessageContaining(String description)
Verifies that the message of the actual
Throwable contains the given description. |
SELF |
hasMessageEndingWith(String description)
Verifies that the message of the actual
Throwable ends with the given description. |
SELF |
hasMessageMatching(String regex)
Verifies that the message of the actual
Throwable matches the given regular expression. |
SELF |
hasMessageStartingWith(String description)
Verifies that the message of the actual
Throwable starts with the given description. |
SELF |
hasNoCause()
Verifies that the actual
Throwable does not have a cause. |
SELF |
hasNoSuppressedExceptions()
Verifies that the actual
Throwable has no suppressed exceptions. |
SELF |
hasRootCauseExactlyInstanceOf(Class<? extends Throwable> type)
Verifies that the root cause of the actual
Throwable is exactly an instance of the given type. |
SELF |
hasRootCauseInstanceOf(Class<? extends Throwable> type)
Verifies that the root cause of the actual
Throwable is an instance of the given type. |
SELF |
hasStackTraceContaining(String description)
Verifies that the stack trace of the actual
Throwable contains the given description. |
SELF |
hasSuppressedException(Throwable suppressedException)
Verifies that the actual
Throwable has a suppressed exception similar to the given one, that is with the same type and message
(it does not use the equals method for comparison). |
as, as, extracting, extracting, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, returns, usingComparatorForFields, usingComparatorForTypeasList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnErrorprotected SELF hasBeenThrown()
public SELF hasMessage(String message)
Throwable is equal to the given one.message - the expected message.AssertionError - if the actual Throwable is null.AssertionError - if the message of the actual Throwable is not equal to the given one.public SELF hasMessage(String message, Object... parameters)
String.format(java.lang.String, java.lang.Object...) method.
Example:
Throwable invalidArgException = new IllegalArgumentException("foo is not a valid input");
Throwable throwable = new Throwable(invalidArgException);
// This assertion succeeds:
assertThat(throwable).hasMessage("%s is not a valid input", "foo");
// These assertions fail:
assertThat(throwable).hasMessage("%s is not a valid input", "bar");
assertThat(throwable).hasMessage("%s is not a valid input", 12);
assertThat(null).hasMessage("%s is not a valid input", "foo");message - a format string representing the expected messageparameters - argument referenced by the format specifiers in the format stringAssertionError - if the actual Throwable is null.AssertionError - if the message of the actual Throwable is not equal to the given one.IllegalFormatException - if the message contains an illegal syntax according to String.format(String, Object...).public SELF hasCause(Throwable cause)
Throwable has a cause similar to the given one, that is with the same type and message
(it does not use the 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()cause - the expected causeAssertionError - if the actual Throwable is null.AssertionError - if the actual Throwable has not the given cause.public SELF hasNoCause()
Throwable does not have a cause.AssertionError - if the actual Throwable is null.AssertionError - if the actual Throwable has a cause.public SELF hasMessageStartingWith(String description)
Throwable starts with the given description.description - the description expected to start the actual Throwable's message.AssertionError - if the actual Throwable is null.AssertionError - if the message of the actual Throwable does not start with the given description.public SELF hasMessageContaining(String description)
Throwable contains the given description.description - the description expected to be contained in the actual Throwable's message.AssertionError - if the actual Throwable is null.AssertionError - if the message of the actual Throwable does not contain the given description.public SELF hasStackTraceContaining(String description)
Throwable contains the given description.description - the description expected to be contained in the actual Throwable's stack trace.AssertionError - if the actual Throwable is null.AssertionError - if the stack trace of the actual Throwable does not contain the given description.public SELF hasMessageMatching(String regex)
Throwable matches 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.AssertionError - if the actual Throwable is null.AssertionError - if the message of the actual Throwable does not match the given regular expression.NullPointerException - if the regex is nullpublic SELF hasMessageEndingWith(String description)
Throwable ends with the given description.description - the description expected to end the actual Throwable's message.AssertionError - if the actual Throwable is null.AssertionError - if the message of the actual Throwable does not end with the given description.public SELF hasCauseInstanceOf(Class<? extends Throwable> type)
Throwable is an instance of the given type.
Example:
Throwable throwable = new Throwable(new NullPointerException());
// assertions 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.NullPointerException - if given type is null.AssertionError - if the actual Throwable is null.AssertionError - if the actual Throwable has no cause.AssertionError - if the cause of the actual Throwable is not an instance of the given type.public SELF hasCauseExactlyInstanceOf(Class<? extends 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.NullPointerException - if given type is null.AssertionError - if the actual Throwable is null.AssertionError - if the actual Throwable has no cause.AssertionError - if the cause of the actual Throwable is not exactly an instance of the given
type.public SELF hasRootCauseInstanceOf(Class<? extends Throwable> type)
Throwable is an instance of the given type.
Example:
Throwable throwable = new Throwable(new IllegalStateException(new NullPointerException()));
// assertions 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.NullPointerException - if given type is null.AssertionError - if the actual Throwable is null.AssertionError - if the actual Throwable has no cause.AssertionError - if the cause of the actual Throwable is not an instance of the given type.public SELF hasRootCauseExactlyInstanceOf(Class<? extends 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);
// assertions 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.NullPointerException - if given type is null.AssertionError - if the actual Throwable is null.AssertionError - if the actual Throwable has no cause.AssertionError - if the root cause of the actual Throwable is not exactly an instance of the
given type.public SELF hasNoSuppressedExceptions()
Throwable has no suppressed exceptions.
Example:
// assertion will pass
assertThat(new Throwable()).hasNoSuppressedExceptions();
// assertion will fail
Throwable throwableWithSuppressedException = new Throwable();
throwableWithSuppressedException.addSuppressed(new IllegalArgumentException());
assertThat(throwableWithSuppressedException).hasNoSuppressedExceptions();NullPointerException - if given type is null.AssertionError - if the actual Throwable has any suppressed exceptions.public SELF hasSuppressedException(Throwable suppressedException)
Throwable has a suppressed exception similar to the given one, that is with the same type and message
(it does not use the equals method for comparison).
Example:
Throwable throwable = new Throwable();
Throwable invalidArgException = new IllegalArgumentException("invalid argument");
throwable.addSuppressed(invalidArgException);
// These assertions succeed:
assertThat(throwable).hasSuppressedException(invalidArgException);
assertThat(throwable).hasSuppressedException(new IllegalArgumentException("invalid argument"));
// These assertions fail:
assertThat(throwable).hasSuppressedException(new IllegalArgumentException("invalid parameter"));
assertThat(throwable).hasSuppressedException(new NullPointerException());suppressedException - the expected suppressed exceptionAssertionError - if the actual Throwable is null.AssertionError - if the actual Throwable does not have the given suppressed exception.public void doesNotThrowAnyException()
ThrowableAssert.ThrowingCallable didn't raise a throwable.
Example :
assertThatCode(() -> foo.bar()).doesNotThrowAnyException();AssertionError - if the actual statement raised a Throwable.Copyright © 2014–2018 AssertJ. All rights reserved.