Package org.assertj.core.error
Class ShouldBeEqual
- java.lang.Object
-
- org.assertj.core.error.ShouldBeEqual
-
- All Implemented Interfaces:
AssertionErrorFactory
public class ShouldBeEqual extends java.lang.Object implements AssertionErrorFactory
Creates anindicating that an assertion that verifies that two objects are equal failed.AssertionErrorThe built
AssertionError's message differentiatesactualandexpecteddescription 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
Fields Modifier and Type Field Description protected java.lang.Objectactualprotected ComparisonStrategycomparisonStrategy(package private) ConstructorInvokerconstructorInvoker(package private) DescriptionFormatterdescriptionFormatterprotected java.lang.Objectexpectedprivate static java.lang.StringEXPECTED_BUT_WAS_MESSAGEprivate static java.lang.StringEXPECTED_BUT_WAS_MESSAGE_USING_COMPARATORprotected MessageFormattermessageFormatterprivate static java.lang.Class<?>[]MSG_ARG_TYPESprivate static java.lang.Class<?>[]MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERRORprivate Representationrepresentation
-
Constructor Summary
Constructors Modifier Constructor Description protectedShouldBeEqual(java.lang.Object actual, java.lang.Object expected, ComparisonStrategy comparisonStrategy, Representation representation)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanactualAndExpectedHaveSameStringRepresentation()private java.lang.AssertionErrorassertionFailedError(java.lang.String message, Representation representation)private java.lang.AssertionErrorcomparisonFailure(Description description)protected java.lang.StringdefaultDetailedErrorMessage(Description description, Representation representation)Builds and returns an error message from description usingdetailedExpected()anddetailedActual()detailed representation.protected java.lang.StringdetailedActual()protected java.lang.StringdetailedExpected()booleanequals(java.lang.Object o)private java.lang.StringerrorMessageForMultilineValues(Description description, Representation representation, java.lang.String actualRepresentation, java.lang.String expectedRepresentation)inthashCode()private booleanhasMultilineValue(java.lang.String actualRepresentation, java.lang.String expectedRepresentation)protected java.lang.Stringindent(java.lang.String valueRepresentation)private java.lang.StringmessageForMultilineValues(java.lang.String actualRepresentation, java.lang.String expectedRepresentation, Representation representation)java.lang.AssertionErrornewAssertionError(Description description, Representation representation)private java.lang.AssertionErrornewComparisonFailure(java.lang.String description)static AssertionErrorFactoryshouldBeEqual(java.lang.Object actual, java.lang.Object expected, ComparisonStrategy comparisonStrategy, Representation representation)Creates a new.ShouldBeEqualstatic AssertionErrorFactoryshouldBeEqual(java.lang.Object actual, java.lang.Object expected, Representation representation)Creates a new.ShouldBeEqualprotected java.lang.StringsmartErrorMessage(Description description, Representation representation)Builds and returns an error message from the given description usingexpectedandactualbasic representation if their description differ otherwise usedefaultDetailedErrorMessage(Description, Representation)to represent them differently.
-
-
-
Field Detail
-
EXPECTED_BUT_WAS_MESSAGE
private static final java.lang.String EXPECTED_BUT_WAS_MESSAGE
- See Also:
- Constant Field Values
-
EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR
private static final java.lang.String EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR
- See Also:
- Constant Field Values
-
MSG_ARG_TYPES
private static final java.lang.Class<?>[] MSG_ARG_TYPES
-
MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR
private static final java.lang.Class<?>[] MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR
-
actual
protected final java.lang.Object actual
-
expected
protected final java.lang.Object expected
-
messageFormatter
protected final MessageFormatter messageFormatter
-
comparisonStrategy
protected final ComparisonStrategy comparisonStrategy
-
representation
private Representation representation
-
constructorInvoker
ConstructorInvoker constructorInvoker
-
descriptionFormatter
DescriptionFormatter descriptionFormatter
-
-
Constructor Detail
-
ShouldBeEqual
protected ShouldBeEqual(java.lang.Object actual, java.lang.Object expected, ComparisonStrategy comparisonStrategy, Representation representation)
-
-
Method Detail
-
shouldBeEqual
public static AssertionErrorFactory shouldBeEqual(java.lang.Object actual, java.lang.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- theRepresentationused to format values.- Returns:
- the created
AssertionErrorFactory.
-
shouldBeEqual
public static AssertionErrorFactory shouldBeEqual(java.lang.Object actual, java.lang.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- theComparisonStrategyused to compare actual with expected.representation- theRepresentationused to format values.- Returns:
- the created
AssertionErrorFactory.
-
newAssertionError
public java.lang.AssertionError newAssertionError(Description description, Representation representation)
Creates anindicating that an assertion that verifies that two objects are equal failed.AssertionError
Themessage is built so that it differentiatesAssertionErroractualandexpecteddescription 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
actualandexpectedstring 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.AssertionFailedErrorwould be used.AssertionErrorstack trace won't show AssertJ related elements ifFailuresis configured to filter them (seeFailures.setRemoveAssertJRelatedElementsFromStackTrace(boolean)).- Specified by:
newAssertionErrorin interfaceAssertionErrorFactory- Parameters:
description- the description of the failed assertion.representation- theRepresentationused to format values.- Returns:
- the created
AssertionError.
-
actualAndExpectedHaveSameStringRepresentation
protected boolean actualAndExpectedHaveSameStringRepresentation()
-
smartErrorMessage
protected java.lang.String smartErrorMessage(Description description, Representation representation)
Builds and returns an error message from the given description usingexpectedandactualbasic representation if their description differ otherwise usedefaultDetailedErrorMessage(Description, Representation)to represent them differently.- Parameters:
description- theDescriptionused to build the returned error messagerepresentation- theRepresentationused to build String representation of object- Returns:
- the error message from description using
expectedandactual"smart" representation.
-
errorMessageForMultilineValues
private java.lang.String errorMessageForMultilineValues(Description description, Representation representation, java.lang.String actualRepresentation, java.lang.String expectedRepresentation)
-
hasMultilineValue
private boolean hasMultilineValue(java.lang.String actualRepresentation, java.lang.String expectedRepresentation)
-
messageForMultilineValues
private java.lang.String messageForMultilineValues(java.lang.String actualRepresentation, java.lang.String expectedRepresentation, Representation representation)
-
indent
protected java.lang.String indent(java.lang.String valueRepresentation)
-
defaultDetailedErrorMessage
protected java.lang.String defaultDetailedErrorMessage(Description description, Representation representation)
Builds and returns an error message from description usingdetailedExpected()anddetailedActual()detailed representation.- Parameters:
description- theDescriptionused to build the returned error messagerepresentation- theRepresentationused to build String representation of object- Returns:
- the error message from description using
detailedExpected()anddetailedActual()detailed representation.
-
assertionFailedError
private java.lang.AssertionError assertionFailedError(java.lang.String message, Representation representation)
-
comparisonFailure
private java.lang.AssertionError comparisonFailure(Description description)
-
newComparisonFailure
private java.lang.AssertionError newComparisonFailure(java.lang.String description) throws java.lang.Exception- Throws:
java.lang.Exception
-
detailedActual
protected java.lang.String detailedActual()
-
detailedExpected
protected java.lang.String detailedExpected()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-