Package org.fest.assertions
Class Fail
java.lang.Object
org.fest.assertions.Fail
Understands failure methods.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Fail()
This constructor is protected to make it possible to subclass this class. -
Method Summary
Modifier and TypeMethodDescriptionprotected static AssertionError
comparisonFailed
(Description description, Object actual, Object expected) Returns a
describing a comparison failure.AssertionError
static void
fail()
Fails with no message.static AssertionError
Fails with the given message.static void
Throws an
with the given message and with theAssertionError
that caused the failure.Throwable
private static void
fail
(Description description, Object[] message) protected static void
failIfActualIsNull
(String customErrorMessage, Description description, Object actual) Throws an
if the actual value isAssertionError
null
.protected static void
failIfEqual
(String customErrorMessage, Description descriptionOfActual, Object actual, Object other) Throws an
if the given objects are equal.AssertionError
protected static void
failIfNotEqual
(String customErrorMessage, Description descriptionOfActual, Object actual, Object expected) Throws an
if 'actual' is not equal to 'expected'.AssertionError
protected static void
failIfNotNull
(String customErrorMessage, Description description, Object o) Throws an
if the given object is notAssertionError
null
.protected static void
failIfNotSame
(String customErrorMessage, Description descriptionOfActual, Object actual, Object other) Throws an
if the given objects are not the same.AssertionError
protected static void
failIfNull
(String customErrorMessage, Description description, Object o) Throws an
if the given object isAssertionError
null
.protected static void
failIfSame
(String customErrorMessage, Description descriptionOfActual, Object actual, Object other) Throws an
if the given objects are the same.AssertionError
static AssertionError
Creates a
with the given message.AssertionError
protected static void
failWithMessage
(String customErrorMessage) Throws an
only if the given custom message is notAssertionError
null
.protected static void
failWithMessage
(String customErrorMessage, Throwable realCause) Throws an
only if the given custom message is notAssertionError
null
.
-
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
if the given objects are equal.AssertionError
- Parameters:
customErrorMessage
- any custom error message. This message will replace the default one only if it (the custom message) is notnull
.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
if 'actual' is not equal to 'expected'. If JUnit 4 (or greater) is in the classpath, this method will throw aAssertionError
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 notnull
.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
describing a comparison failure.AssertionError
- 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
if the actual value isAssertionError
null
.- Parameters:
customErrorMessage
- any custom error message. This message will replace the default one only if it (the custom message) is notnull
.description
- the description of the actual value.actual
- the actual value.- Throws:
AssertionError
- if the actual value isnull
.- Since:
- 1.3
-
failIfNull
Throws an
if the given object isAssertionError
null
.- Parameters:
customErrorMessage
- any custom error message. This message will replace the default one only if it (the custom message) is notnull
.description
- the description of the given object.o
- the given object.- Throws:
AssertionError
- if the given object isnull
.- Since:
- 1.2
-
failIfNotNull
Throws an
if the given object is notAssertionError
null
.- Parameters:
customErrorMessage
- any custom error message. This message will replace the default one only if it (the custom message) is notnull
.description
- the description of the given object.o
- the given object.- Throws:
AssertionError
- if the given object is notnull
.- Since:
- 1.2
-
failIfSame
protected static void failIfSame(String customErrorMessage, Description descriptionOfActual, Object actual, Object other) Throws an
if the given objects are the same.AssertionError
- Parameters:
customErrorMessage
- any custom error message. This message will replace the default one only if it (the custom message) is notnull
.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
if the given objects are not the same.AssertionError
- Parameters:
customErrorMessage
- any custom error message. This message will replace the default one only if it (the custom message) is notnull
.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
-
failWithMessage
Throws an
only if the given custom message is notAssertionError
null
.- Parameters:
customErrorMessage
- the custom error message.- Throws:
AssertionError
- only if the custom error message is notnull
.- Since:
- 1.2
-
failWithMessage
Throws an
only if the given custom message is notAssertionError
null
.- Parameters:
customErrorMessage
- the custom error message.realCause
- cause of the error.- Throws:
AssertionError
- only if the custom error message is notnull
.- Since:
- 1.2
-
fail
Throws an
with the given message and with theAssertionError
that caused the failure.Throwable
- Parameters:
description
- the description of the failed assertion. It can benull
.realCause
- cause of the error.
-
fail
Fails with the given message.Note: This method appears to return
, 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 toAssertionError
void
. Since we cannot create an overloaded version with return typevoid
, 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
Creates a
with the given message.AssertionError
- Parameters:
message
- the message of the exception to create.- Returns:
- the created exception.
- Since:
- 1.2
-