类 ExceptionCollector
ExceptionCollector is a test utility for executing code blocks,
collecting exceptions, and generating a single AssertionError
containing any exceptions encountered as suppressed exceptions.
This utility is intended to support soft assertion use cases
similar to the SoftAssertions support in AssertJ and the
assertAll() support in JUnit Jupiter.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen
-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceExecutableis a functional interface that can be used to implement any generic block of code that potentially throws aThrowable. -
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidAssert that thisExceptionCollectordoes not contain any exceptions.voidexecute(ExceptionCollector.Executable executable) Execute the suppliedExceptionCollector.Executableand track any exception thrown.Get the list of exceptions encountered inexecute(Executable).
-
字段详细资料
-
exceptions
-
-
构造器详细资料
-
ExceptionCollector
public ExceptionCollector()
-
-
方法详细资料
-
execute
Execute the suppliedExceptionCollector.Executableand track any exception thrown.- 参数:
executable- theExecutableto execute- 另请参阅:
-
getExceptions
Get the list of exceptions encountered inexecute(Executable).- 返回:
- an unmodifiable copy of the list of exceptions, potentially empty
- 另请参阅:
-
assertEmpty
Assert that thisExceptionCollectordoes not contain any exceptions.If this collector is empty, this method is effectively a no-op.
If this collector contains a single
ErrororException, this method rethrows the error or exception.If this collector contains a single
Throwable, this method throws anAssertionErrorwith the error message of theThrowableand with theThrowableas the cause.If this collector contains multiple exceptions, this method throws an
AssertionErrorwhose message is "Multiple Exceptions (#):" followed by a new line with the error message of each exception separated by a new line, with#replaced with the number of exceptions present. In addition, each exception will be added to theAssertionErroras asuppressed exception.- 抛出:
Exception- 另请参阅:
-