Class ShouldBeEqual

java.lang.Object
org.fest.assertions.error.ShouldBeEqual
All Implemented Interfaces:
AssertionErrorFactory

public class ShouldBeEqual extends Object implements 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 Details

    • actual

      protected final Object actual
    • expected

      protected final Object expected
  • Method Details

    • shouldBeEqual

      public static AssertionErrorFactory shouldBeEqual(Object actual, Object expected)
      Creates a new ShouldBeEqual.
      Parameters:
      actual - the actual value in the failed assertion.
      expected - the expected value in the failed assertion.
      Returns:
      the created AssertionErrorFactory.
    • shouldBeEqual

      public static AssertionErrorFactory shouldBeEqual(Object actual, Object expected, ComparisonStrategy comparisonStrategy)
      Creates a new ShouldBeEqual.
      Parameters:
      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.
      Returns:
      the created AssertionErrorFactory.
    • newAssertionError

      public AssertionError newAssertionError(Description description)
      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 differents), this method will instead create a org.junit.ComparisonFailure that highlights the difference(s) between the expected and actual objects.

      AssertionError stack trace won't show Fest related elements if Failures is configured to filter them (see Failures.setRemoveFestRelatedElementsFromStackTrace(boolean)).
      Specified by:
      newAssertionError in interface AssertionErrorFactory
      Parameters:
      description - the description of the failed assertion.
      Returns:
      the created AssertionError.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object