Package org.fest.assertions
Class ObjectAssert
Understands assertion methods for objects. To create a new instance of this class use the
method
Assertions.assertThat(Object)
.-
Field Summary
Fields inherited from class org.fest.assertions.GenericAssert
actual
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
as
(Description description) Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
describedAs
(String description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(String)
describedAs
(Description description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(Description)
doesNotSatisfy
(Condition<Object> condition) Verifies that the actualObject
does not satisfy the given condition.private boolean
foundInstanceOfAny
(Class<?>... types) Alias for
.satisfies(Condition)
Verifies that the actualObject
is equal to the given one.isInstanceOf
(Class<?> type) Verifies that the actualObject
is an instance of the given type.isInstanceOfAny
(Class<?>... types) Verifies that the actualObject
is an instance of any of the given types.Alias for
.doesNotSatisfy(Condition)
isNotEqualTo
(Object other) Verifies that the actualObject
is not equal to the given one.Verifies that the actualObject
is notnull
.isNotSameAs
(Object other) Verifies that the actualObject
is not the same as the given one.Verifies that the actualObject
is the same as the given one.overridingErrorMessage
(String message) Replaces the default message displayed in case of a failure with the given one.Verifies that the actualObject
satisfies the given condition.private String
(package private) void
validateNotNull
(Class<?> type) Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNull
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
-
Constructor Details
-
ObjectAssert
Creates a newObjectAssert
.- Parameters:
actual
- the target to verify.
-
-
Method Details
-
isInstanceOf
Verifies that the actualObject
is an instance of the given type.- Parameters:
type
- the type to check the actualObject
against.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
isnull
.AssertionError
- if the actualObject
is not an instance of the given type.NullPointerException
- if the given type isnull
.
-
isInstanceOfAny
Verifies that the actualObject
is an instance of any of the given types.- Parameters:
types
- the types to check the actualObject
against.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
isnull
.AssertionError
- if the actualObject
is not an instance of any of the given types.NullPointerException
- if the given array of types isnull
.NullPointerException
- if the given array of types containsnull
s.
-
foundInstanceOfAny
-
validateNotNull
-
typeNames
-
as
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionError
For example:
assertThat(val).as("name").isEqualTo("Frodo");
- Specified by:
as
in classGenericAssert<Object>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for
, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(String)
For example:
assertThat(val).describedAs("name").isEqualTo("Frodo");
- Specified by:
describedAs
in classGenericAssert<Object>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
as
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionError
For example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
- Specified by:
as
in classGenericAssert<Object>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for
, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(Description)
For example:
assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");
- Specified by:
describedAs
in classGenericAssert<Object>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
satisfies
Verifies that the actualObject
satisfies the given condition.- Specified by:
satisfies
in classGenericAssert<Object>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualObject
does not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualObject
does not satisfy the given condition.- Specified by:
doesNotSatisfy
in classGenericAssert<Object>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualObject
satisfies the given condition.- See Also:
-
is
Alias for
.satisfies(Condition)
- Specified by:
is
in classGenericAssert<Object>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualObject
does not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for
.doesNotSatisfy(Condition)
- Specified by:
isNot
in classGenericAssert<Object>
- Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualObject
satisfies the given condition.- Since:
- 1.2
-
isNotNull
Verifies that the actualObject
is notnull
.- Specified by:
isNotNull
in classGenericAssert<Object>
- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
isnull
.
-
isSameAs
Verifies that the actualObject
is the same as the given one.- Specified by:
isSameAs
in classGenericAssert<Object>
- Parameters:
expected
- the givenObject
to compare the actualObject
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
is not the same as the given one.
-
isNotSameAs
Verifies that the actualObject
is not the same as the given one.- Specified by:
isNotSameAs
in classGenericAssert<Object>
- Parameters:
other
- the givenObject
to compare the actualObject
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
is the same as the given one.
-
isEqualTo
Verifies that the actualObject
is equal to the given one.- Specified by:
isEqualTo
in classGenericAssert<Object>
- Parameters:
expected
- the givenObject
to compare the actualObject
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
is not equal to the given one.
-
isNotEqualTo
Verifies that the actualObject
is not equal to the given one.- Specified by:
isNotEqualTo
in classGenericAssert<Object>
- Parameters:
other
- the givenObject
to compare the actualObject
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
is equal to the given one.
-
overridingErrorMessage
Replaces the default message displayed in case of a failure with the given one.For example, the following assertion:
assertThat("Hello").isEqualTo("Bye");
will fail with the default message "expected:<'[Bye]'> but was:<'[Hello]'>."We can replace this message with our own:
assertThat("Hello").overridingErrorMessage("'Hello' should be equal to 'Bye'").isEqualTo("Bye");
in this case, the assertion will fail showing the message "'Hello' should be equal to 'Bye'".- Specified by:
overridingErrorMessage
in classGenericAssert<Object>
- Parameters:
message
- the given error message, which will replace the default one.- Returns:
- this assertion.
-