Class AssertionFailureBuilder
java.lang.Object
org.junit.jupiter.api.AssertionFailureBuilder
-
Method Summary
Modifier and TypeMethodDescriptionSet the actual value of the assertion.static AssertionFailureBuilderCreate a newAssertionFailureBuilder.build()Build theAssertionFailedErrorwithout throwing it.voidBuild theAssertionFailedErrorand throw it.Set the cause of the assertion failure.Set the expected value of the assertion.includeValuesInMessage(boolean includeValuesInMessage) Set whether to include the actual and expected values in the generated failure message.Set the user-defined message of the assertion.Set the reason why the assertion failed.retainStackTraceElements(int retainStackTraceElements) Set depth to trim the stacktrace to.trimStacktrace(@Nullable Class<?> target) Set target to trim the stacktrace to.
-
Method Details
-
assertionFailure
Create a newAssertionFailureBuilder. -
message
Set the user-defined message of the assertion.The
messagemay be passed as aSupplieror plainString. If any other type is passed, it is converted toStringas perStringUtils.nullSafeToString(Object).- Parameters:
message- the user-defined failure message; may benull- Returns:
- this builder for method chaining
-
reason
Set the reason why the assertion failed.- Parameters:
reason- the failure reason; may benull- Returns:
- this builder for method chaining
-
cause
Set the cause of the assertion failure.- Parameters:
cause- the failure cause; may benull- Returns:
- this builder for method chaining
-
expected
Set the expected value of the assertion.- Parameters:
expected- the expected value; may benull- Returns:
- this builder for method chaining
-
actual
Set the actual value of the assertion.- Parameters:
actual- the actual value; may benull- Returns:
- this builder for method chaining
-
includeValuesInMessage
Set whether to include the actual and expected values in the generated failure message.- Parameters:
includeValuesInMessage- whether to include the actual and expected values- Returns:
- this builder for method chaining
-
trimStacktrace
@API(status=EXPERIMENTAL, since="6.1") public AssertionFailureBuilder trimStacktrace(@Nullable Class<?> target) Set target to trim the stacktrace to.Unless
retainStackTraceElements(int)is set all stacktrace elements before the last element fromtargetare trimmed.- Parameters:
target- class to trim from the stacktrace- Returns:
- this builder for method chaining
-
retainStackTraceElements
@API(status=EXPERIMENTAL, since="6.1") public AssertionFailureBuilder retainStackTraceElements(int retainStackTraceElements) Set depth to trim the stacktrace to. Defaults to 1.If
trimStacktrace(Class)was set, all butretainStackTraceElements - 1stacktrace elements before the last element fromtargetare removed. IfretainStackTraceElementsis zero, all elements including those fromtargetare trimmed.- Parameters:
retainStackTraceElements- depth of trimming, must be non-negative- Returns:
- this builder for method chaining
-
buildAndThrow
Build theAssertionFailedErrorand throw it.- Throws:
AssertionFailedError- always
-
build
Build theAssertionFailedErrorwithout throwing it.- Returns:
- the built assertion failure
-