org.fest.assertions
Class ListAssert

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

public class ListAssert
extends ObjectGroupAssert<ListAssert,List<?>>

Assertions for Lists.

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

Since:
1.1
Author:
Alex Ruiz, Yvonne Wang

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual, myself
 
Constructor Summary
protected ListAssert(List<?> actual)
          Creates a new ListAssert.
 
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 List.
 ListAssert contains(Object o, Index index)
          Verifies that the actual List contains the given object at the given index.
 ListAssert containsExactly(Object... objects)
          Verifies that the actual List contains the given objects, in the same order.
 ListAssert containsSequence(Object... sequence)
          Verifies that the actual List contains the given sequence of objects, without any other objects between them.
 ListAssert endsWith(Object... sequence)
          Verifies that the actual List ends with the given sequence of objects, without any other objects between them.
 ListAssert onProperty(String propertyName)
          Creates a new instance of ListAssert whose target list contains the values of the given property name from the elements of this ListAssert's list.
 ListAssert startsWith(Object... sequence)
          Verifies that the actual List starts with the given sequence of objects, without any other objects between them.
 
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

ListAssert

protected ListAssert(List<?> actual)
Creates a new ListAssert.

Parameters:
actual - the target to verify.
Method Detail

contains

public ListAssert contains(Object o,
                           Index index)
Verifies that the actual List contains the given object at the given index.

Parameters:
o - the object to look for.
index - the index where the object should be stored in the actual List.
Returns:
this assertion object.
Throws:
NullPointerException - if the given Index is null.
IndexOutOfBoundsException - if the value of the given Index is negative, or equal to or greater than the size of the actual List.
AssertionError - if the given List does not contain the given object at the given index.

containsSequence

public ListAssert containsSequence(Object... sequence)
Verifies that the actual List contains the given sequence of objects, without any other objects between them.

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

startsWith

public ListAssert startsWith(Object... sequence)
Verifies that the actual List starts with the given sequence of objects, without any other objects between them. Same as containsSequence(java.lang.Object...), but verifies also that first given object is also first element of List.

Parameters:
sequence - the sequence of objects to look for.
Returns:
this assertion object.
Throws:
AssertionError - if the actual List is null.
AssertionError - if the given array is null.
AssertionError - if the actual List is not empty and with the given sequence of objects is empty.
AssertionError - if the actual List does not start with the given sequence of objects.

endsWith

public ListAssert endsWith(Object... sequence)
Verifies that the actual List ends with the given sequence of objects, without any other objects between them. Same as containsSequence(java.lang.Object...), but verifies also that last given object is also last element of List.

Parameters:
sequence - the sequence of objects to look for.
Returns:
this assertion object.
Throws:
AssertionError - if the actual List is null.
AssertionError - if the given array is null.
AssertionError - if the actual List is not empty and with the given sequence of objects is empty.
AssertionError - if the actual List does not end with the given sequence of objects.

actualGroupSize

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

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

containsExactly

public ListAssert containsExactly(Object... objects)
Verifies that the actual List contains the given objects, in the same order. This method works just like #isEqualTo(List), with the difference that internally the given array is converted to a List.

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

onProperty

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

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


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