Package org.fest.assertions
Class Assert
java.lang.Object
org.fest.assertions.Assert
- Direct Known Subclasses:
GenericAssert
Understands the base class for all assertion methods for objects and primitives.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final String
Returns the message to use when a failure occurs, if one has been specified.final String
Returns the description of the actual value in this assertion.protected final void
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
protected final void
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
final boolean
Throws
if called.UnsupportedOperationException
protected final AssertionError
Fails by throwing an
.AssertionError
protected final void
Fails by throwing an
.AssertionError
protected final void
Throws an
only if the the custom message in this assertion object is notAssertionError
null
.protected final void
failIfCustomMessageIsSet
(Throwable realCause) Throws an
only if the the custom message in this assertion object is notAssertionError
null
.protected final AssertionError
Creates an
, adding the description of the actual value to the given message.AssertionError
protected final String
formattedErrorMessage
(String message) Returns the given message formatted as follows:final int
hashCode()
Always returns 1.protected final Description
Returns the description of the actual value in this assertion.protected final void
replaceDefaultErrorMessagesWith
(String message) Specifies the message to use in case of a failure, replacing the default one.
-
Field Details
-
description
-
errorMessage
-
-
Constructor Details
-
Assert
public Assert()
-
-
Method Details
-
description
Returns the description of the actual value in this assertion.- Returns:
- the description of the actual value in this assertion.
-
description
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
- Parameters:
d
- the new description.
-
description
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
- Parameters:
d
- the new 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
Returns the given message formatted as follows:[assertion description] given message.
- Parameters:
message
- the message to format.- Returns:
- the formatted message.
-
replaceDefaultErrorMessagesWith
Specifies the message to use in case of a failure, replacing the default one.- Parameters:
message
- the new error message.
-
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
only if the the custom message in this assertion object is notAssertionError
null
.- Throws:
AssertionError
- only if the custom error message in this assertion object is notnull
.- Since:
- 1.2
-
failIfCustomMessageIsSet
Throws an
only if the the custom message in this assertion object is notAssertionError
null
.- Parameters:
realCause
- cause of the error.- Throws:
AssertionError
- only if the custom error message in this assertion object is notnull
.- Since:
- 1.2
-
fail
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
Fails by throwing an
.AssertionError
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:
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
Creates an
, adding the description of the actual value to the given message.AssertionError
- Parameters:
reason
- the reason for the failure, used as the message for the thrown exception.- Returns:
- the created exception.
-
equals
Throws
if called. It is easy to accidentally callUnsupportedOperationException
instead ofequals(Object)
isEqualTo
.- Overrides:
equals
in classObject
- Throws:
UnsupportedOperationException
- if this method is called.
-
hashCode
public final int hashCode()Always returns 1.
-