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).
- Author:
- Alex Ruiz, Yvonne Wang, Joel Costigliola
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Objectprotected final ComparisonStrategyprotected final Objectprotected final MessageFormatter -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedShouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected StringdefaultDetailedErrorMessage(Description description, Representation representation) Builds and returns an error message from description usingdetailedExpected()anddetailedActual()detailed representation.protected Stringprotected StringbooleaninthashCode()protected StringnewAssertionError(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).static AssertionErrorFactoryshouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation) Creates a new.ShouldBeEqualstatic AssertionErrorFactoryshouldBeEqual(Object actual, Object expected, Representation representation) Creates a new.ShouldBeEqualprotected 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 Details
-
actual
-
expected
-
messageFormatter
-
comparisonStrategy
-
-
Constructor Details
-
ShouldBeEqual
protected 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.representation- theRepresentationused to format values.- 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- theComparisonStrategyused to compare actual with expected.representation- theRepresentationused to format values.- Returns:
- the created
AssertionErrorFactory.
-
newAssertionError
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
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.
-
indent
-
defaultDetailedErrorMessage
protected 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.
-
detailedActual
-
detailedExpected
-
equals
-
hashCode
public int hashCode()
-