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
ConstructorsModifierConstructorDescriptionprotectedThrowableAssert(Throwable actual) Creates a newThrowableAssert. -
Method Summary
Modifier and TypeMethodDescriptionSets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErroras(Description description) Sets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErrordescribedAs(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 actualThrowabledoes not satisfy the given condition.hasMessage(String message) Verifies that the message of the actualThrowableis equal to the given one.Verifies that the actualThrowabledoes not have a cause.Alias for.satisfies(Condition)Verifies that the actualThrowableis equal to the given one.isExactlyInstanceOf(Class<?> type) Verifies that the actualThrowableis an instance of the given type.isInstanceOf(Class<? extends Throwable> type) Verifies that the actualThrowableis an instance of the given type.Alias for.doesNotSatisfy(Condition)isNotEqualTo(Throwable other) Verifies that the actualThrowableis not equal to the given one.Verifies that the actualThrowableis notnull.isNotSameAs(Throwable other) Verifies that the actualThrowableis not the same as the given one.Verifies that the actualThrowableis 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 actualThrowablesatisfies the given condition.Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNullMethods 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 anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as("name").isEqualTo("Frodo");- Specified by:
asin 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:
describedAsin 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 anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");- Specified by:
asin 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:
describedAsin classGenericAssert<Throwable>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
isInstanceOf
Verifies that the actualThrowableis an instance of the given type.- Parameters:
type- the type to check the actualThrowableagainst.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualThrowableisnull.AssertionError- if the actualThrowableis not an instance of the given type.NullPointerException- if the given type isnull.
-
isExactlyInstanceOf
Verifies that the actualThrowableis an instance of the given type. In order for the assertion to pass, the type of the actualThrowablehas to be exactly the same as the given type.- Parameters:
type- the type to check the actualThrowableagainst.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualThrowableisnull.AssertionError- if the actualThrowableis not an instance of the given type.NullPointerException- if the given type isnull.
-
hasMessage
Verifies that the message of the actualThrowableis equal to the given one.- Parameters:
message- the expected message.- Returns:
- this assertion error.
- Throws:
AssertionError- if the actualThrowableisnull.AssertionError- if the message of the actualThrowableis not equal to the given one.
-
hasNoCause
Verifies that the actualThrowabledoes not have a cause.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualThrowableisnull.AssertionError- if the actualThrowablehas a cause.
-
isEqualTo
Verifies that the actualThrowableis equal to the given one.- Specified by:
isEqualToin classGenericAssert<Throwable>- Parameters:
expected- the givenThrowableto compare the actualThrowableto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualThrowableis not equal to the given one.
-
isNotEqualTo
Verifies that the actualThrowableis not equal to the given one.- Specified by:
isNotEqualToin classGenericAssert<Throwable>- Parameters:
other- the givenThrowableto compare the actualThrowableto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualThrowableis equal to the given one.
-
isNotNull
Verifies that the actualThrowableis notnull.- Specified by:
isNotNullin classGenericAssert<Throwable>- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualThrowableisnull.
-
isNotSameAs
Verifies that the actualThrowableis not the same as the given one.- Specified by:
isNotSameAsin classGenericAssert<Throwable>- Parameters:
other- the givenThrowableto compare the actualThrowableto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualThrowableis the same as the given one.
-
isSameAs
Verifies that the actualThrowableis the same as the given one.- Specified by:
isSameAsin classGenericAssert<Throwable>- Parameters:
expected- the givenThrowableto compare the actualThrowableto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualThrowableis not the same as the given one.
-
satisfies
Verifies that the actualThrowablesatisfies the given condition.- Specified by:
satisfiesin classGenericAssert<Throwable>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualThrowabledoes not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualThrowabledoes not satisfy the given condition.- Specified by:
doesNotSatisfyin classGenericAssert<Throwable>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualThrowablesatisfies the given condition.- See Also:
-
is
Alias for.satisfies(Condition)- Specified by:
isin classGenericAssert<Throwable>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualThrowabledoes not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for.doesNotSatisfy(Condition)- Specified by:
isNotin classGenericAssert<Throwable>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualThrowablesatisfies 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:
overridingErrorMessagein classGenericAssert<Throwable>- Parameters:
message- the given error message, which will replace the default one.- Returns:
- this assertion.
-