Package org.fest.assertions
Class ThrowableAssert
Understands assertion methods for
Throwable
. To create a new instance of this class use the
method Assertions.assertThat(Throwable)
.-
Field Summary
FieldsFields inherited from class org.fest.assertions.GenericAssert
actual
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ThrowableAssert
(Throwable actual) Creates a newThrowableAssert
. -
Method Summary
Modifier and TypeMethodDescriptionSets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
as
(Description description) Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
describedAs
(String description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(String)
describedAs
(Description description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(Description)
doesNotSatisfy
(Condition<Throwable> condition) Verifies that the actualThrowable
does not satisfy the given condition.hasMessage
(String message) Verifies that the message of the actualThrowable
is equal to the given one.Verifies that the actualThrowable
does not have a cause.Alias for
.satisfies(Condition)
Verifies that the actualThrowable
is equal to the given one.isExactlyInstanceOf
(Class<?> type) Verifies that the actualThrowable
is an instance of the given type.isInstanceOf
(Class<? extends Throwable> type) Verifies that the actualThrowable
is an instance of the given type.Alias for
.doesNotSatisfy(Condition)
isNotEqualTo
(Throwable other) Verifies that the actualThrowable
is not equal to the given one.Verifies that the actualThrowable
is notnull
.isNotSameAs
(Throwable other) Verifies that the actualThrowable
is not the same as the given one.Verifies that the actualThrowable
is the same as the given one.overridingErrorMessage
(String message) Replaces the default message displayed in case of a failure with the given one.Verifies that the actualThrowable
satisfies the given condition.Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNull
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
-
Field Details
-
objectAssert
-
-
Constructor Details
-
ThrowableAssert
Creates a newThrowableAssert
.- Parameters:
actual
- the target to verify.
-
-
Method Details
-
as
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionError
For example:
assertThat(val).as("name").isEqualTo("Frodo");
- Specified by:
as
in classGenericAssert<Throwable>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for
, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(String)
For example:
assertThat(val).describedAs("name").isEqualTo("Frodo");
- Specified by:
describedAs
in classGenericAssert<Throwable>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
as
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionError
For example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
- Specified by:
as
in classGenericAssert<Throwable>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for
, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(Description)
For example:
assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");
- Specified by:
describedAs
in classGenericAssert<Throwable>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
isInstanceOf
Verifies that the actualThrowable
is an instance of the given type.- Parameters:
type
- the type to check the actualThrowable
against.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
is not an instance of the given type.NullPointerException
- if the given type isnull
.
-
isExactlyInstanceOf
Verifies that the actualThrowable
is an instance of the given type. In order for the assertion to pass, the type of the actualThrowable
has to be exactly the same as the given type.- Parameters:
type
- the type to check the actualThrowable
against.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
is not an instance of the given type.NullPointerException
- if the given type isnull
.
-
hasMessage
Verifies that the message of the actualThrowable
is equal to the given one.- Parameters:
message
- the expected message.- Returns:
- this assertion error.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the message of the actualThrowable
is not equal to the given one.
-
hasNoCause
Verifies that the actualThrowable
does not have a cause.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.AssertionError
- if the actualThrowable
has a cause.
-
isEqualTo
Verifies that the actualThrowable
is equal to the given one.- Specified by:
isEqualTo
in classGenericAssert<Throwable>
- Parameters:
expected
- the givenThrowable
to compare the actualThrowable
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
is not equal to the given one.
-
isNotEqualTo
Verifies that the actualThrowable
is not equal to the given one.- Specified by:
isNotEqualTo
in classGenericAssert<Throwable>
- Parameters:
other
- the givenThrowable
to compare the actualThrowable
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
is equal to the given one.
-
isNotNull
Verifies that the actualThrowable
is notnull
.- Specified by:
isNotNull
in classGenericAssert<Throwable>
- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
isnull
.
-
isNotSameAs
Verifies that the actualThrowable
is not the same as the given one.- Specified by:
isNotSameAs
in classGenericAssert<Throwable>
- Parameters:
other
- the givenThrowable
to compare the actualThrowable
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
is the same as the given one.
-
isSameAs
Verifies that the actualThrowable
is the same as the given one.- Specified by:
isSameAs
in classGenericAssert<Throwable>
- Parameters:
expected
- the givenThrowable
to compare the actualThrowable
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualThrowable
is not the same as the given one.
-
satisfies
Verifies that the actualThrowable
satisfies the given condition.- Specified by:
satisfies
in classGenericAssert<Throwable>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualThrowable
does not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualThrowable
does not satisfy the given condition.- Specified by:
doesNotSatisfy
in classGenericAssert<Throwable>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualThrowable
satisfies the given condition.- See Also:
-
is
Alias for
.satisfies(Condition)
- Specified by:
is
in classGenericAssert<Throwable>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualThrowable
does not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for
.doesNotSatisfy(Condition)
- Specified by:
isNot
in classGenericAssert<Throwable>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualThrowable
satisfies the given condition.- Since:
- 1.2
-
overridingErrorMessage
Replaces the default message displayed in case of a failure with the given one.For example, the following assertion:
assertThat("Hello").isEqualTo("Bye");
will fail with the default message "expected:<'[Bye]'> but was:<'[Hello]'>."We can replace this message with our own:
assertThat("Hello").overridingErrorMessage("'Hello' should be equal to 'Bye'").isEqualTo("Bye");
in this case, the assertion will fail showing the message "'Hello' should be equal to 'Bye'".- Specified by:
overridingErrorMessage
in classGenericAssert<Throwable>
- Parameters:
message
- the given error message, which will replace the default one.- Returns:
- this assertion.
-