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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for an executable block of code that may throw aThrowable.static interfaceFactory forThrowableCollectorinstances. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAssert that thisThrowableCollectoris empty (i.e., has not collected anyThrowables).voidexecute(ThrowableCollector.Executable executable) Execute the suppliedThrowableCollector.Executableand collect anyThrowablethrown during the execution.Get the firstThrowablecollected by thisThrowableCollector.booleanisEmpty()Determine if thisThrowableCollectoris empty (i.e., has not collected anyThrowables).booleanDetermine if thisThrowableCollectoris not empty (i.e., has collected at least oneThrowable).Convert the collectedThrowablesinto aTestExecutionResult.
-
Constructor Details
-
Method Details
-
execute
Execute the suppliedThrowableCollector.Executableand collect anyThrowablethrown during the execution.If the
Executablethrows an unrecoverable exception — for example, anOutOfMemoryError— this method will rethrow it.- Parameters:
executable- theExecutableto execute- See Also:
-
getThrowable
Get the firstThrowablecollected by thisThrowableCollector.If this collector is not empty, the first collected
Throwablewill be returned with any additionalThrowablessuppressed in the firstThrowable.If the first collected
Throwableaborted execution and at least one later collectedThrowablefailed execution, the first failingThrowablewill be returned with the previous aborting and any additionalThrowablessuppressed inside.- Returns:
- the first collected
Throwableornullif thisThrowableCollectoris empty - See Also:
-
isEmpty
public boolean isEmpty()Determine if thisThrowableCollectoris empty (i.e., has not collected anyThrowables). -
isNotEmpty
public boolean isNotEmpty()Determine if thisThrowableCollectoris not empty (i.e., has collected at least oneThrowable). -
assertEmpty
public void assertEmpty()Assert that thisThrowableCollectoris empty (i.e., has not collected anyThrowables).If this collector is not empty, the first collected
Throwablewill be thrown with any additionalThrowablessuppressed in the firstThrowable. Note, however, that theThrowablewill not be wrapped. Rather, it will be masked as an unchecked exception.- See Also:
-
toTestExecutionResult
Convert the collectedThrowablesinto aTestExecutionResult.- Returns:
- aborted if the collected
Throwableaborted execution; failed if it failed execution; and successful otherwise - Since:
- 1.6
-