Top Description Inners Fields Constructors Methods
org.junit.platform.engine.support.hierarchical

public Class ThrowableCollector

extends Object
Class Inheritance
Known Direct Subclasses
org.junit.platform.engine.support.hierarchical.OpenTest4JAwareThrowableCollector
Annotations
@API
status:MAINTAINED
since:1.3
Static Imports
org.apiguardian.api.API.Status.MAINTAINED, org.junit.platform.engine.TestExecutionResult.aborted, .TestExecutionResult.failed, .TestExecutionResult.successful

Simple component that can be used to collect one or more instances of 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
OpenTest4JAwareThrowableCollector

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ThrowableCollector.Executable

Functional interface for an executable block of code that may throw a Throwable.

public static interface
ThrowableCollector.Factory

Factory for ThrowableCollector instances.

Field Summary

Modifier and TypeField and Description
private final Predicate<? super Throwable>
private Throwable

Constructor Summary

AccessConstructor and Description
public
ThrowableCollector(Predicate<? super Throwable>
the predicate used to decide whether a Throwable aborted execution; never null.
abortedExecutionPredicate
)

Create a new ThrowableCollector that uses the supplied Predicate to determine whether a Throwable aborted or failed execution.

Method Summary

Modifier and TypeMethod and Description
private void
add(Throwable
the Throwable to add
t
)

Add the supplied Throwable to this ThrowableCollector.

public void
assertEmpty()

Assert that this ThrowableCollector is empty (i.e., has not collected any Throwables).

public void
execute(ThrowableCollector.Executable
the Executable to execute
executable
)

Execute the supplied Executable and collect any Throwable thrown during the execution.

public Throwable

Returns:

the first collected Throwable or null if this ThrowableCollector is empty
getThrowable
()

Get the first Throwable collected by this ThrowableCollector.

private boolean
public boolean
isEmpty()

Determine if this ThrowableCollector is empty (i.e., has not collected any Throwables).

public boolean
isNotEmpty()

Determine if this ThrowableCollector is not empty (i.e., has collected at least one Throwable).

public TestExecutionResult

Returns:

aborted if the collected Throwable aborted execution; failed if it failed execution; and successful otherwise
toTestExecutionResult
()

Convert the collected Throwables into a TestExecutionResult.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

abortedExecutionPredicateback to summary
private final Predicate<? super Throwable> abortedExecutionPredicate
throwableback to summary
private Throwable throwable

Constructor Detail

ThrowableCollectorback to summary
public ThrowableCollector(Predicate<? super Throwable> abortedExecutionPredicate)

Create a new ThrowableCollector that uses the supplied Predicate to determine whether a Throwable aborted or failed execution.

Parameters
abortedExecutionPredicate:Predicate<? super Throwable>

the predicate used to decide whether a Throwable aborted execution; never null.

Method Detail

addback to summary
private void add(Throwable t)

Add the supplied Throwable to this ThrowableCollector.

Parameters
t:Throwable

the Throwable to add

See Also
execute(Executable), assertEmpty()
assertEmptyback to summary
public void assertEmpty()

Assert that this 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.

See Also
getThrowable(), ExceptionUtils#throwAsUncheckedException(Throwable)
executeback to summary
public void execute(ThrowableCollector.Executable executable)

Execute the supplied Executable and collect any Throwable thrown during the execution.

If the Executable throws an unrecoverable exception — for example, an OutOfMemoryError — this method will rethrow it.

Parameters
executable:ThrowableCollector.Executable

the Executable to execute

See Also
assertEmpty()
getThrowableback to summary
public Throwable getThrowable()

Get the first 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.

Returns:Throwable

the first collected Throwable or null if this ThrowableCollector is empty

See Also
isEmpty(), assertEmpty()
hasAbortedExecutionback to summary
private boolean hasAbortedExecution(Throwable t)
isEmptyback to summary
public boolean isEmpty()

Determine if this ThrowableCollector is empty (i.e., has not collected any Throwables).

isNotEmptyback to summary
public boolean isNotEmpty()

Determine if this ThrowableCollector is not empty (i.e., has collected at least one Throwable).

toTestExecutionResultback to summary
public TestExecutionResult toTestExecutionResult()

Convert the collected Throwables into a TestExecutionResult.

Returns:TestExecutionResult

aborted if the collected Throwable aborted execution; failed if it failed execution; and successful otherwise

Annotations
@API
status:MAINTAINED
since:1.6
Since
1.6
org.junit.platform.engine.support.hierarchical back to summary

public Interface ThrowableCollector.Executable

Annotations
@FunctionalInterface

Functional interface for an executable block of code that may throw a Throwable.

Method Summary

Modifier and TypeMethod and Description
public void
execute()

Execute this executable, potentially throwing a Throwable that signals abortion or failure.

Method Detail

executeback to summary
public void execute() throws Throwable

Execute this executable, potentially throwing a Throwable that signals abortion or failure.

org.junit.platform.engine.support.hierarchical back to summary

public Interface ThrowableCollector.Factory


Factory for ThrowableCollector instances.

Method Summary

Modifier and TypeMethod and Description
public ThrowableCollector
create()

Create a new instance of a ThrowableCollector.

Method Detail

createback to summary
public ThrowableCollector create()

Create a new instance of a ThrowableCollector.