org.fest.assertions
Class ThrowableAssert

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<Throwable>
          extended by org.fest.assertions.ThrowableAssert

public class ThrowableAssert
extends GenericAssert<Throwable>

Understands assertion methods for Throwable. To create a new instance of this class use the method Assertions.assertThat(Throwable).

Author:
David DIDIER, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual
 
Constructor Summary
protected ThrowableAssert(Throwable actual)
          Creates a new ThrowableAssert.
 
Method Summary
 ThrowableAssert as(Description description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 ThrowableAssert as(String description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 ThrowableAssert describedAs(Description description)
          Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy.
 ThrowableAssert describedAs(String description)
          Alias for GenericAssert.as(String), since "as" is a keyword in Groovy.
 ThrowableAssert doesNotSatisfy(Condition<Throwable> condition)
          Verifies that the actual Throwable does not satisfy the given condition.
 ThrowableAssert hasMessage(String message)
          Verifies that the message of the actual Throwable is equal to the given one.
 ThrowableAssert hasNoCause()
          Verifies that the actual Throwable does not have a cause.
 ThrowableAssert is(Condition<Throwable> condition)
          Alias for satisfies(Condition).
 ThrowableAssert isEqualTo(Throwable expected)
          Verifies that the actual Throwable is equal to the given one.
 ThrowableAssert isExactlyInstanceOf(Class<?> type)
          Verifies that the actual Throwable is an instance of the given type.
 ThrowableAssert isInstanceOf(Class<? extends Throwable> type)
          Verifies that the actual Throwable is an instance of the given type.
 ThrowableAssert isNot(Condition<Throwable> condition)
          Alias for doesNotSatisfy(Condition).
 ThrowableAssert isNotEqualTo(Throwable other)
          Verifies that the actual Throwable is not equal to the given one.
 ThrowableAssert isNotNull()
          Verifies that the actual Throwable is not null.
 ThrowableAssert isNotSameAs(Throwable other)
          Verifies that the actual Throwable is not the same as the given one.
 ThrowableAssert isSameAs(Throwable expected)
          Verifies that the actual Throwable is the same as the given one.
 ThrowableAssert overridingErrorMessage(String message)
          Replaces the default message displayed in case of a failure with the given one.
 ThrowableAssert satisfies(Condition<Throwable> condition)
          Verifies that the actual Throwable 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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThrowableAssert

protected ThrowableAssert(Throwable actual)
Creates a new ThrowableAssert.

Parameters:
actual - the target to verify.
Method Detail

as

public ThrowableAssert as(String description)
Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).as("name").isEqualTo("Frodo");
 

Specified by:
as in class GenericAssert<Throwable>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public ThrowableAssert describedAs(String description)
Alias for GenericAssert.as(String), 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.

For example:

 assertThat(val).describedAs("name").isEqualTo("Frodo");
 

Specified by:
describedAs in class GenericAssert<Throwable>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

public ThrowableAssert as(Description description)
Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
 

Specified by:
as in class GenericAssert<Throwable>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public ThrowableAssert describedAs(Description description)
Alias for GenericAssert.as(Description), 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.

For example:

 assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");
 

Specified by:
describedAs in class GenericAssert<Throwable>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

isInstanceOf

public ThrowableAssert isInstanceOf(Class<? extends Throwable> type)
Verifies that the actual Throwable is an instance of the given type.

Parameters:
type - the type to check the actual Throwable against.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is null.
AssertionError - if the actual Throwable is not an instance of the given type.
NullPointerException - if the given type is null.

isExactlyInstanceOf

public ThrowableAssert isExactlyInstanceOf(Class<?> type)
Verifies that the actual Throwable is an instance of the given type. In order for the assertion to pass, the type of the actual Throwable has to be exactly the same as the given type.

Parameters:
type - the type to check the actual Throwable against.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is null.
AssertionError - if the actual Throwable is not an instance of the given type.
NullPointerException - if the given type is null.

hasMessage

public ThrowableAssert hasMessage(String message)
Verifies that the message of the actual Throwable is equal to the given one.

Parameters:
message - the expected message.
Returns:
this assertion error.
Throws:
AssertionError - if the actual Throwable is null.
AssertionError - if the message of the actual Throwable is not equal to the given one.

hasNoCause

public ThrowableAssert hasNoCause()
Verifies that the actual Throwable does not have a cause.

Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is null.
AssertionError - if the actual Throwable has a cause.

isEqualTo

public ThrowableAssert isEqualTo(Throwable expected)
Verifies that the actual Throwable is equal to the given one.

Specified by:
isEqualTo in class GenericAssert<Throwable>
Parameters:
expected - the given Throwable to compare the actual Throwable to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is not equal to the given one.

isNotEqualTo

public ThrowableAssert isNotEqualTo(Throwable other)
Verifies that the actual Throwable is not equal to the given one.

Specified by:
isNotEqualTo in class GenericAssert<Throwable>
Parameters:
other - the given Throwable to compare the actual Throwable to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is equal to the given one.

isNotNull

public ThrowableAssert isNotNull()
Verifies that the actual Throwable is not null.

Specified by:
isNotNull in class GenericAssert<Throwable>
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is null.

isNotSameAs

public ThrowableAssert isNotSameAs(Throwable other)
Verifies that the actual Throwable is not the same as the given one.

Specified by:
isNotSameAs in class GenericAssert<Throwable>
Parameters:
other - the given Throwable to compare the actual Throwable to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is the same as the given one.

isSameAs

public ThrowableAssert isSameAs(Throwable expected)
Verifies that the actual Throwable is the same as the given one.

Specified by:
isSameAs in class GenericAssert<Throwable>
Parameters:
expected - the given Throwable to compare the actual Throwable to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is not the same as the given one.

satisfies

public ThrowableAssert satisfies(Condition<Throwable> condition)
Verifies that the actual Throwable satisfies the given condition.

Specified by:
satisfies in class GenericAssert<Throwable>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Throwable does not satisfy the given condition.
See Also:
is(Condition)

doesNotSatisfy

public ThrowableAssert doesNotSatisfy(Condition<Throwable> condition)
Verifies that the actual Throwable does not satisfy the given condition.

Specified by:
doesNotSatisfy in class GenericAssert<Throwable>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Throwable satisfies the given condition.
See Also:
isNot(Condition)

is

public ThrowableAssert is(Condition<Throwable> condition)
Alias for satisfies(Condition).

Specified by:
is in class GenericAssert<Throwable>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Throwable does not satisfy the given condition.
Since:
1.2

isNot

public ThrowableAssert isNot(Condition<Throwable> condition)
Alias for doesNotSatisfy(Condition).

Specified by:
isNot in class GenericAssert<Throwable>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Throwable satisfies the given condition.
Since:
1.2

overridingErrorMessage

public ThrowableAssert overridingErrorMessage(String message)
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 class GenericAssert<Throwable>
Parameters:
message - the given error message, which will replace the default one.
Returns:
this assertion.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.