Class ThrowableCollector
- Direct Known Subclasses:
OpenTest4JAwareThrowableCollector
Throwable
.
This class distinguishes between Throwables
that abort
and those that fail test execution. The latter take precedence over
the former, i.e. if both types of Throwables
were collected, the ones
that abort execution are reported as
suppressed Throwables
of the first Throwable
that failed execution.
- Since:
- 1.3
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface for an executable block of code that may throw aThrowable
.static interface
Factory forThrowableCollector
instances. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Assert that thisThrowableCollector
is empty (i.e., has not collected anyThrowables
).void
execute
(ThrowableCollector.Executable executable) Execute the suppliedThrowableCollector.Executable
and collect anyThrowable
thrown during the execution.Get the firstThrowable
collected by thisThrowableCollector
.boolean
isEmpty()
Determine if thisThrowableCollector
is empty (i.e., has not collected anyThrowables
).boolean
Determine if thisThrowableCollector
is not empty (i.e., has collected at least oneThrowable
).Convert the collectedThrowables
into aTestExecutionResult
.
-
Constructor Details
-
Method Details
-
execute
Execute the suppliedThrowableCollector.Executable
and collect anyThrowable
thrown during the execution.If the
Executable
throws an unrecoverable exception — for example, anOutOfMemoryError
— this method will rethrow it.- Parameters:
executable
- theExecutable
to execute- See Also:
-
getThrowable
Get the firstThrowable
collected by thisThrowableCollector
.If this collector is not empty, the first collected
Throwable
will be returned with any additionalThrowables
suppressed in the firstThrowable
.If the first collected
Throwable
aborted execution and at least one later collectedThrowable
failed execution, the first failingThrowable
will be returned with the previous aborting and any additionalThrowables
suppressed inside.- Returns:
- the first collected
Throwable
ornull
if thisThrowableCollector
is empty - See Also:
-
isEmpty
public boolean isEmpty()Determine if thisThrowableCollector
is empty (i.e., has not collected anyThrowables
). -
isNotEmpty
public boolean isNotEmpty()Determine if thisThrowableCollector
is not empty (i.e., has collected at least oneThrowable
). -
assertEmpty
public void assertEmpty()Assert that thisThrowableCollector
is empty (i.e., has not collected anyThrowables
).If this collector is not empty, the first collected
Throwable
will be thrown with any additionalThrowables
suppressed in the firstThrowable
. Note, however, that theThrowable
will not be wrapped. Rather, it will be masked as an unchecked exception.- See Also:
-
toTestExecutionResult
Convert the collectedThrowables
into aTestExecutionResult
.- Returns:
- aborted if the collected
Throwable
aborted execution; failed if it failed execution; and successful otherwise - Since:
- 1.6
-