org.assertj.core.api
Class AbstractThrowableAssert<S extends AbstractThrowableAssert<S,A>,A extends Throwable>

java.lang.Object
  extended by org.assertj.core.api.AbstractAssert<S,A>
      extended by org.assertj.core.api.AbstractThrowableAssert<S,A>
Type Parameters:
S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
A - the type of the "actual" value.
All Implemented Interfaces:
Assert<S,A>, Descriptable<S>, ExtensionPoints<S,A>
Direct Known Subclasses:
ThrowableAssert

public abstract class AbstractThrowableAssert<S extends AbstractThrowableAssert<S,A>,A extends Throwable>
extends AbstractAssert<S,A>

Base class for all implementations of assertions for Throwables.

Author:
David DIDIER, Alex Ruiz, Joel Costigliola, Mikhail Mazursky

Field Summary
 
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself
 
Constructor Summary
protected AbstractThrowableAssert(A actual, Class<?> selfType)
           
 
Method Summary
 S hasCauseExactlyInstanceOf(Class<? extends Throwable> type)
          Verifies that the cause of the actual Throwable is exactly an instance of the given type.
 S hasCauseInstanceOf(Class<? extends Throwable> type)
          Verifies that the cause of the actual Throwable is an instance of the given type.
 S hasMessage(String message)
          Verifies that the message of the actual Throwable is equal to the given one.
 S hasMessageContaining(String description)
          Verifies that the message of the actual Throwable contains with the given description.
 S hasMessageEndingWith(String description)
          Verifies that the message of the actual Throwable ends with the given description.
 S hasMessageStartingWith(String description)
          Verifies that the message of the actual Throwable starts with the given description.
 S hasNoCause()
          Verifies that the actual Throwable does not have a cause.
 S hasRootCauseExactlyInstanceOf(Class<? extends Throwable> type)
          Verifies that the root cause of the actual Throwable is exactly an instance of the given type.
 S hasRootCauseInstanceOf(Class<? extends Throwable> type)
          Verifies that the root cause of the actual Throwable is an instance of the given type.
 
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractThrowableAssert

protected AbstractThrowableAssert(A actual,
                                  Class<?> selfType)
Method Detail

hasMessage

public S 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 object.
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 S 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.

hasMessageStartingWith

public S hasMessageStartingWith(String description)
Verifies that the message of the actual Throwable starts with the given description.

Parameters:
description - the description expected to start the actual Throwable's message.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is null.
AssertionError - if the message of the actual Throwable does not start with the given description.

hasMessageContaining

public S hasMessageContaining(String description)
Verifies that the message of the actual Throwable contains with the given description.

Parameters:
description - the description expected to be contained in the actual Throwable's message.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is null.
AssertionError - if the message of the actual Throwable does not contain the given description.

hasMessageEndingWith

public S hasMessageEndingWith(String description)
Verifies that the message of the actual Throwable ends with the given description.

Parameters:
description - the description expected to end the actual Throwable's message.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Throwable is null.
AssertionError - if the message of the actual Throwable does not end with the given description.

hasCauseInstanceOf

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

Example:

 Throwable throwable = new Throwable(new NullPointerException());

 // assertion will pass
 assertThat(throwable).hasCauseInstanceOf(NullPointerException.class);
 assertThat(throwable).hasCauseInstanceOf(RuntimeException.class);

 // assertion will fail
 assertThat(throwable).hasCauseInstanceOf(IllegalArgumentException.class);
 

Parameters:
type - the expected cause type.
Returns:
this assertion object.
Throws:
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.

hasCauseExactlyInstanceOf

public S hasCauseExactlyInstanceOf(Class<? extends Throwable> type)
Verifies that the cause of the actual 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);
 

Parameters:
type - the expected cause type.
Returns:
this assertion object.
Throws:
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.

hasRootCauseInstanceOf

public S hasRootCauseInstanceOf(Class<? extends Throwable> type)
Verifies that the root cause of the actual Throwable is an instance of the given type.

Example:

 Throwable throwable = new Throwable(new IllegalStateException(new NullPointerException()));

 // assertion will pass
 assertThat(throwable).hasRootCauseInstanceOf(NullPointerException.class);
 assertThat(throwable).hasRootCauseInstanceOf(RuntimeException.class);

 // assertion will fail
 assertThat(throwable).hasRootCauseInstanceOf(IllegalStateException.class);
 

Parameters:
type - the expected cause type.
Returns:
this assertion object.
Throws:
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.

hasRootCauseExactlyInstanceOf

public S hasRootCauseExactlyInstanceOf(Class<? extends Throwable> type)
Verifies that the root cause of the actual 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);

 // assertion will fail (even if NullPointerException is a RuntimeException since we want an exact match)
 assertThat(throwable).hasRootCauseExactlyInstanceOf(RuntimeException.class);
 assertThat(throwable).hasRootCauseExactlyInstanceOf(IllegalStateException.class);
 

Parameters:
type - the expected cause type.
Returns:
this assertion object.
Throws:
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.


Copyright © 2013–2015 AssertJ. All rights reserved.