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
ConstructorsModifierConstructorDescriptionprotectedObjectArrayAssert(Object... actual) Creates a newObjectArrayAssert. -
Method Summary
Modifier and TypeMethodDescriptionReturns the actual value as aList.Returns the actual value as aSet.protected intReturns 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 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.AssertionErrorVerifies that the actualObjectarray contains the given objects.containsOnly(Object... objects) Verifies that the actualObjectarray 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 actualObjectarray does not have duplicates.doesNotSatisfy(Condition<Object[]> condition) Verifies that the actualObjectarray does not satisfy the given condition.Verifies that the actualObjectarray does not contain the given objects.hasAllElementsOfType(Class<?> type) Verifies that all the elements in the actualObjectarray belong to the specified type.hasAtLeastOneElementOfType(Class<?> type) Verifies that at least one element in the actualObjectarray belong to the specified type.hasSize(int expected) Verifies that the number of elements in the actualObjectarray is equal to the given one.Alias for.satisfies(Condition)Verifies that the actualObjectarray is equal to the given array.Alias for.doesNotSatisfy(Condition)Verifies that the actualObjectarray contains at least on element.isNotEqualTo(Object[] array) Verifies that the actualObjectarray is not equal to the given array.Verifies that the actualObjectarray is notnull.isNotSameAs(Object[] expected) Verifies that the actualObjectarray is not the same as the given array.Verifies that the actualObjectarray is the same as the given array.onProperty(String propertyName) Creates a new instance ofwhose target array contains the values of the given property name from the elements of thisObjectArrayAssertObjectArrayAssert's array.overridingErrorMessage(String message) Replaces the default message displayed in case of a failure with the given one.Verifies that the actualObjectarray satisfies the given condition.private voidvalidateIsNotNull(Class<?> type) Methods inherited from class org.fest.assertions.ItemGroupAssert
assertContains, assertContainsOnly, assertDoesNotHaveDuplicates, assertExcludes, asSet, validateIsNotNullMethods inherited from class org.fest.assertions.GroupAssert
assertHasSize, assertIsNotEmpty, isEmpty, isNullOrEmptyMethods 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
-
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 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 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:
describedAsin 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 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 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:
describedAsin classObjectGroupAssert<Object[]>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
hasAllElementsOfType
Verifies that all the elements in the actualObjectarray 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 assertionhasAllElementsOfTypewill 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 actualObjectarray is not the same as the specified one.
-
hasAtLeastOneElementOfType
Verifies that at least one element in the actualObjectarray 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 actualObjectdoes not have any elements of the given type.
-
validateIsNotNull
-
contains
Verifies that the actualObjectarray contains the given objects.- Specified by:
containsin classObjectGroupAssert<Object[]>- Parameters:
objects- the objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray isnull.NullPointerException- if the givenObjectarray isnull.AssertionError- if the actualObjectarray does not contain the given objects.
-
containsOnly
Verifies that the actualObjectarray contains the given objects only.- Specified by:
containsOnlyin classObjectGroupAssert<Object[]>- Parameters:
objects- the objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray isnull.NullPointerException- if the givenObjectarray isnull.AssertionError- if the actualObjectarray does not contain the given objects, or if the actualObjectarray contains elements other than the ones specified.
-
excludes
Verifies that the actualObjectarray does not contain the given objects.- Specified by:
excludesin classObjectGroupAssert<Object[]>- Parameters:
objects- the objects the array should exclude.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray isnull.NullPointerException- if the givenObjectarray isnull.AssertionError- if the actualObjectarray contains any of the given objects.
-
doesNotHaveDuplicates
Verifies that the actualObjectarray does not have duplicates.- Specified by:
doesNotHaveDuplicatesin classObjectGroupAssert<Object[]>- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray isnull.AssertionError- if the actualObjectarray has duplicates.
-
satisfies
Verifies that the actualObjectarray satisfies 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 actualObjectarray does not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualObjectarray does 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 actualObjectarray satisfies 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 actualObjectarray does 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 actualObjectarray satisfies the given condition.- Since:
- 1.2
-
isNotNull
Verifies that the actualObjectarray is notnull.- Specified by:
isNotNullin classGenericAssert<Object[]>- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray isnull.
-
isNotEmpty
Verifies that the actualObjectarray contains at least on element.- Specified by:
isNotEmptyin classGroupAssert<Object[]>- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray isnull.AssertionError- if the actualObjectarray is empty.
-
isEqualTo
Verifies that the actualObjectarray is equal to the given array. Array equality is checked by.Arrays.deepEquals(Object[], Object[])- Specified by:
isEqualToin classGenericAssert<Object[]>- Parameters:
expected- the given array to compare the actual array to.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray is not equal to the given one.
-
isNotEqualTo
Verifies that the actualObjectarray is not equal to the given array. Array equality is checked by.Arrays.deepEquals(Object[], Object[])- Specified by:
isNotEqualToin classGenericAssert<Object[]>- Parameters:
array- the given array to compare the actual array to.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray is equal to the given one.
-
hasSize
Verifies that the number of elements in the actualObjectarray is equal to the given one.- Specified by:
hasSizein classGroupAssert<Object[]>- Parameters:
expected- the expected number of elements in the actualObjectarray.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray isnull.AssertionError- if the number of elements in the actualObjectarray is not equal to the given one.
-
isSameAs
Verifies that the actualObjectarray is the same as the given array.- Specified by:
isSameAsin classGenericAssert<Object[]>- Parameters:
expected- the given array to compare the actual array to.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray is not the same as the given one.
-
isNotSameAs
Verifies that the actualObjectarray is not the same as the given array.- Specified by:
isNotSameAsin classGenericAssert<Object[]>- Parameters:
expected- the given array to compare the actual array to.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualObjectarray 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:
overridingErrorMessagein classObjectGroupAssert<Object[]>- Parameters:
message- the given error message, which will replace the default one.- Returns:
- this assertion.
-
onProperty
Creates a new instance ofwhose target array contains the values of the given property name from the elements of thisObjectArrayAssertObjectArrayAssert's array. Property access works with both simple properties likePerson.ageand nested propertiesPerson.father.age.For example, let's say we have a array of
Personobjects 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:
onPropertyin classObjectGroupAssert<Object[]>- Parameters:
propertyName- the name of the property to extract values from the actual array to build a newObjectArrayAssert.- Returns:
- a new
ObjectArrayAssertcontaining 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:
actualAsSetin classItemGroupAssert<Object[]>- Returns:
- the actual value as a
Set.
-
actualAsList
Returns the actual value as aList.- Specified by:
actualAsListin 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:
actualGroupSizein classGroupAssert<Object[]>- Returns:
- the size of the actual group of values.
-