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 anythrown when an assertion fails.AssertionErroras(Description description) Sets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErrordescribedAs(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 actualObjectdoes not satisfy the given condition.private booleanfoundInstanceOfAny(Class<?>... types) Alias for.satisfies(Condition)Verifies that the actualObjectis equal to the given one.isInstanceOf(Class<?> type) Verifies that the actualObjectis an instance of the given type.isInstanceOfAny(Class<?>... types) Verifies that the actualObjectis an instance of any of the given types.Alias for.doesNotSatisfy(Condition)isNotEqualTo(Object other) Verifies that the actualObjectis not equal to the given one.Verifies that the actualObjectis notnull.isNotSameAs(Object other) Verifies that the actualObjectis not the same as the given one.Verifies that the actualObjectis 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 actualObjectsatisfies the given condition.private String(package private) voidvalidateNotNull(Class<?> type) Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNullMethods 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 actualObjectis an instance of the given type.- Parameters:
type- the type to check the actualObjectagainst.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectisnull.AssertionError- if the actualObjectis not an instance of the given type.NullPointerException- if the given type isnull.
-
isInstanceOfAny
Verifies that the actualObjectis an instance of any of the given types.- Parameters:
types- the types to check the actualObjectagainst.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectisnull.AssertionError- if the actualObjectis not an instance of any of the given types.NullPointerException- if the given array of types isnull.NullPointerException- if the given array of types containsnulls.
-
foundInstanceOfAny
-
validateNotNull
-
typeNames
-
as
Sets the description of the actual value, to be used in as message of anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as("name").isEqualTo("Frodo");- Specified by:
asin 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:
describedAsin 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 anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");- Specified by:
asin 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:
describedAsin classGenericAssert<Object>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
satisfies
Verifies that the actualObjectsatisfies the given condition.- Specified by:
satisfiesin classGenericAssert<Object>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualObjectdoes not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualObjectdoes not satisfy the given condition.- Specified by:
doesNotSatisfyin classGenericAssert<Object>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualObjectsatisfies the given condition.- See Also:
-
is
Alias for.satisfies(Condition)- Specified by:
isin classGenericAssert<Object>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualObjectdoes not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for.doesNotSatisfy(Condition)- Specified by:
isNotin classGenericAssert<Object>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualObjectsatisfies the given condition.- Since:
- 1.2
-
isNotNull
Verifies that the actualObjectis notnull.- Specified by:
isNotNullin classGenericAssert<Object>- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectisnull.
-
isSameAs
Verifies that the actualObjectis the same as the given one.- Specified by:
isSameAsin classGenericAssert<Object>- Parameters:
expected- the givenObjectto compare the actualObjectto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectis not the same as the given one.
-
isNotSameAs
Verifies that the actualObjectis not the same as the given one.- Specified by:
isNotSameAsin classGenericAssert<Object>- Parameters:
other- the givenObjectto compare the actualObjectto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectis the same as the given one.
-
isEqualTo
Verifies that the actualObjectis equal to the given one.- Specified by:
isEqualToin classGenericAssert<Object>- Parameters:
expected- the givenObjectto compare the actualObjectto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectis not equal to the given one.
-
isNotEqualTo
Verifies that the actualObjectis not equal to the given one.- Specified by:
isNotEqualToin classGenericAssert<Object>- Parameters:
other- the givenObjectto compare the actualObjectto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectis 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:
overridingErrorMessagein classGenericAssert<Object>- Parameters:
message- the given error message, which will replace the default one.- Returns:
- this assertion.
-