org.fest.assertions
Class Fail

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

public final class Fail
extends Object

Understands failure methods.

Author:
Alex Ruiz, Yvonne Wang

Constructor Summary
protected Fail()
          This constructor is protected to make it possible to subclass this class.
 
Method Summary
static void fail()
          Fails with no message.
static AssertionError fail(String message)
          Fails with the given message.
static void fail(String description, Throwable realCause)
          Throws an AssertionError with the given message and with the Throwable that caused the failure.
protected static void failIfEqual(String customErrorMessage, Description descriptionOfActual, Object actual, Object other)
          Throws an AssertionError if the given objects are equal.
protected static void failIfNotEqual(String customErrorMessage, Description descriptionOfActual, Object actual, Object expected)
          Throws an AssertionError if 'actual' is not equal to 'expected'.
protected static void failIfNotNull(String customErrorMessage, Description description, Object o)
          Throws an AssertionError if the given object is not null.
protected static void failIfNotSame(String customErrorMessage, Description descriptionOfActual, Object actual, Object other)
          Throws an AssertionError if the given objects are not the same.
protected static void failIfNull(String customErrorMessage, Description description, Object o)
          Throws an AssertionError if the given object is null.
protected static void failIfSame(String customErrorMessage, Description descriptionOfActual, Object actual, Object other)
          Throws an AssertionError if the given objects are the same.
static AssertionError failure(String message)
          Creates a AssertionError with the given message.
protected static void failWithMessage(String customErrorMessage)
          Throws an AssertionError only if the given custom message is not null.
protected static void failWithMessage(String customErrorMessage, Throwable realCause)
          Throws an AssertionError only if the given custom message is not null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

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

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

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(String)

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


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.