Class ThrowableAssertAlternative<ACTUAL extends Throwable>
- All Implemented Interfaces:
Assert<ThrowableAssertAlternative<ACTUAL>,
,ACTUAL> Descriptable<ThrowableAssertAlternative<ACTUAL>>
,ExtensionPoints<ThrowableAssertAlternative<ACTUAL>,
ACTUAL>
- Direct Known Subclasses:
SoftThrowableAssertAlternative
Throwable
similar to ThrowableAssert
but with assertions methods named
differently to make testing code fluent (ex : withMessage
instead of hasMessage
.
assertThatExceptionOfType(IOException.class)
.isThrownBy(() -> { throw new IOException("boom! tcha!"); });
.withMessage("boom! %s", "tcha!");
This class is linked with the ThrowableTypeAssert
and allow to check that an exception
type is thrown by a lambda.-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionas
(Description description) Sets the description of the assertion that is going to be called after.describedAs
(String description, Object... args) Sets the description of the assertion that is going to be called after.describedAs
(Description description) Sets the description of the assertion that is going to be called after.protected ThrowableAssert
<ACTUAL> Verifies that the actualThrowable
has a cause similar to the given one, that is with same type and message (it does not useequals
method for comparison).withCauseExactlyInstanceOf
(Class<? extends Throwable> type) Verifies that the cause of the actualThrowable
is exactly an instance of the given type.withCauseInstanceOf
(Class<? extends Throwable> type) Verifies that the cause of the actualThrowable
is an instance of the given type.withMessage
(String message) Verifies that the message of the actualThrowable
is equal to the given one.withMessage
(String message, Object... parameters) Verifies that the message of the actualThrowable
is equal to the given one built usingString.format(String, Object...)
syntax.withMessageContaining
(String description) Verifies that the message of the actualThrowable
contains the given description.withMessageContaining
(String description, Object... parameters) Verifies that the message of the actualThrowable
contains the given description, after being formatted using theString.format(java.lang.String, java.lang.Object...)
method.withMessageContainingAll
(CharSequence... values) Verifies that the message of the actualThrowable
contains all the given values.withMessageEndingWith
(String description) Verifies that the message of the actualThrowable
ends with the given description.withMessageEndingWith
(String description, Object... parameters) Verifies that the message of the actualThrowable
ends with the given description, after being formatted using theString.format(java.lang.String, java.lang.Object...)
method.withMessageMatching
(String regex) Verifies that the message of the actualThrowable
matches with the given regular expression.withMessageNotContaining
(String content) Verifies that the message of the actualThrowable
does not contain the given content or is null.withMessageNotContainingAny
(CharSequence... values) Verifies that the message of the actualThrowable
does not contain any of the given values or isnull
.withMessageStartingWith
(String description) Verifies that the message of the actualThrowable
starts with the given description.withMessageStartingWith
(String description, Object... parameters) Verifies that the message of the actualThrowable
starts with the given description, after being formatted using theString.format(java.lang.String, java.lang.Object...)
method.Verifies that the actualThrowable
does not have a cause.withRootCauseExactlyInstanceOf
(Class<? extends Throwable> type) Verifies that the root cause of the actualThrowable
is exactly an instance of the given type.withRootCauseInstanceOf
(Class<? extends Throwable> type) Verifies that the root cause of the actualThrowable
is an instance of the given type.withStackTraceContaining
(String description) Verifies that the stack trace of the actualThrowable
contains with the given description.withStackTraceContaining
(String description, Object... parameters) Verifies that the stack trace of the actualThrowable
contains with the given description, after being formatted using theString.format(java.lang.String, java.lang.Object...)
method.Methods inherited from class org.assertj.core.api.AbstractObjectAssert
as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison
Methods inherited from class org.assertj.core.api.AbstractAssert
areEqual, asInstanceOf, asList, assertionError, asString, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, describedAs
-
Constructor Details
-
ThrowableAssertAlternative
-
-
Method Details
-
getDelegate
-
as
Description copied from interface:Descriptable
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
String
by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
as
in interfaceDescriptable<ACTUAL extends Throwable>
- Overrides:
as
in classAbstractObjectAssert<ThrowableAssertAlternative<ACTUAL extends Throwable>,
ACTUAL extends Throwable> - Parameters:
description
- the new description to set.- Returns:
this
object.- See Also:
-
withMessage
Verifies that the message of the actualThrowable
is equal to the given one.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessage("wrong amount 123"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessage("wrong amount 123 euros");
- Parameters:
message
- the expected message.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
is not equal to the given one.- See Also:
-
withMessage
Verifies that the message of the actualThrowable
is equal to the given one built usingString.format(String, Object...)
syntax.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessage("wrong amount %s, "123"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessage("wrong amount 123 euros");
- Parameters:
message
- a format string representing the expected messageparameters
- argument referenced by the format specifiers in the format string- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
is not equal to the given one.- See Also:
-
withCause
Verifies that the actualThrowable
has a cause similar to the given one, that is with same type and message (it does not useequals
method for comparison).Example:
Throwable illegalArgumentException = new IllegalArgumentException("invalid arg"); Throwable wrappingException = new Throwable(illegalArgumentException); // This assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw wrappingException;}) .withCause(illegalArgumentException); // These assertions fail: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw wrappingException;}) .withCause(new IllegalArgumentException("bad arg")); assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw wrappingException;}) .withCause(new NullPointerException()); assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw wrappingException;}) .withCause(null);
- Parameters:
cause
- the expected cause.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has not the given cause.- See Also:
-
withNoCause
Verifies that the actualThrowable
does not have a cause.Example:
IllegalArgumentException exception = new IllegalArgumentException(); // This assertion succeeds: assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> {throw exception;}) .withNoCause(); // These assertion fails: Throwable illegalArgumentException = new Throwable(exception); assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withNoCause();
- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has a cause.- See Also:
-
withMessageStartingWith
Verifies that the message of the actualThrowable
starts with the given description.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageStartingWith("wrong amount"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageStartingWith("right amount");
- Parameters:
description
- the description expected to start the actualThrowable
's message.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
does not start with the given description.- See Also:
-
withMessageStartingWith
public ThrowableAssertAlternative<ACTUAL> withMessageStartingWith(String description, Object... parameters) Verifies that the message of the actualThrowable
starts with the given description, after being formatted using theString.format(java.lang.String, java.lang.Object...)
method.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageStartingWith("%s amount", "wrong"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageStartingWith("%s amount", "right");
- Parameters:
description
- the description expected to start the actualThrowable
's message.parameters
- argument referenced by the format specifiers in the format string- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
does not start with the given description.IllegalFormatException
- if the message contains an illegal syntax according toString.format(String, Object...)
.- See Also:
-
withMessageContaining
Verifies that the message of the actualThrowable
contains the given description.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageContaining("amount"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageContaining("456");
- Parameters:
description
- the description expected to be contained in the actualThrowable
's message.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
does not contain the given description.- See Also:
-
withMessageContaining
public ThrowableAssertAlternative<ACTUAL> withMessageContaining(String description, Object... parameters) Verifies that the message of the actualThrowable
contains the given description, after being formatted using theString.format(java.lang.String, java.lang.Object...)
method.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageContaining("%s", amount); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageContaining("%d", 456);
- Parameters:
description
- the description expected to be contained in the actualThrowable
's message.parameters
- argument referenced by the format specifiers in the format string- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
does not contain the given description.IllegalFormatException
- if the message contains an illegal syntax according toString.format(String, Object...)
.- See Also:
-
withMessageContainingAll
Verifies that the message of the actualThrowable
contains all the given values.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageContainingAll("amount", "123"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageContainingAll("456");
- Parameters:
values
- the Strings expected to be contained in the actualThrowable
's message.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
does not contain all the given values.- See Also:
-
withMessageNotContaining
Verifies that the message of the actualThrowable
does not contain the given content or is null.Examples:
//assertions will pass assertThatExceptionOfType(Exception.class) .isThrownBy(codeThrowing(new Exception("boom"))) .withMessageNotContaining("bam"); assertThatExceptionOfType(Exception.class) .isThrownBy(codeThrowing(new Exception())) .withMessageNotContaining("bam"); //assertion fails: assertThatExceptionOfType(Exception.class) .isThrownBy(codeThrowing(new Exception("boom"))) .withMessageNotContaining("boom");
- Parameters:
content
- the content expected to not be contained in the actualThrowable
's message.- Returns:
- this assertion object
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
contains the given content.- See Also:
-
withMessageNotContainingAny
Verifies that the message of the actualThrowable
does not contain any of the given values or isnull
.Examples:
//assertions will pass assertThatExceptionOfType(Exception.class) .isThrownBy(codeThrowing(new Exception("boom"))) .withMessageNotContainingAny("bam"); assertThatExceptionOfType(Exception.class) .isThrownBy(codeThrowing(new Exception())) .withMessageNotContainingAny("bam"); // assertion fails: assertThatExceptionOfType(Exception.class) .isThrownBy(codeThrowing(new Exception("boom"))) .withMessageNotContainingAny("bam", "boom");
- Parameters:
values
- the contents expected to not be contained in the actualThrowable
's message.- Returns:
- this assertion object
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
contains any of the given values.- See Also:
-
withStackTraceContaining
Verifies that the stack trace of the actualThrowable
contains with the given description.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withStackTraceContaining("amount"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withStackTraceContaining("456");
- Parameters:
description
- the description expected to be contained in the actualThrowable
's stack trace.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the stack trace of the actualThrowable
does not contain the given description.- See Also:
-
withStackTraceContaining
public ThrowableAssertAlternative<ACTUAL> withStackTraceContaining(String description, Object... parameters) Verifies that the stack trace of the actualThrowable
contains with the given description, after being formatted using theString.format(java.lang.String, java.lang.Object...)
method.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withStackTraceContaining("%s", amount); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withStackTraceContaining("%d", 456);
- Parameters:
description
- the description expected to be contained in the actualThrowable
's stack trace.parameters
- argument referenced by the format specifiers in the format string- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the stack trace of the actualThrowable
does not contain the given description.IllegalFormatException
- if the message contains an illegal syntax according toString.format(String, Object...)
.- See Also:
-
withMessageMatching
Verifies that the message of the actualThrowable
matches with the given regular expression.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageMatching("wrong amount [0-9]*"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageMatching("wrong amount [0-9]* euros");
- Parameters:
regex
- the regular expression of value expected to be matched the actualThrowable
's message.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
does not match the given regular expression.NullPointerException
- if the regex is null- See Also:
-
withMessageEndingWith
Verifies that the message of the actualThrowable
ends with the given description.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageEndingWith("123"); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageEndingWith("456");
- Parameters:
description
- the description expected to end the actualThrowable
's message.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
does not end with the given description.- See Also:
-
withMessageEndingWith
public ThrowableAssertAlternative<ACTUAL> withMessageEndingWith(String description, Object... parameters) Verifies that the message of the actualThrowable
ends with the given description, after being formatted using theString.format(java.lang.String, java.lang.Object...)
method.Examples:
Throwable illegalArgumentException = new IllegalArgumentException("wrong amount 123"); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageEndingWith("%d", 123); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw illegalArgumentException;}) .withMessageEndingWith("%d", 456);
- Parameters:
description
- the description expected to end the actualThrowable
's message.parameters
- argument referenced by the format specifiers in the format string- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
does not end with the given description.IllegalFormatException
- if the message contains an illegal syntax according toString.format(String, Object...)
.- See Also:
-
withCauseInstanceOf
Verifies that the cause of the actualThrowable
is an instance of the given type.Example:
Throwable throwable = new Throwable(new NullPointerException()); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withCauseInstanceOf(NullPointerException.class); assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withCauseInstanceOf(RuntimeException.class); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withCauseInstanceOf(IllegalArgumentException.class);
- Parameters:
type
- the expected cause type.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if given type isnull
.AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has no cause.AssertionError
- if the cause of the actualThrowable
is not an instance of the given type.- See Also:
-
withCauseExactlyInstanceOf
public ThrowableAssertAlternative<ACTUAL> withCauseExactlyInstanceOf(Class<? extends Throwable> type) Verifies that the cause of the actualThrowable
is exactly an instance of the given type.Example:
Throwable throwable = new Throwable(new NullPointerException()); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withCauseExactlyInstanceOf(NullPointerException.class); // assertions will fail (even if NullPointerException is a RuntimeException since we want an exact match) assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withCauseExactlyInstanceOf(RuntimeException.class); assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withCauseExactlyInstanceOf(IllegalArgumentException.class);
- Parameters:
type
- the expected cause type.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if given type isnull
.AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has no cause.AssertionError
- if the cause of the actualThrowable
is not exactly an instance of the given type.- See Also:
-
withRootCauseInstanceOf
Verifies that the root cause of the actualThrowable
is an instance of the given type.Example:
Throwable throwable = new Throwable( new IllegalStateException( new NullPointerException())); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withRootCauseInstanceOf(NullPointerException.class); assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withRootCauseInstanceOf(RuntimeException.class); // assertion fails: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withRootCauseInstanceOf(IllegalStateException.class);
- Parameters:
type
- the expected cause type.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if given type isnull
.AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has no cause.AssertionError
- if the cause of the actualThrowable
is not an instance of the given type.- See Also:
-
withRootCauseExactlyInstanceOf
public ThrowableAssertAlternative<ACTUAL> withRootCauseExactlyInstanceOf(Class<? extends Throwable> type) Verifies that the root cause of the actualThrowable
is exactly an instance of the given type.Example:
Throwable throwable = new Throwable( new IllegalStateException( new NullPointerException())); // assertion succeeds: assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withRootCauseExactlyInstanceOf(NullPointerException.class); // assertion fails (even if NullPointerException is a RuntimeException since we want an exact match) assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withRootCauseExactlyInstanceOf(RuntimeException.class); assertThatExceptionOfType(Throwable.class) .isThrownBy(() -> {throw throwable;}) .withRootCauseExactlyInstanceOf(IllegalStateException.class);
- Parameters:
type
- the expected cause type.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if given type isnull
.AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has no cause.AssertionError
- if the root cause of the actualThrowable
is not exactly an instance of the given type.- See Also:
-
describedAs
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Alias for
since "as" is a keyword in Groovy.Descriptable.as(String, Object...)
- Parameters:
description
- the new description to set.args
- optional parameter if description is a format String.- Returns:
this
object.
-
describedAs
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
String
by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
describedAs
in interfaceDescriptable<ACTUAL extends Throwable>
- Overrides:
describedAs
in classAbstractAssert<ThrowableAssertAlternative<ACTUAL extends Throwable>,
ACTUAL extends Throwable> - Parameters:
description
- the new description to set.- Returns:
this
object.
-
havingCause
Checks if the actualThrowable
has a cause and returns a new assertion object where the cause becomes the actual Throwable in order to further assert properties of the causeThrowable
- Returns:
- a new assertion object with the cause of the current actual becoming the new actual
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has no cause.- Since:
- 3.16.0
-
havingRootCause
Checks if the actualThrowable
has a root cause and returns a new assertion object where the root cause becomes the actual Throwable in order to further assert properties of the causeThrowable
- Returns:
- a new assertion object with the root cause of the current actual becoming the new actual
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has no root cause.- Since:
- 3.16.0
-