org.fest.assertions
Class ObjectGroupAssert<S,A>

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<S,A>
Type Parameters:
S - used to simulate "self types." For more information please read "Emulating 'self types' using Java Generics to simplify fluent API implementation."
A - the type the "actual" value.
Direct Known Subclasses:
CollectionAssert, IteratorAssert, ListAssert, ObjectArrayAssert

public abstract class ObjectGroupAssert<S,A>
extends ItemGroupAssert<S,A>

Template for assertions for arrays or collections.

Since:
1.3
Author:
Yvonne Wang

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual, myself
 
Constructor Summary
protected ObjectGroupAssert(Class<S> selfType, A actual)
          Creates a new ObjectGroupAssert.
 
Method Summary
 S contains(Object... objects)
          Verifies that the actual group of objects contains the given objects.
 S containsOnly(Object... objects)
          Verifies that the actual group of objects contains the given objects only, in any order.
 S doesNotHaveDuplicates()
          Verifies that the actual group of objects does not have duplicates.
 S excludes(Object... objects)
          Verifies that the actual group of objects does not contain the given objects.
protected abstract  S onProperty(String propertyName)
          Creates a new group of objects whose target collection contains the values of the given property name from the elements of the actual group of objects.
 
Methods inherited from class org.fest.assertions.ItemGroupAssert
actualAsList, actualAsSet, assertContains, assertContainsOnly, assertDoesNotHaveDuplicates, assertExcludes, validateIsNotNull
 
Methods inherited from class org.fest.assertions.GroupAssert
actualGroupSize, 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

ObjectGroupAssert

protected ObjectGroupAssert(Class<S> selfType,
                            A actual)
Creates a new ObjectGroupAssert.

Parameters:
selfType - the "self type."
actual - the target to verify.
Method Detail

contains

public final S contains(Object... objects)
Verifies that the actual group of objects contains the given objects.

Parameters:
objects - the objects to look for.
Returns:
this assertion object.
Throws:
AssertionError - if the actual group of objects is null.
NullPointerException - if the given array is null.
AssertionError - if the actual group of objects does not contain the given objects.

containsOnly

public final S containsOnly(Object... objects)
Verifies that the actual group of objects contains the given objects only, in any order.

Parameters:
objects - the objects to look for.
Returns:
this assertion object.
Throws:
AssertionError - if the actual group of objects is null.
NullPointerException - if the given group of objects is null.
AssertionError - if the actual group of objects does not contain the given objects, or if the actual group of objects contains elements other than the ones specified.

excludes

public final S excludes(Object... objects)
Verifies that the actual group of objects does not contain the given objects.

Parameters:
objects - the objects that the group of objects should exclude.
Returns:
this assertion object.
Throws:
AssertionError - if the actual group of objects is null.
NullPointerException - if the given array is null.
AssertionError - if the actual group of objects contains any of the given objects.

doesNotHaveDuplicates

public final S doesNotHaveDuplicates()
Verifies that the actual group of objects does not have duplicates.

Returns:
this assertion object.
Throws:
AssertionError - if the actual group of objects is null.
AssertionError - if the actual group of objects has duplicates.

onProperty

protected abstract S onProperty(String propertyName)
Creates a new group of objects whose target collection contains the values of the given property name from the elements of the actual group of objects. 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
 

Parameters:
propertyName - the name of the property to extract values from the actual collection to build a new group of objects.
Returns:
a new group of objects containing the values of the given property name from the elements of the actual group of objects.
Throws:
AssertionError - if the actual group of objects is null.
org.fest.util.IntrospectionError - if an element in the given collection does not have a matching property.
Since:
1.3


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