org.fest.assertions
Class ObjectArrayAssert

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<S,A>
          extended by org.fest.assertions.GroupAssert<S,A>
              extended by org.fest.assertions.ItemGroupAssert<S,A>
                  extended by org.fest.assertions.ObjectGroupAssert<ObjectArrayAssert,Object[]>
                      extended by org.fest.assertions.ObjectArrayAssert

public class ObjectArrayAssert
extends ObjectGroupAssert<ObjectArrayAssert,Object[]>

Assertions for Object arrays.

To create a new instance of this class invoke Assertions.assertThat(Object[]).

Author:
Yvonne Wang, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual, myself
 
Constructor Summary
protected ObjectArrayAssert(Object... actual)
          Creates a new ObjectArrayAssert.
 
Method Summary
protected  List<Object> actualAsList()
          Returns the actual value as a List.
protected  Set<Object> actualAsSet()
          Returns the actual value as a Set.
protected  int actualGroupSize()
          Returns the size of the actual group of values (array, collection, etc.)
 ObjectArrayAssert hasAllElementsOfType(Class<?> type)
          Verifies that all the elements in the actual Object array belong to the specified type.
 ObjectArrayAssert hasAtLeastOneElementOfType(Class<?> type)
          Verifies that at least one element in the actual Object array belong to the specified type.
 ObjectArrayAssert isEqualTo(Object[] expected)
          Verifies that the actual Object array is equal to the given array.
 ObjectArrayAssert isNotEqualTo(Object[] array)
          Verifies that the actual Object array is not equal to the given array.
 ObjectArrayAssert onProperty(String propertyName)
          Creates a new instance of ObjectArrayAssert whose target array contains the values of the given property name from the elements of this ObjectArrayAssert's array.
 
Methods inherited from class org.fest.assertions.ObjectGroupAssert
contains, containsOnly, doesNotHaveDuplicates, excludes
 
Methods inherited from class org.fest.assertions.ItemGroupAssert
assertContains, assertContainsOnly, assertDoesNotHaveDuplicates, assertExcludes, validateIsNotNull
 
Methods inherited from class org.fest.assertions.GroupAssert
hasSize, isEmpty, isNotEmpty, isNullOrEmpty
 
Methods inherited from class org.fest.assertions.GenericAssert
as, as, describedAs, describedAs, doesNotSatisfy, is, isIn, isIn, isNot, isNotIn, isNotIn, isNotNull, isNotSameAs, isNull, isSameAs, overridingErrorMessage, satisfies
 
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectArrayAssert

protected ObjectArrayAssert(Object... actual)
Creates a new ObjectArrayAssert.

Parameters:
actual - the target to verify.
Method Detail

hasAllElementsOfType

public ObjectArrayAssert hasAllElementsOfType(Class<?> type)
Verifies that all the elements in the actual Object 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 assertion hasAllElementsOfType will be successful.

Parameters:
type - the expected type.
Returns:
this assertion object.
Throws:
NullPointerException - if the given type is null.
AssertionError - if the component type of the actual Object array is not the same as the specified one.

hasAtLeastOneElementOfType

public ObjectArrayAssert hasAtLeastOneElementOfType(Class<?> type)
Verifies that at least one element in the actual Object 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 actual Object does not have any elements of the given type.

isEqualTo

public ObjectArrayAssert isEqualTo(Object[] expected)
Verifies that the actual Object array is equal to the given array. Array equality is checked by Arrays.deepEquals(Object[], Object[]).

Overrides:
isEqualTo in class GenericAssert<ObjectArrayAssert,Object[]>
Parameters:
expected - the given array to compare the actual array to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is not equal to the given one.

isNotEqualTo

public ObjectArrayAssert isNotEqualTo(Object[] array)
Verifies that the actual Object array is not equal to the given array. Array equality is checked by Arrays.deepEquals(Object[], Object[]).

Overrides:
isNotEqualTo in class GenericAssert<ObjectArrayAssert,Object[]>
Parameters:
array - the given array to compare the actual array to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is equal to the given one.

onProperty

public ObjectArrayAssert onProperty(String propertyName)
Creates a new instance of ObjectArrayAssert whose target array contains the values of the given property name from the elements of this ObjectArrayAssert's array. Property access works with both simple properties like Person.age and nested properties Person.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 class ObjectGroupAssert<ObjectArrayAssert,Object[]>
Parameters:
propertyName - the name of the property to extract values from the actual array to build a new ObjectArrayAssert.
Returns:
a new ObjectArrayAssert containing the values of the given property name from the elements of this ObjectArrayAssert's array.
Throws:
AssertionError - if the actual array is null.
org.fest.util.IntrospectionError - if an element in the given array does not have a matching property.
Since:
1.3

actualAsSet

protected Set<Object> actualAsSet()
Returns the actual value as a Set.

Specified by:
actualAsSet in class ItemGroupAssert<ObjectArrayAssert,Object[]>
Returns:
the actual value as a Set.

actualAsList

protected List<Object> actualAsList()
Returns the actual value as a List.

Specified by:
actualAsList in class ItemGroupAssert<ObjectArrayAssert,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 class GroupAssert<ObjectArrayAssert,Object[]>
Returns:
the size of the actual group of values.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.