org.fest.assertions
Class CollectionAssert

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<CollectionAssert,Collection<?>>
                      extended by org.fest.assertions.CollectionAssert

public class CollectionAssert
extends ObjectGroupAssert<CollectionAssert,Collection<?>>

Assertions for Collections.

To create a new instance of this class invoke Assertions.assertThat(Collection).

Author:
Yvonne Wang, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual, myself
 
Constructor Summary
protected CollectionAssert(Collection<?> actual)
          Creates a new CollectionAssert.
 
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 number of elements in the actual collection.
 CollectionAssert onProperty(String propertyName)
          Creates a new instance of CollectionAssert whose target collection contains the values of the given property name from the elements of this CollectionAssert's collection.
 
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, isEqualTo, isIn, isIn, isNot, isNotEqualTo, 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

CollectionAssert

protected CollectionAssert(Collection<?> actual)
Creates a new CollectionAssert.

Parameters:
actual - the target to verify.
Method Detail

actualGroupSize

protected int actualGroupSize()
Returns the number of elements in the actual collection.

Specified by:
actualGroupSize in class GroupAssert<CollectionAssert,Collection<?>>
Returns:
the number of elements in the actual collection.
Throws:
AssertionError - if the actual collection is null.

onProperty

public CollectionAssert onProperty(String propertyName)
Creates a new instance of CollectionAssert whose target collection contains the values of the given property name from the elements of this CollectionAssert's collection. Property access works with both simple properties like Person.age and nested properties Person.father.age.

For example, let's say we have a collection 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<CollectionAssert,Collection<?>>
Parameters:
propertyName - the name of the property to extract values from the actual collection to build a new CollectionAssert.
Returns:
a new CollectionAssert containing the values of the given property name from the elements of this CollectionAssert's collection.
Throws:
AssertionError - if the actual collection is null.
org.fest.util.IntrospectionError - if an element in the given collection 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<CollectionAssert,Collection<?>>
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<CollectionAssert,Collection<?>>
Returns:
the actual value as a List.


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