Package org.assertj.core.error
Class ShouldBeEqual
- java.lang.Object
-
- org.assertj.core.error.ShouldBeEqual
-
- All Implemented Interfaces:
AssertionErrorFactory
public class ShouldBeEqual extends Object implements AssertionErrorFactory
Creates an
indicating that an assertion that verifies that two objects are equal failed.AssertionError
The built
AssertionError
's message differentiatesactual
andexpected
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).- Author:
- Alex Ruiz, Yvonne Wang, Joel Costigliola
-
-
Field Summary
Fields Modifier and Type Field Description protected Object
actual
protected org.assertj.core.internal.ComparisonStrategy
comparisonStrategy
(package private) ConstructorInvoker
constructorInvoker
(package private) DescriptionFormatter
descriptionFormatter
protected Object
expected
private static String
EXPECTED_BUT_WAS_MESSAGE
private static String
EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR
protected MessageFormatter
messageFormatter
private static Class<?>[]
MSG_ARG_TYPES
private static Class<?>[]
MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR
private Representation
representation
-
Constructor Summary
Constructors Modifier Constructor Description protected
ShouldBeEqual(Object actual, Object expected, org.assertj.core.internal.ComparisonStrategy comparisonStrategy, Representation representation)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
actualAndExpectedHaveSameStringRepresentation()
private AssertionError
assertionFailedError(String message, Representation representation)
private AssertionError
comparisonFailure(Description description)
protected String
defaultDetailedErrorMessage(Description description, Representation representation)
Builds and returns an error message from description usingdetailedExpected()
anddetailedActual()
detailed representation.protected String
detailedActual()
protected String
detailedExpected()
boolean
equals(Object o)
private String
errorMessageForMultilineValues(Description description, Representation representation, String actualRepresentation, String expectedRepresentation)
int
hashCode()
private boolean
hasMultilineValue(String actualRepresentation, String expectedRepresentation)
protected String
indent(String valueRepresentation)
private String
messageForMultilineValues(String actualRepresentation, String expectedRepresentation, Representation representation)
AssertionError
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, org.assertj.core.internal.ComparisonStrategy comparisonStrategy, Representation representation)
Creates a new
.ShouldBeEqual
static AssertionErrorFactory
shouldBeEqual(Object actual, Object expected, Representation representation)
Creates a new
.ShouldBeEqual
protected String
smartErrorMessage(Description description, Representation representation)
Builds and returns an error message from the given description usingexpected
andactual
basic representation if their description differ otherwise usedefaultDetailedErrorMessage(Description, Representation)
to represent them differently.
-
-
-
Field Detail
-
EXPECTED_BUT_WAS_MESSAGE
private static final String EXPECTED_BUT_WAS_MESSAGE
- See Also:
- Constant Field Values
-
EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR
private static final String EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR
- See Also:
- Constant Field Values
-
MSG_ARG_TYPES
private static final Class<?>[] MSG_ARG_TYPES
-
MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR
private static final Class<?>[] MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR
-
actual
protected final Object actual
-
expected
protected final Object expected
-
messageFormatter
protected final MessageFormatter messageFormatter
-
comparisonStrategy
protected final org.assertj.core.internal.ComparisonStrategy comparisonStrategy
-
representation
private Representation representation
-
constructorInvoker
ConstructorInvoker constructorInvoker
-
descriptionFormatter
DescriptionFormatter descriptionFormatter
-
-
Constructor Detail
-
ShouldBeEqual
protected ShouldBeEqual(Object actual, Object expected, org.assertj.core.internal.ComparisonStrategy comparisonStrategy, Representation representation)
-
-
Method Detail
-
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.representation
- theRepresentation
used to format values.- Returns:
- the created
AssertionErrorFactory
.
-
shouldBeEqual
public static AssertionErrorFactory shouldBeEqual(Object actual, Object expected, org.assertj.core.internal.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.representation
- theRepresentation
used to format values.- Returns:
- the created
AssertionErrorFactory
.
-
newAssertionError
public AssertionError 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).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.If opentest4j is on the classpath then
org.opentest4j.AssertionFailedError
would be used.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
- theRepresentation
used to format values.- Returns:
- the created
AssertionError
.
-
actualAndExpectedHaveSameStringRepresentation
protected boolean actualAndExpectedHaveSameStringRepresentation()
-
smartErrorMessage
protected String smartErrorMessage(Description description, Representation representation)
Builds and returns an error message from the given description usingexpected
andactual
basic representation if their description differ otherwise usedefaultDetailedErrorMessage(Description, Representation)
to represent them differently.- 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
"smart" representation.
-
errorMessageForMultilineValues
private String errorMessageForMultilineValues(Description description, Representation representation, String actualRepresentation, String expectedRepresentation)
-
hasMultilineValue
private boolean hasMultilineValue(String actualRepresentation, String expectedRepresentation)
-
messageForMultilineValues
private String messageForMultilineValues(String actualRepresentation, String expectedRepresentation, Representation representation)
-
defaultDetailedErrorMessage
protected String defaultDetailedErrorMessage(Description description, Representation representation)
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.
-
assertionFailedError
private AssertionError assertionFailedError(String message, Representation representation)
-
comparisonFailure
private AssertionError comparisonFailure(Description description)
-
newComparisonFailure
private AssertionError newComparisonFailure(String description) throws Exception
- Throws:
Exception
-
detailedActual
protected String detailedActual()
-
detailedExpected
protected String detailedExpected()
-
-