@API(status=MAINTAINED,
since="1.3")
public class ThrowableCollector
extends java.lang.Object
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.
OpenTest4JAwareThrowableCollector
Modifier and Type | Class and Description |
---|---|
static interface |
ThrowableCollector.Executable
Functional interface for an executable block of code that may throw a
Throwable . |
static interface |
ThrowableCollector.Factory
Factory for
ThrowableCollector instances. |
Modifier and Type | Field and Description |
---|---|
private java.util.function.Predicate<? super java.lang.Throwable> |
abortedExecutionPredicate |
private java.lang.Throwable |
throwable |
Constructor and Description |
---|
ThrowableCollector(java.util.function.Predicate<? super java.lang.Throwable> abortedExecutionPredicate)
Create a new
ThrowableCollector that uses the supplied
Predicate to determine whether a Throwable
aborted or failed execution. |
Modifier and Type | Method and Description |
---|---|
private void |
add(java.lang.Throwable t)
Add the supplied
Throwable to this ThrowableCollector . |
void |
assertEmpty()
Assert that this
ThrowableCollector is empty (i.e.,
has not collected any Throwables ). |
void |
execute(ThrowableCollector.Executable executable)
Execute the supplied
ThrowableCollector.Executable and collect any Throwable
thrown during the execution. |
java.lang.Throwable |
getThrowable()
Get the first
Throwable collected by this
ThrowableCollector . |
private boolean |
hasAbortedExecution(java.lang.Throwable t) |
boolean |
isEmpty()
Determine if this
ThrowableCollector is empty (i.e.,
has not collected any Throwables ). |
boolean |
isNotEmpty()
Determine if this
ThrowableCollector is not empty (i.e.,
has collected at least one Throwable ). |
TestExecutionResult |
toTestExecutionResult()
Convert the collected
Throwables into a TestExecutionResult . |
private final java.util.function.Predicate<? super java.lang.Throwable> abortedExecutionPredicate
private java.lang.Throwable throwable
public ThrowableCollector(java.util.function.Predicate<? super java.lang.Throwable> abortedExecutionPredicate)
ThrowableCollector
that uses the supplied
Predicate
to determine whether a Throwable
aborted or failed execution.abortedExecutionPredicate
- the predicate used to decide whether a
Throwable
aborted execution; never null
.public void execute(ThrowableCollector.Executable executable)
ThrowableCollector.Executable
and collect any Throwable
thrown during the execution.
If the Executable
throws a blacklisted exception
— for example, an OutOfMemoryError
— this method will
rethrow it.
executable
- the Executable
to executeassertEmpty()
private void add(java.lang.Throwable t)
Throwable
to this ThrowableCollector
.t
- the Throwable
to addexecute(Executable)
,
assertEmpty()
public java.lang.Throwable getThrowable()
Throwable
collected by this
ThrowableCollector
.
If this collector is not empty, the first collected Throwable
will be returned with any additional Throwables
suppressed in the
first Throwable
.
If the first collected Throwable
aborted execution
and at least one later collected Throwable
failed
execution, the first failing Throwable
will be returned
with the previous aborting and any additional Throwables
suppressed inside.
Throwable
or null
if this
ThrowableCollector
is emptyisEmpty()
,
assertEmpty()
public boolean isEmpty()
ThrowableCollector
is empty (i.e.,
has not collected any Throwables
).public boolean isNotEmpty()
ThrowableCollector
is not empty (i.e.,
has collected at least one Throwable
).public void assertEmpty()
ThrowableCollector
is empty (i.e.,
has not collected any Throwables
).
If this collector is not empty, the first collected Throwable
will be thrown with any additional Throwables
suppressed in the
first Throwable
. Note, however, that the Throwable
will not be wrapped. Rather, it will be
masked
as an unchecked exception.
@API(status=MAINTAINED, since="1.6") public TestExecutionResult toTestExecutionResult()
Throwables
into a TestExecutionResult
.Throwable
aborted execution;
failed if it failed
execution; and successful
otherwiseprivate boolean hasAbortedExecution(java.lang.Throwable t)