Class Fail

java.lang.Object
org.fest.assertions.Fail

public final class Fail extends Object
Understands failure methods.
  • Constructor Details

    • Fail

      protected Fail()
      This constructor is protected to make it possible to subclass this class. Since all its methods are static, there is no point on creating a new instance of it.
  • Method Details

    • fail

      public static void fail()
      Fails with no message.
      Throws:
      AssertionError - without any message.
    • failIfEqual

      protected static void failIfEqual(String customErrorMessage, Description descriptionOfActual, Object actual, Object other)
      Throws an AssertionError if the given objects are equal.
      Parameters:
      customErrorMessage - any custom error message. This message will replace the default one only if it (the custom message) is not null.
      descriptionOfActual - the description of the actual value.
      actual - the actual object.
      other - the object to compare to.
      Throws:
      AssertionError - if the given objects are equal.
      Since:
      1.2
    • failIfNotEqual

      protected static void failIfNotEqual(String customErrorMessage, Description descriptionOfActual, Object actual, Object expected)
      Throws an AssertionError if 'actual' is not equal to 'expected'. If JUnit 4 (or greater) is in the classpath, this method will throw a ComparisonFailure instead. More details about this feature can be found here.
      Parameters:
      customErrorMessage - any custom error message. This message will replace the default one only if it (the custom message) is not null.
      descriptionOfActual - the description of the actual value.
      actual - the actual object.
      expected - the expected object.
      Throws:
      AssertionError - if the given objects are not equal.
      Since:
      1.2
    • comparisonFailed

      protected static AssertionError comparisonFailed(Description description, Object actual, Object expected)
      Returns a AssertionError describing a comparison failure.
      Parameters:
      description - the description of the comparison.
      actual - the actual value.
      expected - the expected value.
      Returns:
      a AssertionError describing the comparison failure.
      Since:
      1.3
    • failIfActualIsNull

      protected static void failIfActualIsNull(String customErrorMessage, Description description, Object actual)
      Throws an AssertionError if the actual value is null.
      Parameters:
      customErrorMessage - any custom error message. This message will replace the default one only if it (the custom message) is not null.
      description - the description of the actual value.
      actual - the actual value.
      Throws:
      AssertionError - if the actual value is null.
      Since:
      1.3
    • failIfNull

      protected static void failIfNull(String customErrorMessage, Description description, Object o)
      Throws an AssertionError if the given object is null.
      Parameters:
      customErrorMessage - any custom error message. This message will replace the default one only if it (the custom message) is not null.
      description - the description of the given object.
      o - the given object.
      Throws:
      AssertionError - if the given object is null.
      Since:
      1.2
    • failIfNotNull

      protected static void failIfNotNull(String customErrorMessage, Description description, Object o)
      Throws an AssertionError if the given object is not null.
      Parameters:
      customErrorMessage - any custom error message. This message will replace the default one only if it (the custom message) is not null.
      description - the description of the given object.
      o - the given object.
      Throws:
      AssertionError - if the given object is not null.
      Since:
      1.2
    • failIfSame

      protected static void failIfSame(String customErrorMessage, Description descriptionOfActual, Object actual, Object other)
      Throws an AssertionError if the given objects are the same.
      Parameters:
      customErrorMessage - any custom error message. This message will replace the default one only if it (the custom message) is not null.
      descriptionOfActual - the description of the actual value.
      actual - the actual object.
      other - the object to compare to.
      Throws:
      AssertionError - if the given objects are the same.
      Since:
      1.2
    • failIfNotSame

      protected static void failIfNotSame(String customErrorMessage, Description descriptionOfActual, Object actual, Object other)
      Throws an AssertionError if the given objects are not the same.
      Parameters:
      customErrorMessage - any custom error message. This message will replace the default one only if it (the custom message) is not null.
      descriptionOfActual - the description of the actual value.
      actual - the actual object.
      other - the object to compare to.
      Throws:
      AssertionError - if the given objects are not the same.
      Since:
      1.2
    • fail

      private static void fail(Description description, Object[] message)
    • failWithMessage

      protected static void failWithMessage(String customErrorMessage)
      Throws an AssertionError only if the given custom message is not null.
      Parameters:
      customErrorMessage - the custom error message.
      Throws:
      AssertionError - only if the custom error message is not null.
      Since:
      1.2
    • failWithMessage

      protected static void failWithMessage(String customErrorMessage, Throwable realCause)
      Throws an AssertionError only if the given custom message is not null.
      Parameters:
      customErrorMessage - the custom error message.
      realCause - cause of the error.
      Throws:
      AssertionError - only if the custom error message is not null.
      Since:
      1.2
    • fail

      public static void fail(String description, Throwable realCause)
      Throws an AssertionError with the given message and with the Throwable that caused the failure.
      Parameters:
      description - the description of the failed assertion. It can be null.
      realCause - cause of the error.
    • fail

      public static AssertionError fail(String message)
      Fails with the given message.

      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:
      message - error message.
      Returns:
      the thrown AssertionError.
      Throws:
      AssertionError - with the given message.
      See Also:
    • failure

      public static AssertionError failure(String message)
      Creates a AssertionError with the given message.
      Parameters:
      message - the message of the exception to create.
      Returns:
      the created exception.
      Since:
      1.2