@API(status=STABLE,
since="5.9")
public class AssertionFailureBuilder
extends java.lang.Object
AssertionFailedErrors.
Using this builder ensures consistency in how failure message are formatted within JUnit Jupiter and for custom user-defined assertions.
AssertionFailedError| Modifier and Type | Field and Description |
|---|---|
private java.lang.Object |
actual |
private java.lang.Throwable |
cause |
private java.lang.Object |
expected |
private boolean |
includeValuesInMessage |
private java.lang.Object |
message |
private boolean |
mismatch |
private java.lang.String |
reason |
| Modifier | Constructor and Description |
|---|---|
private |
AssertionFailureBuilder() |
| Modifier and Type | Method and Description |
|---|---|
AssertionFailureBuilder |
actual(java.lang.Object actual)
Set the actual value of the assertion.
|
static AssertionFailureBuilder |
assertionFailure()
Create a new
AssertionFailureBuilder. |
org.opentest4j.AssertionFailedError |
build()
Build the
AssertionFailedError without
throwing it. |
void |
buildAndThrow()
Build the
AssertionFailedError and throw it. |
private static java.lang.String |
buildPrefix(java.lang.String message) |
AssertionFailureBuilder |
cause(java.lang.Throwable cause)
Set the cause of the assertion failure.
|
AssertionFailureBuilder |
expected(java.lang.Object expected)
Set the expected value of the assertion.
|
private static java.lang.String |
formatClassAndValue(java.lang.Object value,
java.lang.String valueString) |
private static java.lang.String |
formatValues(java.lang.Object expected,
java.lang.Object actual) |
private static java.lang.String |
getClassName(java.lang.Object obj) |
AssertionFailureBuilder |
includeValuesInMessage(boolean includeValuesInMessage)
Set whether to include the actual and expected values in the generated
failure message.
|
AssertionFailureBuilder |
message(java.lang.Object message)
Set the user-defined message of the assertion.
|
private static java.lang.String |
nullSafeGet(java.lang.Object messageOrSupplier) |
AssertionFailureBuilder |
reason(java.lang.String reason)
Set the reason why the assertion failed.
|
private static java.lang.String |
toHash(java.lang.Object obj) |
private static java.lang.String |
toString(java.lang.Object obj) |
private java.lang.Object message
private java.lang.Throwable cause
private boolean mismatch
private java.lang.Object expected
private java.lang.Object actual
private java.lang.String reason
private boolean includeValuesInMessage
public static AssertionFailureBuilder assertionFailure()
AssertionFailureBuilder.public AssertionFailureBuilder message(java.lang.Object message)
The message may be passed as a Supplier or plain
String. If any other type is passed, it is converted to
String as per StringUtils.nullSafeToString(Object).
message - the user-defined failure message; may be nullpublic AssertionFailureBuilder reason(java.lang.String reason)
reason - the failure reason; may be nullpublic AssertionFailureBuilder cause(java.lang.Throwable cause)
cause - the failure cause; may be nullpublic AssertionFailureBuilder expected(java.lang.Object expected)
expected - the expected value; may be nullpublic AssertionFailureBuilder actual(java.lang.Object actual)
actual - the actual value; may be nullpublic AssertionFailureBuilder includeValuesInMessage(boolean includeValuesInMessage)
includeValuesInMessage - whether to include the actual and expected
valuespublic void buildAndThrow()
throws org.opentest4j.AssertionFailedError
AssertionFailedError and throw it.org.opentest4j.AssertionFailedError - alwayspublic org.opentest4j.AssertionFailedError build()
AssertionFailedError without
throwing it.private static java.lang.String nullSafeGet(java.lang.Object messageOrSupplier)
private static java.lang.String buildPrefix(java.lang.String message)
private static java.lang.String formatValues(java.lang.Object expected,
java.lang.Object actual)
private static java.lang.String formatClassAndValue(java.lang.Object value,
java.lang.String valueString)
private static java.lang.String toString(java.lang.Object obj)
private static java.lang.String toHash(java.lang.Object obj)
private static java.lang.String getClassName(java.lang.Object obj)