public class ShouldBeEqual extends java.lang.Object implements AssertionErrorFactory
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).
Modifier and Type | Field and Description |
---|---|
protected java.lang.Object |
actual |
private ComparisonStrategy |
comparisonStrategy |
(package private) ConstructorInvoker |
constructorInvoker |
(package private) DescriptionFormatter |
descriptionFormatter |
protected java.lang.Object |
expected |
private static java.lang.String |
EXPECTED_BUT_WAS_MESSAGE |
private static java.lang.String |
EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR |
(package private) MessageFormatter |
messageFormatter |
private static java.lang.Class<?>[] |
MSG_ARG_TYPES |
private Representation |
representation |
Constructor and Description |
---|
ShouldBeEqual(java.lang.Object actual,
java.lang.Object expected,
ComparisonStrategy comparisonStrategy,
Representation representation) |
Modifier and Type | Method and Description |
---|---|
private boolean |
actualAndExpectedHaveSameStringRepresentation() |
private java.lang.AssertionError |
comparisonFailure(Description description) |
private java.lang.String |
defaultDetailedErrorMessage(Description description,
Representation representation)
Builds and returns an error message from description using
detailedExpected() and
detailedActual() detailed representation. |
private java.lang.String |
defaultErrorMessage(Description description,
Representation representation)
|
private java.lang.String |
detailedActual() |
private java.lang.String |
detailedExpected() |
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
private java.lang.Object[] |
msgArgs(java.lang.String description) |
java.lang.AssertionError |
newAssertionError(Description description,
Representation representation)
|
private java.lang.AssertionError |
newComparisonFailure(java.lang.String description) |
static AssertionErrorFactory |
shouldBeEqual(java.lang.Object actual,
java.lang.Object expected,
ComparisonStrategy comparisonStrategy,
Representation representation)
Creates a new
. |
static AssertionErrorFactory |
shouldBeEqual(java.lang.Object actual,
java.lang.Object expected,
Representation representation)
Creates a new
. |
private static final java.lang.String EXPECTED_BUT_WAS_MESSAGE
private static final java.lang.String EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR
private static final java.lang.Class<?>[] MSG_ARG_TYPES
protected final java.lang.Object actual
protected final java.lang.Object expected
final MessageFormatter messageFormatter
private final ComparisonStrategy comparisonStrategy
private Representation representation
ConstructorInvoker constructorInvoker
DescriptionFormatter descriptionFormatter
ShouldBeEqual(java.lang.Object actual, java.lang.Object expected, ComparisonStrategy comparisonStrategy, Representation representation)
public static AssertionErrorFactory shouldBeEqual(java.lang.Object actual, java.lang.Object expected, Representation representation)
ShouldBeEqual
.actual
- the actual value in the failed assertion.expected
- the expected value in the failed assertion.AssertionErrorFactory
.public static AssertionErrorFactory shouldBeEqual(java.lang.Object actual, java.lang.Object expected, ComparisonStrategy comparisonStrategy, Representation representation)
ShouldBeEqual
.actual
- the actual value in the failed assertion.expected
- the expected value in the failed assertion.comparisonStrategy
- the ComparisonStrategy
used to compare actual with expected.AssertionErrorFactory
.public java.lang.AssertionError newAssertionError(Description description, Representation representation)
AssertionError
indicating that an assertion that verifies that two objects are
equal failed.AssertionError
message is built so that it differentiates actual
and
expected
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
and
expected
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 if Failures
is configured to filter
them (see Failures.setRemoveAssertJRelatedElementsFromStackTrace(boolean)
).newAssertionError
in interface AssertionErrorFactory
description
- the description of the failed assertion.representation
- AssertionError
.private boolean actualAndExpectedHaveSameStringRepresentation()
private java.lang.String defaultErrorMessage(Description description, Representation representation)
expected
and actual
basic
representation.description
- the Description
used to build the returned error messagerepresentation
- the Representation
used to build String representation
of objectexpected
and actual
basic representation.private java.lang.String defaultDetailedErrorMessage(Description description, Representation representation)
detailedExpected()
and
detailedActual()
detailed representation.description
- the Description
used to build the returned error messagerepresentation
- the Representation
used to build String representation
of objectdetailedExpected()
and detailedActual()
detailed representation.private java.lang.AssertionError comparisonFailure(Description description)
private java.lang.AssertionError newComparisonFailure(java.lang.String description) throws java.lang.Exception
java.lang.Exception
private java.lang.Object[] msgArgs(java.lang.String description)
private java.lang.String detailedActual()
private java.lang.String detailedExpected()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object