Package org.fest.assertions
Class ObjectArrayAssert
java.lang.Object
Understands assertions for
Object
arrays. 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
ConstructorsModifierConstructorDescriptionprotected
ObjectArrayAssert
(Object... actual) Creates a newObjectArrayAssert
. -
Method Summary
Modifier and TypeMethodDescriptionReturns the actual value as aList
.Returns the actual value as aSet
.protected int
Returns the size of the actual group of values (array, collection, etc.)Sets 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
Verifies that the actualObject
array contains the given objects.containsOnly
(Object... objects) Verifies that the actualObject
array contains the given objects only.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)
Verifies that the actualObject
array does not have duplicates.doesNotSatisfy
(Condition<Object[]> condition) Verifies that the actualObject
array does not satisfy the given condition.Verifies that the actualObject
array does not contain the given objects.hasAllElementsOfType
(Class<?> type) Verifies that all the elements in the actualObject
array belong to the specified type.hasAtLeastOneElementOfType
(Class<?> type) Verifies that at least one element in the actualObject
array belong to the specified type.hasSize
(int expected) Verifies that the number of elements in the actualObject
array is equal to the given one.Alias for
.satisfies(Condition)
Verifies that the actualObject
array is equal to the given array.Alias for
.doesNotSatisfy(Condition)
Verifies that the actualObject
array contains at least on element.isNotEqualTo
(Object[] array) Verifies that the actualObject
array is not equal to the given array.Verifies that the actualObject
array is notnull
.isNotSameAs
(Object[] expected) Verifies that the actualObject
array is not the same as the given array.Verifies that the actualObject
array is the same as the given array.onProperty
(String propertyName) Creates a new instance of
whose target array contains the values of the given property name from the elements of thisObjectArrayAssert
ObjectArrayAssert
's array.overridingErrorMessage
(String message) Replaces the default message displayed in case of a failure with the given one.Verifies that the actualObject
array satisfies the given condition.private void
validateIsNotNull
(Class<?> type) Methods inherited from class org.fest.assertions.ItemGroupAssert
assertContains, assertContainsOnly, assertDoesNotHaveDuplicates, assertExcludes, asSet, validateIsNotNull
Methods inherited from class org.fest.assertions.GroupAssert
assertHasSize, assertIsNotEmpty, isEmpty, isNullOrEmpty
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
-
ObjectArrayAssert
Creates a newObjectArrayAssert
.- Parameters:
actual
- the target to verify.
-
-
Method Details
-
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 classObjectGroupAssert<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 classObjectGroupAssert<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 classObjectGroupAssert<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 classObjectGroupAssert<Object[]>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
hasAllElementsOfType
Verifies that all the elements in the actualObject
array belong to the specified type. Matching includes subclasses of the given type.For example, consider the following code listing:
Number[] numbers = { 2, 6 ,8 }; assertThat(numbers).hasComponentType(Integer.class);
The assertionhasAllElementsOfType
will be successful.- Parameters:
type
- the expected type.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given type isnull
.AssertionError
- if the component type of the actualObject
array is not the same as the specified one.
-
hasAtLeastOneElementOfType
Verifies that at least one element in the actualObject
array belong to the specified type. Matching includes subclasses of the given type.- Parameters:
type
- the expected type.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
does not have any elements of the given type.
-
validateIsNotNull
-
contains
Verifies that the actualObject
array contains the given objects.- Specified by:
contains
in classObjectGroupAssert<Object[]>
- Parameters:
objects
- the objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array isnull
.NullPointerException
- if the givenObject
array isnull
.AssertionError
- if the actualObject
array does not contain the given objects.
-
containsOnly
Verifies that the actualObject
array contains the given objects only.- Specified by:
containsOnly
in classObjectGroupAssert<Object[]>
- Parameters:
objects
- the objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array isnull
.NullPointerException
- if the givenObject
array isnull
.AssertionError
- if the actualObject
array does not contain the given objects, or if the actualObject
array contains elements other than the ones specified.
-
excludes
Verifies that the actualObject
array does not contain the given objects.- Specified by:
excludes
in classObjectGroupAssert<Object[]>
- Parameters:
objects
- the objects the array should exclude.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array isnull
.NullPointerException
- if the givenObject
array isnull
.AssertionError
- if the actualObject
array contains any of the given objects.
-
doesNotHaveDuplicates
Verifies that the actualObject
array does not have duplicates.- Specified by:
doesNotHaveDuplicates
in classObjectGroupAssert<Object[]>
- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array isnull
.AssertionError
- if the actualObject
array has duplicates.
-
satisfies
Verifies that the actualObject
array 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
array does not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualObject
array 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
array 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
array 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
array satisfies the given condition.- Since:
- 1.2
-
isNotNull
Verifies that the actualObject
array is notnull
.- Specified by:
isNotNull
in classGenericAssert<Object[]>
- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array isnull
.
-
isNotEmpty
Verifies that the actualObject
array contains at least on element.- Specified by:
isNotEmpty
in classGroupAssert<Object[]>
- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array isnull
.AssertionError
- if the actualObject
array is empty.
-
isEqualTo
Verifies that the actualObject
array is equal to the given array. Array equality is checked by
.Arrays.deepEquals(Object[], Object[])
- Specified by:
isEqualTo
in classGenericAssert<Object[]>
- Parameters:
expected
- the given array to compare the actual array to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array is not equal to the given one.
-
isNotEqualTo
Verifies that the actualObject
array is not equal to the given array. Array equality is checked by
.Arrays.deepEquals(Object[], Object[])
- Specified by:
isNotEqualTo
in classGenericAssert<Object[]>
- Parameters:
array
- the given array to compare the actual array to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array is equal to the given one.
-
hasSize
Verifies that the number of elements in the actualObject
array is equal to the given one.- Specified by:
hasSize
in classGroupAssert<Object[]>
- Parameters:
expected
- the expected number of elements in the actualObject
array.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array isnull
.AssertionError
- if the number of elements in the actualObject
array is not equal to the given one.
-
isSameAs
Verifies that the actualObject
array is the same as the given array.- Specified by:
isSameAs
in classGenericAssert<Object[]>
- Parameters:
expected
- the given array to compare the actual array to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array is not the same as the given one.
-
isNotSameAs
Verifies that the actualObject
array is not the same as the given array.- Specified by:
isNotSameAs
in classGenericAssert<Object[]>
- Parameters:
expected
- the given array to compare the actual array to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualObject
array is the same as 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 classObjectGroupAssert<Object[]>
- Parameters:
message
- the given error message, which will replace the default one.- Returns:
- this assertion.
-
onProperty
Creates a new instance of
whose target array contains the values of the given property name from the elements of thisObjectArrayAssert
ObjectArrayAssert
's array. Property access works with both simple properties likePerson.age
and nested propertiesPerson.father.age
.For example, let's say we have a array of
Person
objects and you want to verify their age:assertThat(persons).onProperty("age").containsOnly(25, 16, 44, 37); // simple property assertThat(persons).onProperty("father.age").containsOnly(55, 46, 74, 62); // nested property
- Specified by:
onProperty
in classObjectGroupAssert<Object[]>
- Parameters:
propertyName
- the name of the property to extract values from the actual array to build a newObjectArrayAssert
.- Returns:
- a new
ObjectArrayAssert
containing the values of the given property name from the elements of thisObjectArrayAssert
's array. - Throws:
AssertionError
- if the actual array isnull
.org.fest.util.IntrospectionError
- if an element in the given array does not have a matching property.- Since:
- 1.3
-
actualAsSet
Returns the actual value as aSet
.- Specified by:
actualAsSet
in classItemGroupAssert<Object[]>
- Returns:
- the actual value as a
Set
.
-
actualAsList
Returns the actual value as aList
.- Specified by:
actualAsList
in classItemGroupAssert<Object[]>
- Returns:
- the actual value as a
List
.
-
actualGroupSize
protected int actualGroupSize()Returns the size of the actual group of values (array, collection, etc.)- Specified by:
actualGroupSize
in classGroupAssert<Object[]>
- Returns:
- the size of the actual group of values.
-