- java.lang.Object
-
- org.junit.jupiter.api.AssertionFailureBuilder
-
@API(status=STABLE, since="5.9") public class AssertionFailureBuilder extends java.lang.Object
Builder forAssertionFailedErrors
.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
-
-
Constructor Summary
Constructors Modifier Constructor Description private
AssertionFailureBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AssertionFailureBuilder
actual(java.lang.Object actual)
Set the actual value of the assertion.static AssertionFailureBuilder
assertionFailure()
Create a newAssertionFailureBuilder
.org.opentest4j.AssertionFailedError
build()
Build theAssertionFailedError
without throwing it.void
buildAndThrow()
Build theAssertionFailedError
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)
-
-
-
Field Detail
-
message
private java.lang.Object message
-
cause
private java.lang.Throwable cause
-
mismatch
private boolean mismatch
-
expected
private java.lang.Object expected
-
actual
private java.lang.Object actual
-
reason
private java.lang.String reason
-
includeValuesInMessage
private boolean includeValuesInMessage
-
-
Method Detail
-
assertionFailure
public static AssertionFailureBuilder assertionFailure()
Create a newAssertionFailureBuilder
.
-
message
public AssertionFailureBuilder message(java.lang.Object 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
public AssertionFailureBuilder reason(java.lang.String reason)
Set the reason why the assertion failed.- Parameters:
reason
- the failure reason; may benull
- Returns:
- this builder for method chaining
-
cause
public AssertionFailureBuilder cause(java.lang.Throwable cause)
Set the cause of the assertion failure.- Parameters:
cause
- the failure cause; may benull
- Returns:
- this builder for method chaining
-
expected
public AssertionFailureBuilder expected(java.lang.Object expected)
Set the expected value of the assertion.- Parameters:
expected
- the expected value; may benull
- Returns:
- this builder for method chaining
-
actual
public AssertionFailureBuilder actual(java.lang.Object actual)
Set the actual value of the assertion.- Parameters:
actual
- the actual value; may benull
- Returns:
- this builder for method chaining
-
includeValuesInMessage
public AssertionFailureBuilder includeValuesInMessage(boolean 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.AssertionFailedError
Build 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
private static java.lang.String nullSafeGet(java.lang.Object messageOrSupplier)
-
buildPrefix
private static java.lang.String buildPrefix(java.lang.String message)
-
formatValues
private static java.lang.String formatValues(java.lang.Object expected, java.lang.Object actual)
-
formatClassAndValue
private static java.lang.String formatClassAndValue(java.lang.Object value, java.lang.String valueString)
-
toString
private static java.lang.String toString(java.lang.Object obj)
-
toHash
private static java.lang.String toHash(java.lang.Object obj)
-
getClassName
private static java.lang.String getClassName(java.lang.Object obj)
-
-