java.lang.Object
org.junit.jupiter.api.AssertionFailureBuilder
Builder for
AssertionFailedErrors
.
Using this builder ensures consistency in how failure message are formatted within JUnit Jupiter and for custom user-defined assertions.
- Since:
- 5.9
- See Also:
-
AssertionFailedError
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSet the actual value of the assertion.static AssertionFailureBuilder
Create a newAssertionFailureBuilder
.org.opentest4j.AssertionFailedError
build()
Build theAssertionFailedError
without throwing it.void
Build theAssertionFailedError
and throw it.private static String
buildPrefix
(String message) Set the cause of the assertion failure.Set the expected value of the assertion.private static String
formatClassAndValue
(Object value, String valueString) private static String
formatValues
(Object expected, Object actual) private static String
getClassName
(Object obj) 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.private static String
nullSafeGet
(Object messageOrSupplier) Set the reason why the assertion failed.private static String
private static String
-
Field Details
-
message
-
cause
-
mismatch
private boolean mismatch -
expected
-
actual
-
reason
-
includeValuesInMessage
private boolean includeValuesInMessage
-
-
Constructor Details
-
AssertionFailureBuilder
private AssertionFailureBuilder()
-
-
Method Details
-
assertionFailure
Create a newAssertionFailureBuilder
. -
message
Set the user-defined message of the assertion.The
message
may be passed as aSupplier
or plainString
. If any other type is passed, it is converted toString
as 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
-
buildAndThrow
public void buildAndThrow() throws org.opentest4j.AssertionFailedErrorBuild theAssertionFailedError
and throw it.- Throws:
org.opentest4j.AssertionFailedError
- always
-
build
public org.opentest4j.AssertionFailedError build()Build theAssertionFailedError
without throwing it.- Returns:
- the built assertion failure
-
nullSafeGet
-
buildPrefix
-
formatValues
-
formatClassAndValue
-
toString
-
toHash
-
getClassName
-