public class ShouldBeEqual extends 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 Object |
actual |
protected ComparisonStrategy |
comparisonStrategy |
protected Object |
expected |
protected MessageFormatter |
messageFormatter |
| Modifier | Constructor and Description |
|---|---|
protected |
ShouldBeEqual(Object actual,
Object expected,
ComparisonStrategy comparisonStrategy,
Representation representation) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
actualAndExpectedHaveSameStringRepresentation() |
protected String |
defaultDetailedErrorMessage(Description description,
Representation representation)
Builds and returns an error message from description using
detailedExpected() and
detailedActual() detailed representation. |
protected String |
detailedActual() |
protected String |
detailedExpected() |
boolean |
equals(Object o) |
int |
hashCode() |
protected String |
indent(String valueRepresentation) |
AssertionError |
newAssertionError(Description description,
Representation representation)
Creates an
indicating that an assertion that verifies that two objects are
equal failed.The 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). |
static AssertionErrorFactory |
shouldBeEqual(Object actual,
Object expected,
ComparisonStrategy comparisonStrategy,
Representation representation)
Creates a new
. |
static AssertionErrorFactory |
shouldBeEqual(Object actual,
Object expected,
Representation representation)
Creates a new
. |
protected String |
smartErrorMessage(Description description,
Representation representation)
Builds and returns an error message from the given description using
expected and actual basic
representation if their description differ otherwise use
defaultDetailedErrorMessage(Description, Representation) to represent them differently. |
protected final Object actual
protected final Object expected
protected final MessageFormatter messageFormatter
protected final ComparisonStrategy comparisonStrategy
protected ShouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation)
public static AssertionErrorFactory shouldBeEqual(Object actual, Object expected, Representation representation)
ShouldBeEqual.actual - the actual value in the failed assertion.expected - the expected value in the failed assertion.representation - the Representation used to format values.AssertionErrorFactory.public static AssertionErrorFactory shouldBeEqual(Object actual, 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.representation - the Representation used to format values.AssertionErrorFactory.public 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.
If opentest4j is on the classpath then org.opentest4j.AssertionFailedError would be used.
AssertionError stack trace won't show AssertJ related elements if Failures is configured to filter
them (see Failures.setRemoveAssertJRelatedElementsFromStackTrace(boolean)).newAssertionError in interface AssertionErrorFactorydescription - the description of the failed assertion.representation - the Representation used to format values.AssertionError.protected boolean actualAndExpectedHaveSameStringRepresentation()
protected String smartErrorMessage(Description description, Representation representation)
expected and actual basic
representation if their description differ otherwise use
defaultDetailedErrorMessage(Description, Representation) to represent them differently.description - the Description used to build the returned error messagerepresentation - the Representation used to build String representation
of objectexpected and actual "smart" representation.protected 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.protected String detailedActual()
protected String detailedExpected()
Copyright © 2025. All rights reserved.