Class ThrowableCollector
- java.lang.Object
-
- org.junit.platform.engine.support.hierarchical.ThrowableCollector
-
- Direct Known Subclasses:
OpenTest4JAwareThrowableCollector
@API(status=MAINTAINED, since="1.3") public class ThrowableCollector extends Object
Simple component that can be used to collect one or more instances ofThrowable.This class distinguishes between
Throwablesthat abort and those that fail test execution. The latter take precedence over the former, i.e. if both types ofThrowableswere collected, the ones that abort execution are reported as suppressedThrowablesof the firstThrowablethat failed execution.- Since:
- 1.3
- See Also:
OpenTest4JAwareThrowableCollector
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceThrowableCollector.ExecutableFunctional interface for an executable block of code that may throw aThrowable.static interfaceThrowableCollector.FactoryFactory forThrowableCollectorinstances.
-
Constructor Summary
Constructors Constructor Description ThrowableCollector(Predicate<? super Throwable> abortedExecutionPredicate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertEmpty()Assert that thisThrowableCollectoris empty (i.e., has not collected anyThrowables).voidexecute(ThrowableCollector.Executable executable)Execute the suppliedThrowableCollector.Executableand collect anyThrowablethrown during the execution.ThrowablegetThrowable()Get the firstThrowablecollected by thisThrowableCollector.booleanisEmpty()Determine if thisThrowableCollectoris empty (i.e., has not collected anyThrowables).booleanisNotEmpty()Determine if thisThrowableCollectoris not empty (i.e., has collected at least oneThrowable).
-
-
-
Constructor Detail
-
ThrowableCollector
public ThrowableCollector(Predicate<? super Throwable> abortedExecutionPredicate)
Create a newThrowableCollectorthat uses the suppliedPredicateto determine whether aThrowableaborted or failed execution.- Parameters:
abortedExecutionPredicate- the predicate used to decide whether aThrowableaborted execution; nevernull.
-
-
Method Detail
-
execute
public void execute(ThrowableCollector.Executable executable)
Execute the suppliedThrowableCollector.Executableand collect anyThrowablethrown during the execution.If the
Executablethrows a blacklisted exception — for example, anOutOfMemoryError— this method will rethrow it.- Parameters:
executable- theExecutableto execute- See Also:
assertEmpty()
-
getThrowable
public Throwable 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(),assertEmpty()
-
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.
-
-