Package org.assertj.core.error
Class ShouldBeEqual
java.lang.Object
org.assertj.core.error.ShouldBeEqual
- All Implemented Interfaces:
AssertionErrorFactory
Creates an
AssertionError
indicating that an assertion that verifies that two objects are equal
failed.
The built AssertionError
's message differentiates actual
and expected
description if their
string representation are the same (e.g. 42 float and 42 double). It also mentions the comparator in case of a custom
comparator is used (instead of equals method).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Object
private final ComparisonStrategy
(package private) ConstructorInvoker
(package private) DescriptionFormatter
protected final Object
private static final String
private static final String
(package private) final MessageFormatter
private static final Class<?>[]
private Representation
-
Constructor Summary
ConstructorsConstructorDescriptionShouldBeEqual
(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation) -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
private AssertionError
comparisonFailure
(Description description) private String
defaultDetailedErrorMessage
(Description description, Representation representation) Builds and returns an error message from description usingdetailedExpected()
anddetailedActual()
detailed representation.private String
defaultErrorMessage
(Description description, Representation representation) private String
private String
boolean
int
hashCode()
private Object[]
newAssertionError
(Description description, Representation representation) Creates an
indicating that an assertion that verifies that two objects are equal failed.AssertionError
The
message is built so that it differentiatesAssertionError
actual
andexpected
description in case their string representation are the same (like 42 float and 42 double).private AssertionError
newComparisonFailure
(String description) static AssertionErrorFactory
shouldBeEqual
(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation) Creates a new
.ShouldBeEqual
static AssertionErrorFactory
shouldBeEqual
(Object actual, Object expected, Representation representation) Creates a new
.ShouldBeEqual
-
Field Details
-
EXPECTED_BUT_WAS_MESSAGE
- See Also:
-
EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR
- See Also:
-
MSG_ARG_TYPES
-
actual
-
expected
-
messageFormatter
-
comparisonStrategy
-
representation
-
constructorInvoker
ConstructorInvoker constructorInvoker -
descriptionFormatter
DescriptionFormatter descriptionFormatter
-
-
Constructor Details
-
ShouldBeEqual
ShouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation)
-
-
Method Details
-
shouldBeEqual
public static AssertionErrorFactory shouldBeEqual(Object actual, Object expected, Representation representation) Creates a new
.ShouldBeEqual
- Parameters:
actual
- the actual value in the failed assertion.expected
- the expected value in the failed assertion.- Returns:
- the created
AssertionErrorFactory
.
-
shouldBeEqual
public static AssertionErrorFactory shouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation) Creates a new
.ShouldBeEqual
- Parameters:
actual
- the actual value in the failed assertion.expected
- the expected value in the failed assertion.comparisonStrategy
- theComparisonStrategy
used to compare actual with expected.- Returns:
- the created
AssertionErrorFactory
.
-
newAssertionError
Creates an
indicating that an assertion that verifies that two objects are equal failed.AssertionError
The
message is built so that it differentiatesAssertionError
actual
andexpected
description in case their string representation are the same (like 42 float and 42 double).If JUnit 4 is in the classpath and the description is standard (no comparator was used and
actual
andexpected
string representation were different), this method will instead create a org.junit.ComparisonFailure that highlights the difference(s) between the expected and actual objects.AssertionError
stack trace won't show AssertJ related elements ifFailures
is configured to filter them (seeFailures.setRemoveAssertJRelatedElementsFromStackTrace(boolean)
).- Specified by:
newAssertionError
in interfaceAssertionErrorFactory
- Parameters:
description
- the description of the failed assertion.representation
-- Returns:
- the created
AssertionError
.
-
actualAndExpectedHaveSameStringRepresentation
private boolean actualAndExpectedHaveSameStringRepresentation() -
defaultErrorMessage
Builds and returns an error message from description usingexpected
andactual
basic representation.- Parameters:
description
- theDescription
used to build the returned error messagerepresentation
- theRepresentation
used to build String representation of object- Returns:
- the error message from description using
expected
andactual
basic representation.
-
defaultDetailedErrorMessage
Builds and returns an error message from description usingdetailedExpected()
anddetailedActual()
detailed representation.- Parameters:
description
- theDescription
used to build the returned error messagerepresentation
- theRepresentation
used to build String representation of object- Returns:
- the error message from description using
detailedExpected()
anddetailedActual()
detailed representation.
-
comparisonFailure
-
newComparisonFailure
- Throws:
Exception
-
msgArgs
-
detailedActual
-
detailedExpected
-
equals
-
hashCode
public int hashCode()
-