org.fest.assertions
Class ObjectGroupAssert<T>

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<T>
          extended by org.fest.assertions.GroupAssert<T>
              extended by org.fest.assertions.ItemGroupAssert<T>
                  extended by org.fest.assertions.ObjectGroupAssert<T>
Type Parameters:
T - the type of object implementations of this template can verify.
Direct Known Subclasses:
CollectionAssert, ListAssert, ObjectArrayAssert

public abstract class ObjectGroupAssert<T>
extends ItemGroupAssert<T>

Understands a template for assertion methods related to arrays or collections.

Since:
1.3
Author:
Yvonne Wang

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual
 
Constructor Summary
protected ObjectGroupAssert(T actual)
          Creates a new ObjectGroupAssert.
 
Method Summary
protected abstract  ObjectGroupAssert<T> as(Description description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
protected abstract  ObjectGroupAssert<T> as(String description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
protected abstract  ObjectGroupAssert<T> contains(Object... objects)
          Verifies that the actual group of objects contains the given objects.
protected abstract  ObjectGroupAssert<T> containsOnly(Object... objects)
          Verifies that the actual group of objects contains the given objects only, in any order.
protected abstract  ObjectGroupAssert<T> describedAs(Description description)
          Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy.
protected abstract  ObjectGroupAssert<T> describedAs(String description)
          Alias for GenericAssert.as(String), since "as" is a keyword in Groovy.
protected abstract  ObjectGroupAssert<T> doesNotHaveDuplicates()
          Verifies that the actual group of objects does not have duplicates.
protected abstract  ObjectGroupAssert<T> excludes(Object... objects)
          Verifies that the actual group of objects does not contain the given objects.
protected abstract  ObjectGroupAssert<T> 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.
protected abstract  ObjectGroupAssert<T> overridingErrorMessage(String message)
          Replaces the default message displayed in case of a failure with the given one.
 
Methods inherited from class org.fest.assertions.ItemGroupAssert
actualAsList, actualAsSet, assertContains, assertContainsOnly, assertDoesNotHaveDuplicates, assertExcludes, asSet, validateIsNotNull
 
Methods inherited from class org.fest.assertions.GroupAssert
actualGroupSize, assertHasSize, assertIsNotEmpty, hasSize, isEmpty, isNotEmpty, isNullOrEmpty
 
Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, doesNotSatisfy, is, isEqualTo, isNot, isNotEqualTo, isNotNull, isNotSameAs, isNull, isSameAs, 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(T actual)
Creates a new ObjectGroupAssert.

Parameters:
actual - the target to verify.
Method Detail

contains

protected abstract ObjectGroupAssert<T> 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

protected abstract ObjectGroupAssert<T> 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

protected abstract ObjectGroupAssert<T> 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

protected abstract ObjectGroupAssert<T> 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 ObjectGroupAssert<T> 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

as

protected abstract ObjectGroupAssert<T> as(String description)
Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).as("name").isEqualTo("Frodo");
 

Specified by:
as in class GroupAssert<T>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

protected abstract ObjectGroupAssert<T> describedAs(String description)
Alias for GenericAssert.as(String), 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.

For example:

 assertThat(val).describedAs("name").isEqualTo("Frodo");
 

Specified by:
describedAs in class GroupAssert<T>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

protected abstract ObjectGroupAssert<T> as(Description description)
Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
 

Specified by:
as in class GroupAssert<T>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

protected abstract ObjectGroupAssert<T> describedAs(Description description)
Alias for GenericAssert.as(Description), 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.

For example:

 assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");
 

Specified by:
describedAs in class GroupAssert<T>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

overridingErrorMessage

protected abstract ObjectGroupAssert<T> overridingErrorMessage(String message)
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 class GroupAssert<T>
Parameters:
message - the given error message, which will replace the default one.
Returns:
this assertion.


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