public class Throwables
extends java.lang.Object
Throwable
s.Modifier and Type | Field and Description |
---|---|
(package private) Failures |
failures |
private static Throwables |
INSTANCE |
Constructor and Description |
---|
Throwables() |
Modifier and Type | Method and Description |
---|---|
void |
assertHasCause(AssertionInfo info,
java.lang.Throwable actual,
java.lang.Throwable expectedCause) |
void |
assertHasCauseExactlyInstanceOf(AssertionInfo info,
java.lang.Throwable actual,
java.lang.Class<? extends java.lang.Throwable> type)
Assert that the cause of actual
Throwable is exactly an instance of the given type. |
void |
assertHasCauseInstanceOf(AssertionInfo info,
java.lang.Throwable actual,
java.lang.Class<? extends java.lang.Throwable> type)
Assert that the cause of actual
Throwable is an instance of the given type. |
void |
assertHasCauseReference(AssertionInfo info,
java.lang.Throwable actual,
java.lang.Throwable expectedCause)
Asserts that the actual
Throwable has a cause that refers to the expected one. |
void |
assertHasMessage(AssertionInfo info,
java.lang.Throwable actual,
java.lang.String expectedMessage)
Asserts that the given actual
Throwable message is equal to the given one. |
void |
assertHasMessageContaining(AssertionInfo info,
java.lang.Throwable actual,
java.lang.String description)
Asserts that the message of the actual
Throwable contains with the given description. |
void |
assertHasMessageContainingAll(AssertionInfo info,
java.lang.Throwable actual,
java.lang.CharSequence... values)
Asserts that the message of the actual
Throwable contains with the given values. |
void |
assertHasMessageEndingWith(AssertionInfo info,
java.lang.Throwable actual,
java.lang.String description)
Asserts that the message of the actual
Throwable ends with the given description. |
void |
assertHasMessageFindingMatch(AssertionInfo info,
java.lang.Throwable actual,
java.lang.String regex)
Asserts that a sequence of the message of the actual
Throwable matches with the given regular expression (see Matcher.find() ). |
void |
assertHasMessageMatching(AssertionInfo info,
java.lang.Throwable actual,
java.lang.String regex)
Asserts that the message of the actual
Throwable matches with the given regular expression. |
void |
assertHasMessageNotContaining(AssertionInfo info,
java.lang.Throwable actual,
java.lang.String content)
Asserts that the message of the actual
Throwable does not contain the given content or is null . |
void |
assertHasMessageNotContainingAny(AssertionInfo info,
java.lang.Throwable actual,
java.lang.CharSequence... values)
Asserts that the message of the actual
Throwable does not contain any of the given values or is null . |
void |
assertHasMessageStartingWith(AssertionInfo info,
java.lang.Throwable actual,
java.lang.String description)
Asserts that the message of the actual
Throwable starts with the given description. |
void |
assertHasNoCause(AssertionInfo info,
java.lang.Throwable actual)
Asserts that the actual
Throwable does not have a cause. |
void |
assertHasNoSuppressedExceptions(AssertionInfo info,
java.lang.Throwable actual) |
void |
assertHasRootCause(AssertionInfo info,
java.lang.Throwable actual,
java.lang.Throwable expectedRootCause)
Asserts that the actual
Throwable has a root cause similar to the given one. |
void |
assertHasRootCauseExactlyInstanceOf(AssertionInfo info,
java.lang.Throwable actual,
java.lang.Class<? extends java.lang.Throwable> type)
Assert that the root cause of actual
Throwable is exactly an instance of the given type. |
void |
assertHasRootCauseInstanceOf(AssertionInfo info,
java.lang.Throwable actual,
java.lang.Class<? extends java.lang.Throwable> type)
Assert that the root cause of actual
Throwable is an instance of the given type. |
void |
assertHasStackTraceContaining(AssertionInfo info,
java.lang.Throwable actual,
java.lang.String description)
Asserts that the stack trace of the actual
Throwable contains with the given description. |
void |
assertHasSuppressedException(AssertionInfo info,
java.lang.Throwable actual,
java.lang.Throwable expectedSuppressedException) |
private static void |
assertNotNull(AssertionInfo info,
java.lang.Throwable actual) |
private static void |
checkCharSequenceArrayDoesNotHaveNullElements(java.lang.CharSequence[] values) |
private static void |
checkCharSequenceIsNotNull(java.lang.CharSequence sequence) |
private static void |
checkIsNotEmpty(java.lang.CharSequence... values) |
private static void |
checkIsNotNull(java.lang.CharSequence... values) |
private static boolean |
compareThrowable(java.lang.Throwable actual,
java.lang.Throwable expected) |
private static void |
doCommonCheckForMessages(AssertionInfo info,
java.lang.Throwable actual,
java.lang.CharSequence[] values) |
static Throwables |
instance()
Returns the singleton instance of this class.
|
private static final Throwables INSTANCE
Failures failures
public static Throwables instance()
public void assertHasMessage(AssertionInfo info, java.lang.Throwable actual, java.lang.String expectedMessage)
Throwable
message is equal to the given one.info
- contains information about the assertion.actual
- the given Throwable
.expectedMessage
- the expected message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
is not equal to the given one.public void assertHasCause(AssertionInfo info, java.lang.Throwable actual, java.lang.Throwable expectedCause)
public void assertHasCauseReference(AssertionInfo info, java.lang.Throwable actual, java.lang.Throwable expectedCause)
Throwable
has a cause that refers to the expected one.info
- contains information about the assertion.actual
- the given Throwable
.expectedCause
- the expected cause.public void assertHasRootCause(AssertionInfo info, java.lang.Throwable actual, java.lang.Throwable expectedRootCause)
Throwable
has a root cause similar to the given one.info
- contains information about the assertion.actual
- the given Throwable
.expectedRootCause
- the expected root cause.public void assertHasNoCause(AssertionInfo info, java.lang.Throwable actual)
Throwable
does not have a cause.info
- contains information about the assertion.actual
- the given Throwable
.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the actual Throwable
has a cause.public void assertHasMessageStartingWith(AssertionInfo info, java.lang.Throwable actual, java.lang.String description)
Throwable
starts with the given description.info
- contains information about the assertion.actual
- the given Throwable
.description
- the description expected to start the actual Throwable
's message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
does not start with the given description.public void assertHasMessageContaining(AssertionInfo info, java.lang.Throwable actual, java.lang.String description)
Throwable
contains with the given description.info
- contains information about the assertion.actual
- the given Throwable
.description
- the description expected to be contained in the actual Throwable
's message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
does not contain the given description.public void assertHasMessageContainingAll(AssertionInfo info, java.lang.Throwable actual, java.lang.CharSequence... values)
Throwable
contains with the given values.info
- contains information about the assertion.actual
- the given Throwable
.values
- the Strings expected to be contained in the actual Throwable
's message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
does not contain the given description.public void assertHasMessageNotContaining(AssertionInfo info, java.lang.Throwable actual, java.lang.String content)
Throwable
does not contain the given content or is null
.info
- contains information about the assertion.actual
- the given Throwable
.content
- the content expected not to be contained in the actual Throwable
's message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
contains the given content.public void assertHasMessageNotContainingAny(AssertionInfo info, java.lang.Throwable actual, java.lang.CharSequence... values)
Throwable
does not contain any of the given values or is null
.info
- contains information about the assertion.actual
- the given Throwable
.values
- the contents expected to not be contained in the actual Throwables
's message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
does not contain the given description.public void assertHasStackTraceContaining(AssertionInfo info, java.lang.Throwable actual, java.lang.String description)
Throwable
contains with the given description.info
- contains information about the assertion.actual
- the given Throwable
.description
- the description expected to be contained in the actual Throwable
's stack trace.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the stack trace of the actual Throwable
does not contain the given description.public void assertHasMessageMatching(AssertionInfo info, java.lang.Throwable actual, java.lang.String regex)
Throwable
matches with the given regular expression.info
- contains information about the assertion.actual
- the given Throwable
.regex
- the regular expression of value expected to be matched the actual Throwable
's message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
does not match the given regular expression.java.lang.NullPointerException
- if the regex is nullpublic void assertHasMessageFindingMatch(AssertionInfo info, java.lang.Throwable actual, java.lang.String regex)
Throwable
matches with the given regular expression (see Matcher.find()
).
The Pattern used under the hood enables the Pattern.DOTALL
mode.info
- contains information about the assertion.actual
- the given Throwable
.regex
- the regular expression expected to be found in the actual Throwable
's message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
doesn't contain any sequence matching with the given regular expressionjava.lang.NullPointerException
- if the regex is nullpublic void assertHasMessageEndingWith(AssertionInfo info, java.lang.Throwable actual, java.lang.String description)
Throwable
ends with the given description.info
- contains information about the assertion.actual
- the given Throwable
.description
- the description expected to end the actual Throwable
's message.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the message of the actual Throwable
does not end with the given description.public void assertHasCauseInstanceOf(AssertionInfo info, java.lang.Throwable actual, java.lang.Class<? extends java.lang.Throwable> type)
Throwable
is an instance of the given type.info
- contains information about the assertion.actual
- the given Throwable
.type
- the expected cause type.java.lang.NullPointerException
- if given type is null
.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the actual Throwable
has no cause.java.lang.AssertionError
- if the cause of the actual Throwable
is not an instance of the given type.public void assertHasCauseExactlyInstanceOf(AssertionInfo info, java.lang.Throwable actual, java.lang.Class<? extends java.lang.Throwable> type)
Throwable
is exactly an instance of the given type.info
- contains information about the assertion.actual
- the given Throwable
.type
- the expected cause type.java.lang.NullPointerException
- if given type is null
.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the actual Throwable
has no cause.java.lang.AssertionError
- if the cause of the actual Throwable
is not exactly an instance of the given
type.public void assertHasRootCauseInstanceOf(AssertionInfo info, java.lang.Throwable actual, java.lang.Class<? extends java.lang.Throwable> type)
Throwable
is an instance of the given type.info
- contains information about the assertion.actual
- the given Throwable
.type
- the expected cause type.java.lang.NullPointerException
- if given type is null
.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the actual Throwable
has no cause.java.lang.AssertionError
- if the cause of the actual Throwable
is not an instance of the given type.public void assertHasRootCauseExactlyInstanceOf(AssertionInfo info, java.lang.Throwable actual, java.lang.Class<? extends java.lang.Throwable> type)
Throwable
is exactly an instance of the given type.info
- contains information about the assertion.actual
- the given Throwable
.type
- the expected cause type.java.lang.NullPointerException
- if given type is null
.java.lang.AssertionError
- if the actual Throwable
is null
.java.lang.AssertionError
- if the actual Throwable
has no cause.java.lang.AssertionError
- if the root cause of the actual Throwable
is not exactly an instance of the
given type.public void assertHasNoSuppressedExceptions(AssertionInfo info, java.lang.Throwable actual)
public void assertHasSuppressedException(AssertionInfo info, java.lang.Throwable actual, java.lang.Throwable expectedSuppressedException)
private static void doCommonCheckForMessages(AssertionInfo info, java.lang.Throwable actual, java.lang.CharSequence[] values)
private static void assertNotNull(AssertionInfo info, java.lang.Throwable actual)
private static void checkIsNotNull(java.lang.CharSequence... values)
private static void checkIsNotEmpty(java.lang.CharSequence... values)
private static void checkCharSequenceArrayDoesNotHaveNullElements(java.lang.CharSequence[] values)
private static void checkCharSequenceIsNotNull(java.lang.CharSequence sequence)
private static boolean compareThrowable(java.lang.Throwable actual, java.lang.Throwable expected)