Top Description Fields Constructors Methods
org.assertj.core.error

public Class ShouldBeEqual

extends Object
implements AssertionErrorFactory
Class Inheritance
All Implemented Interfaces
org.assertj.core.error.AssertionErrorFactory
Static Imports
java.lang.String.format, .System.lineSeparator, java.util.Objects.deepEquals, org.assertj.core.util.Arrays.array, .Objects.HASH_CODE_PRIME, .Objects.hashCodeFor

Deprecated

as a consequence of AssertionErrorFactory being deprecated. See corresponding docs for further information.

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).

Authors
Alex Ruiz, Yvonne Wang, Joel Costigliola

Field Summary

Modifier and TypeField and Description
protected final Object
protected final ComparisonStrategy
pack-priv ConstructorInvoker
pack-priv DescriptionFormatter
protected final Object
private static final String
private static final String
protected final MessageFormatter
private static final Class<?>[]
private static final Class<?>[]
private Representation

Constructor Summary

AccessConstructor and Description
protected
ShouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation)

Method Summary

Modifier and TypeMethod and Description
protected boolean
private AssertionError
assertionFailedError(String message, Representation representation)

private AssertionError
protected String

Returns:

the error message from description using detailedExpected() and detailedActual() detailed representation.
defaultDetailedErrorMessage
(Description
the Description used to build the returned error message
description
,
Representation
the org.assertj.core.presentation.Representation used to build String representation of object
representation
)

Builds and returns an error message from description using detailedExpected() and detailedActual() detailed representation.

protected String
protected String
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private String
errorMessageForMultilineValues(Description description, Representation representation, String actualRepresentation, String expectedRepresentation)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
private boolean
hasMultilineValue(String actualRepresentation, String expectedRepresentation)

protected String
indent(String valueRepresentation)

private String
messageForMultilineValues(String actualRepresentation, String expectedRepresentation, Representation representation)

public AssertionError

Returns:

the created AssertionError.
newAssertionError
(Description
the description of the failed assertion.
description
,
Representation
the Representation used to format values.
representation
)

Implements org.assertj.core.error.AssertionErrorFactory.newAssertionError.

Creates an AssertionError indicating that an assertion that verifies that two objects are equal failed.
private AssertionError
public static AssertionErrorFactory

Returns:

the created AssertionErrorFactory.
shouldBeEqual
(Object
the actual value in the failed assertion.
actual
,
Object
the expected value in the failed assertion.
expected
,
Representation
the Representation used to format values.
representation
)

Deprecated as a consequence of AssertionErrorFactory being deprecated.
Creates a new ShouldBeEqual.
public static AssertionErrorFactory

Returns:

the created AssertionErrorFactory.
shouldBeEqual
(Object
the actual value in the failed assertion.
actual
,
Object
the expected value in the failed assertion.
expected
,
ComparisonStrategy
the ComparisonStrategy used to compare actual with expected.
comparisonStrategy
,
Representation
the Representation used to format values.
representation
)

Deprecated as a consequence of AssertionErrorFactory being deprecated.
Creates a new ShouldBeEqual.
protected String

Returns:

the error message from description using expected and actual "smart" representation.
smartErrorMessage
(Description
the Description used to build the returned error message
description
,
Representation
the org.assertj.core.presentation.Representation used to build String representation of object
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.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

actualback to summary
protected final Object actual
comparisonStrategyback to summary
protected final ComparisonStrategy comparisonStrategy
constructorInvokerback to summary
pack-priv ConstructorInvoker constructorInvoker
Annotations
@VisibleForTesting
descriptionFormatterback to summary
pack-priv DescriptionFormatter descriptionFormatter
Annotations
@VisibleForTesting
expectedback to summary
protected final Object expected
EXPECTED_BUT_WAS_MESSAGEback to summary
private static final String EXPECTED_BUT_WAS_MESSAGE
EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATORback to summary
private static final String EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR
messageFormatterback to summary
protected final MessageFormatter messageFormatter
MSG_ARG_TYPESback to summary
private static final Class<?>[] MSG_ARG_TYPES
MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERRORback to summary
private static final Class<?>[] MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR
representationback to summary
private Representation representation

Constructor Detail

ShouldBeEqualback to summary
protected ShouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation)

Method Detail

actualAndExpectedHaveSameStringRepresentationback to summary
protected boolean actualAndExpectedHaveSameStringRepresentation()
assertionFailedErrorback to summary
private AssertionError assertionFailedError(String message, Representation representation)
comparisonFailureback to summary
private AssertionError comparisonFailure(Description description)
defaultDetailedErrorMessageback to summary
protected String defaultDetailedErrorMessage(Description description, Representation representation)

Builds and returns an error message from description using detailedExpected() and detailedActual() detailed representation.

Parameters
description:Description

the Description used to build the returned error message

representation:Representation

the org.assertj.core.presentation.Representation used to build String representation of object

Returns:String

the error message from description using detailedExpected() and detailedActual() detailed representation.

detailedActualback to summary
protected String detailedActual()
detailedExpectedback to summary
protected String detailedExpected()
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
errorMessageForMultilineValuesback to summary
private String errorMessageForMultilineValues(Description description, Representation representation, String actualRepresentation, String expectedRepresentation)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
hasMultilineValueback to summary
private boolean hasMultilineValue(String actualRepresentation, String expectedRepresentation)
indentback to summary
protected String indent(String valueRepresentation)
messageForMultilineValuesback to summary
private String messageForMultilineValues(String actualRepresentation, String expectedRepresentation, Representation representation)
newAssertionErrorback to summary
public AssertionError newAssertionError(Description description, Representation representation)

Implements org.assertj.core.error.AssertionErrorFactory.newAssertionError.

Creates an AssertionError indicating that an assertion that verifies that two objects are equal failed.
The 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)).
Parameters
description:Description

the description of the failed assertion.

representation:Representation

the Representation used to format values.

Returns:AssertionError

the created AssertionError.

Annotations
@Override
newComparisonFailureback to summary
private AssertionError newComparisonFailure(String description) throws Exception
shouldBeEqualback to summary
public static AssertionErrorFactory shouldBeEqual(Object actual, Object expected, Representation representation)

Deprecated

as a consequence of AssertionErrorFactory being deprecated. See corresponding docs for further information.

Creates a new ShouldBeEqual.

Parameters
actual:Object

the actual value in the failed assertion.

expected:Object

the expected value in the failed assertion.

representation:Representation

the Representation used to format values.

Returns:AssertionErrorFactory

the created AssertionErrorFactory.

shouldBeEqualback to summary
public static AssertionErrorFactory shouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy, Representation representation)

Deprecated

as a consequence of AssertionErrorFactory being deprecated. See corresponding docs for further information.

Creates a new ShouldBeEqual.

Parameters
actual:Object

the actual value in the failed assertion.

expected:Object

the expected value in the failed assertion.

comparisonStrategy:ComparisonStrategy

the ComparisonStrategy used to compare actual with expected.

representation:Representation

the Representation used to format values.

Returns:AssertionErrorFactory

the created AssertionErrorFactory.

smartErrorMessageback to summary
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.

Parameters
description:Description

the Description used to build the returned error message

representation:Representation

the org.assertj.core.presentation.Representation used to build String representation of object

Returns:String

the error message from description using expected and actual "smart" representation.