Class Assert

java.lang.Object
org.fest.assertions.Assert
Direct Known Subclasses:
GenericAssert

public abstract class Assert extends Object
Understands the base class for all assertion methods for objects and primitives.
  • Field Details

    • description

      private Description description
    • errorMessage

      private String errorMessage
  • Constructor Details

    • Assert

      public Assert()
  • Method Details

    • description

      public final String description()
      Returns the description of the actual value in this assertion.
      Returns:
      the description of the actual value in this assertion.
    • description

      protected final void description(String d)
      Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
      Parameters:
      d - the new description.
    • description

      protected final void description(Description d)
      Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
      Parameters:
      d - the new description.
    • rawDescription

      protected final Description rawDescription()
      Returns the description of the actual value in this assertion.
      Returns:
      the description of the actual value in this assertion.
      Since:
      1.2
    • formattedErrorMessage

      protected final String formattedErrorMessage(String message)
      Returns the given message formatted as follows:
       [assertion description] given message.
       
      Parameters:
      message - the message to format.
      Returns:
      the formatted message.
    • replaceDefaultErrorMessagesWith

      protected final void replaceDefaultErrorMessagesWith(String message)
      Specifies the message to use in case of a failure, replacing the default one.
      Parameters:
      message - the new error message.
    • customErrorMessage

      protected final String customErrorMessage()
      Returns the message to use when a failure occurs, if one has been specified.
      Returns:
      the message to use when a failure occurs, or null if none has been specified.
    • failIfCustomMessageIsSet

      protected final void failIfCustomMessageIsSet()
      Throws an AssertionError only if the the custom message in this assertion object is not null.
      Throws:
      AssertionError - only if the custom error message in this assertion object is not null.
      Since:
      1.2
    • failIfCustomMessageIsSet

      protected final void failIfCustomMessageIsSet(Throwable realCause)
      Throws an AssertionError only if the the custom message in this assertion object is not null.
      Parameters:
      realCause - cause of the error.
      Throws:
      AssertionError - only if the custom error message in this assertion object is not null.
      Since:
      1.2
    • fail

      protected final void fail(String reason, Throwable cause)
      Fails by throwing an AssertionError.
      Parameters:
      reason - the reason for the failure, used as the message for the thrown exception.
      cause - the root cause of the failure, included in the thrown exception.
    • fail

      protected final AssertionError fail(String reason)
      Fails by throwing an AssertionError.

      Note: This method appears to return AssertionError, but it is really not the case, since the exception is thrown and not returned. In version 2.0 the return type of this method will change to void. Since we cannot create an overloaded version with return type void, we cannot deprecate this method. Please pretend this method does not return anything :)

      Parameters:
      reason - the reason for the failure, used as the message for the thrown exception.
      Returns:
      the thrown AssertionError.
      Throws:
      AssertionError - using the given reason as the message.
      See Also:
    • failure

      protected final AssertionError failure(String reason)
      Creates an AssertionError, adding the description of the actual value to the given message.
      Parameters:
      reason - the reason for the failure, used as the message for the thrown exception.
      Returns:
      the created exception.
    • equals

      public final boolean equals(Object obj)
      Throws UnsupportedOperationException if called. It is easy to accidentally call equals(Object) instead of isEqualTo.
      Overrides:
      equals in class Object
      Throws:
      UnsupportedOperationException - if this method is called.
    • hashCode

      public final int hashCode()
      Always returns 1.
      Overrides:
      hashCode in class Object
      Returns:
      1.