Class AssertionFailedError

  • All Implemented Interfaces:
    Serializable

    public class AssertionFailedError
    extends AssertionError
    AssertionFailedError is a common base class for test-related AssertionErrors.

    In addition to a message and a cause, this class stores the expected and actual values of an assertion using the ValueWrapper type.

    Since:
    1.0
    Author:
    Sam Brannen, Marc Philipp
    See Also:
    Serialized Form
    • Constructor Detail

      • AssertionFailedError

        public AssertionFailedError()
        Constructs an AssertionFailedError with an empty message, no cause, and no expected/actual values.
      • AssertionFailedError

        public AssertionFailedError​(String message)
        Constructs an AssertionFailedError with a message, no cause, and no expected/actual values.
        Parameters:
        message - the detail message; null or blank will be converted to the empty String
      • AssertionFailedError

        public AssertionFailedError​(String message,
                                    Object expected,
                                    Object actual)
        Constructs an AssertionFailedError with a message and expected/actual values but without a cause.
        Parameters:
        message - the detail message; null or blank will be converted to the empty String
        expected - the expected value; may be null
        actual - the actual value; may be null
      • AssertionFailedError

        public AssertionFailedError​(String message,
                                    Throwable cause)
        Constructs an AssertionFailedError with a message and a cause but without expected/actual values.
        Parameters:
        message - the detail message; null or blank will be converted to the empty String
        cause - the cause of the failure
      • AssertionFailedError

        public AssertionFailedError​(String message,
                                    Object expected,
                                    Object actual,
                                    Throwable cause)
        Constructs an AssertionFailedError with a message, expected/actual values, and a cause.
        Parameters:
        message - the detail message; null or blank will be converted to the empty String
        expected - the expected value; may be null
        actual - the actual value; may be null
        cause - the cause of the failure
    • Method Detail

      • isExpectedDefined

        public boolean isExpectedDefined()
        Returns true if an expected value was supplied via an appropriate constructor.
        See Also:
        getExpected()
      • isActualDefined

        public boolean isActualDefined()
        Returns true if an actual value was supplied via an appropriate constructor.
        See Also:
        getActual()
      • toString

        public String toString()
        Returns a short description of this assertion error using the same format as Throwable.toString().

        Since the constructors of this class convert supplied null or blank messages to the empty String, this method only includes non-empty messages in its return value.

        Overrides:
        toString in class Throwable
        Returns:
        a string representation of this AssertionFailedError
        Since:
        1.1.1