Top Description Fields Constructors Methods
org.assertj.core.internal

public Class Throwables

extends Object
Class Inheritance
Static Imports
java.util.Arrays.stream, .Objects.requireNonNull, java.util.stream.Collectors.toCollection, org.assertj.core.error.ShouldContainCharSequence.shouldContain, .ShouldEndWith.shouldEndWith, .ShouldHaveCause.shouldHaveCause, .ShouldHaveCauseExactlyInstance.shouldHaveCauseExactlyInstance, .ShouldHaveCauseInstance.shouldHaveCauseInstance, .ShouldHaveCauseReference.shouldHaveCauseReference, .ShouldHaveMessage.shouldHaveMessage, .ShouldHaveMessageFindingMatchRegex.shouldHaveMessageFindingMatchRegex, .ShouldHaveMessageMatchingRegex.shouldHaveMessageMatchingRegex, .ShouldHaveNoCause.shouldHaveNoCause, .ShouldHaveNoSuppressedExceptions.shouldHaveNoSuppressedExceptions, .ShouldHaveRootCause.shouldHaveRootCause, .ShouldHaveRootCause.shouldHaveRootCauseWithMessage, .ShouldHaveRootCauseExactlyInstance.shouldHaveRootCauseExactlyInstance, .ShouldHaveRootCauseInstance.shouldHaveRootCauseInstance, .ShouldHaveSuppressedException.shouldHaveSuppressedException, .ShouldNotContainCharSequence.shouldNotContain, .ShouldStartWith.shouldStartWith, org.assertj.core.internal.CommonErrors.arrayOfValuesToLookForIsEmpty, .CommonErrors.arrayOfValuesToLookForIsNull, .CommonValidations.checkTypeIsNotNull, org.assertj.core.util.Throwables.getRootCause

Reusable assertions for Throwables.
Authors
Joel Costigliola, Libor Ondrusek, Jack Gough, Mike Gilchrist

Field Summary

Modifier and TypeField and Description
pack-priv Failures
private static final Throwables

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
assertHasCause(AssertionInfo info, Throwable actual, Throwable expectedCause)

public void
assertHasCause(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
)

Asserts that the actual Throwable has a cause.

public void
assertHasCauseExactlyInstanceOf(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
Class<? extends Throwable>
the expected cause type.
type
)

Assert that the cause of actual Throwable is exactly an instance of the given type.

public void
assertHasCauseInstanceOf(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
Class<? extends Throwable>
the expected cause type.
type
)

Assert that the cause of actual Throwable is an instance of the given type.

public void
assertHasCauseReference(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
Throwable
the expected cause.
expectedCause
)

Asserts that the actual Throwable has a cause that refers to the expected one.

public void
assertHasMessage(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
String
the expected message.
expectedMessage
)

Asserts that the given actual Throwable message is equal to the given one.

public void
assertHasMessageContaining(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
String
the description expected to be contained in the actual Throwable's message.
description
)

Asserts that the message of the actual Throwable contains with the given description.

public void
assertHasMessageContainingAll(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
CharSequence...
the Strings expected to be contained in the actual Throwable's message.
values
)

Asserts that the message of the actual Throwable contains with the given values.

public void
assertHasMessageEndingWith(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
String
the description expected to end the actual Throwable's message.
description
)

Asserts that the message of the actual Throwable ends with the given description.

public void
assertHasMessageFindingMatch(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
String
the regular expression expected to be found in the actual Throwable's message.
regex
)

Asserts that a sequence of the message of the actual Throwable matches with the given regular expression (see java.util.regex.Matcher#find()).

public void
assertHasMessageMatching(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
Pattern
the regular expression of value expected to be matched the actual Throwable's message.
regex
)

Asserts that the message of the actual Throwable matches with the given regular expression.

public void
public void
assertHasMessageNotContaining(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
String
the content expected not to be contained in the actual Throwable's message.
content
)

Asserts that the message of the actual Throwable does not contain the given content or is null.

public void
assertHasMessageNotContainingAny(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
CharSequence...
the contents expected to not be contained in the actual Throwable's message.
values
)

Asserts that the message of the actual Throwable does not contain any of the given values or is null.

public void
assertHasMessageStartingWith(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
String
the description expected to start the actual Throwable's message.
description
)

Asserts that the message of the actual Throwable starts with the given description.

public void
assertHasNoCause(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
)

Asserts that the actual Throwable does not have a cause.

public void
public void
assertHasRootCause(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
Throwable
the expected root cause.
expectedRootCause
)

Asserts that the actual Throwable has a root cause similar to the given one.

public void
assertHasRootCause(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
)

Asserts that the actual Throwable has a root cause.

public void
assertHasRootCauseExactlyInstanceOf(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
Class<? extends Throwable>
the expected cause type.
type
)

Assert that the root cause of actual Throwable is exactly an instance of the given type.

public void
assertHasRootCauseInstanceOf(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
Class<? extends Throwable>
the expected cause type.
type
)

Assert that the root cause of actual Throwable is an instance of the given type.

public void
assertHasRootCauseMessage(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
String
the expected message of the root cause.
expectedMessage
)

Asserts that the message of the root cause of the actual Throwable is equal to the given one.

public void
assertHasStackTraceContaining(AssertionInfo
contains information about the assertion.
info
,
Throwable
the given Throwable.
actual
,
String
the description expected to be contained in the actual Throwable's stack trace.
description
)

Asserts that the stack trace of the actual Throwable contains with the given description.

public void
assertHasSuppressedException(AssertionInfo info, Throwable actual, Throwable expectedSuppressedException)

private static void
private static void
private static void
private static void
private static void
private static boolean
private static void
public static Throwables

Returns:

the singleton instance of this class.
instance
()

Returns the singleton instance of this class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

failuresback to summary
pack-priv Failures failures
Annotations
@VisibleForTesting
INSTANCEback to summary
private static final Throwables INSTANCE

Constructor Detail

Throwablesback to summary
pack-priv Throwables()
Annotations
@VisibleForTesting

Method Detail

assertHasCauseback to summary
public void assertHasCause(AssertionInfo info, Throwable actual, Throwable expectedCause)
assertHasCauseback to summary
public void assertHasCause(AssertionInfo info, Throwable actual)

Asserts that the actual Throwable has a cause.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the actual Throwable does not have a cause.
assertHasCauseExactlyInstanceOfback to summary
public void assertHasCauseExactlyInstanceOf(AssertionInfo info, Throwable actual, Class<? extends Throwable> type)

Assert that the cause of actual Throwable is exactly an instance of the given type.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

type:Class<? extends Throwable>

the expected cause type.

Exceptions
NullPointerException:
if given type is null.
AssertionError:
  • if the actual Throwable is null.
  • if the actual Throwable has no cause.
  • if the cause of the actual Throwable is not exactly an instance of the given type.
assertHasCauseInstanceOfback to summary
public void assertHasCauseInstanceOf(AssertionInfo info, Throwable actual, Class<? extends Throwable> type)

Assert that the cause of actual Throwable is an instance of the given type.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

type:Class<? extends Throwable>

the expected cause type.

Exceptions
NullPointerException:
if given type is null.
AssertionError:
  • if the actual Throwable is null.
  • if the actual Throwable has no cause.
  • if the cause of the actual Throwable is not an instance of the given type.
assertHasCauseReferenceback to summary
public void assertHasCauseReference(AssertionInfo info, Throwable actual, Throwable expectedCause)

Asserts that the actual Throwable has a cause that refers to the expected one.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

expectedCause:Throwable

the expected cause.

assertHasMessageback to summary
public void assertHasMessage(AssertionInfo info, Throwable actual, String expectedMessage)

Asserts that the given actual Throwable message is equal to the given one.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

expectedMessage:String

the expected message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable is not equal to the given one.
assertHasMessageContainingback to summary
public void assertHasMessageContaining(AssertionInfo info, Throwable actual, String description)

Asserts that the message of the actual Throwable contains with the given description.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

description:String

the description expected to be contained in the actual Throwable's message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable does not contain the given description.
assertHasMessageContainingAllback to summary
public void assertHasMessageContainingAll(AssertionInfo info, Throwable actual, CharSequence... values)

Asserts that the message of the actual Throwable contains with the given values.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

values:CharSequence[]

the Strings expected to be contained in the actual Throwable's message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable does not contain the given description.
assertHasMessageEndingWithback to summary
public void assertHasMessageEndingWith(AssertionInfo info, Throwable actual, String description)

Asserts that the message of the actual Throwable ends with the given description.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

description:String

the description expected to end the actual Throwable's message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable does not end with the given description.
assertHasMessageFindingMatchback to summary
public void assertHasMessageFindingMatch(AssertionInfo info, Throwable actual, String regex)

Asserts that a sequence of the message of the actual Throwable matches with the given regular expression (see java.util.regex.Matcher#find()). The Pattern used under the hood enables the Pattern#DOTALL mode.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

regex:String

the regular expression expected to be found in the actual Throwable's message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable doesn't contain any sequence matching with the given regular expression
NullPointerException:
if the regex is null
assertHasMessageMatchingback to summary
public void assertHasMessageMatching(AssertionInfo info, Throwable actual, Pattern regex)

Asserts that the message of the actual Throwable matches with the given regular expression.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

regex:Pattern

the regular expression of value expected to be matched the actual Throwable's message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable does not match the given regular expression.
NullPointerException:
if the regex is null
assertHasMessageMatchingback to summary
public void assertHasMessageMatching(AssertionInfo info, Throwable actual, String regex)
See Also
assertHasMessageMatching(AssertionInfo, Throwable, Pattern)
assertHasMessageNotContainingback to summary
public void assertHasMessageNotContaining(AssertionInfo info, Throwable actual, String content)

Asserts that the message of the actual Throwable does not contain the given content or is null.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

content:String

the content expected not to be contained in the actual Throwable's message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable contains the given content.
Since
3.12.0
assertHasMessageNotContainingAnyback to summary
public void assertHasMessageNotContainingAny(AssertionInfo info, Throwable actual, CharSequence... values)

Asserts that the message of the actual Throwable does not contain any of the given values or is null.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

values:CharSequence[]

the contents expected to not be contained in the actual Throwable's message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable does not contain the given description.
assertHasMessageStartingWithback to summary
public void assertHasMessageStartingWith(AssertionInfo info, Throwable actual, String description)

Asserts that the message of the actual Throwable starts with the given description.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

description:String

the description expected to start the actual Throwable's message.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the message of the actual Throwable does not start with the given description.
assertHasNoCauseback to summary
public void assertHasNoCause(AssertionInfo info, Throwable actual)

Asserts that the actual Throwable does not have a cause.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the actual Throwable has a cause.
assertHasNoSuppressedExceptionsback to summary
public void assertHasNoSuppressedExceptions(AssertionInfo info, Throwable actual)
assertHasRootCauseback to summary
public void assertHasRootCause(AssertionInfo info, Throwable actual, Throwable expectedRootCause)

Asserts that the actual Throwable has a root cause similar to the given one.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

expectedRootCause:Throwable

the expected root cause.

assertHasRootCauseback to summary
public void assertHasRootCause(AssertionInfo info, Throwable actual)

Asserts that the actual Throwable has a root cause.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the actual Throwable does not have a root cause.
assertHasRootCauseExactlyInstanceOfback to summary
public void assertHasRootCauseExactlyInstanceOf(AssertionInfo info, Throwable actual, Class<? extends Throwable> type)

Assert that the root cause of actual Throwable is exactly an instance of the given type.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

type:Class<? extends Throwable>

the expected cause type.

Exceptions
NullPointerException:
if given type is null.
AssertionError:
  • if the actual Throwable is null.
  • if the actual Throwable has no cause.
  • if the root cause of the actual Throwable is not exactly an instance of the given type.
assertHasRootCauseInstanceOfback to summary
public void assertHasRootCauseInstanceOf(AssertionInfo info, Throwable actual, Class<? extends Throwable> type)

Assert that the root cause of actual Throwable is an instance of the given type.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

type:Class<? extends Throwable>

the expected cause type.

Exceptions
NullPointerException:
if given type is null.
AssertionError:
  • if the actual Throwable is null.
  • if the actual Throwable has no cause.
  • if the cause of the actual Throwable is not an instance of the given type.
assertHasRootCauseMessageback to summary
public void assertHasRootCauseMessage(AssertionInfo info, Throwable actual, String expectedMessage)

Asserts that the message of the root cause of the actual Throwable is equal to the given one.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

expectedMessage:String

the expected message of the root cause.

assertHasStackTraceContainingback to summary
public void assertHasStackTraceContaining(AssertionInfo info, Throwable actual, String description)

Asserts that the stack trace of the actual Throwable contains with the given description.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Throwable

the given Throwable.

description:String

the description expected to be contained in the actual Throwable's stack trace.

Exceptions
AssertionError:
  • if the actual Throwable is null.
  • if the stack trace of the actual Throwable does not contain the given description.
assertHasSuppressedExceptionback to summary
public void assertHasSuppressedException(AssertionInfo info, Throwable actual, Throwable expectedSuppressedException)
assertNotNullback to summary
private static void assertNotNull(AssertionInfo info, Throwable actual)
checkCharSequenceArrayDoesNotHaveNullElementsback to summary
private static void checkCharSequenceArrayDoesNotHaveNullElements(CharSequence[] values)
checkCharSequenceIsNotNullback to summary
private static void checkCharSequenceIsNotNull(CharSequence sequence)
checkIsNotEmptyback to summary
private static void checkIsNotEmpty(CharSequence... values)
checkIsNotNullback to summary
private static void checkIsNotNull(CharSequence... values)
compareThrowableback to summary
private static boolean compareThrowable(Throwable actual, Throwable expected)
doCommonCheckForMessagesback to summary
private static void doCommonCheckForMessages(AssertionInfo info, Throwable actual, CharSequence[] values)
instanceback to summary
public static Throwables instance()

Returns the singleton instance of this class.

Returns:Throwables

the singleton instance of this class.