org.fest.assertions.api
Class AbstractIterableAssert<S,A extends Iterable<?>>

java.lang.Object
  extended by org.fest.assertions.api.AbstractAssert<S,A>
      extended by org.fest.assertions.api.AbstractIterableAssert<S,A>
Type Parameters:
S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
A - the type of the "actual" value.
All Implemented Interfaces:
Assert<S,A>, Descriptable<S>, EnumerableAssert<S>, ExtensionPoints<S,A>, ObjectEnumerableAssert<S>
Direct Known Subclasses:
IterableAssert, ListAssert

public abstract class AbstractIterableAssert<S,A extends Iterable<?>>
extends AbstractAssert<S,A>
implements ObjectEnumerableAssert<S>

Base class for implementations of ObjectEnumerableAssert whose actual value type is Collection.

Author:
Yvonne Wang, Alex Ruiz, Mathieu Baechler, Joel Costigliola, Maciej Jaskowski, Nicolas François

Field Summary
 
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
 
Constructor Summary
protected AbstractIterableAssert(A actual, Class<S> selfType)
           
 
Method Summary
<E> S
are(Condition<E> condition)
          Verifies that each element value satisfies the given condition
<E> S
areAtLeast(int times, Condition<E> condition)
          Verifies that there is at least n elements in the actual group satisfying the given condition.
<E> S
areAtMost(int times, Condition<E> condition)
          Verifies that there is at most n elements in the actual group satisfying the given condition.
<E> S
areExactly(int times, Condition<E> condition)
          Verifies that there is exactly n elements in the actual group satisfying the given condition.
<E> S
areNot(Condition<E> condition)
          Verifies that each element value not satisfies the given condition
<E> S
areNotAtLeast(int times, Condition<E> condition)
          Verifies that there is at least n elements in the actual group not satisfying the given condition.
<E> S
areNotAtMost(int times, Condition<E> condition)
          Verifies that there is at most n elements in the actual group not satisfying the given condition.
<E> S
areNotExactly(int times, Condition<E> condition)
          Verifies that there is exactly n elements in the actual group not satisfying the given condition.
 S contains(Object... values)
          Verifies that the actual group contains the given values, in any order.
 S containsNull()
          Verifies that the actual group contains at least a null element.
 S containsOnly(Object... values)
          Verifies that the actual group contains only the given values and nothing else, in any order.
 S containsSequence(Object... sequence)
          Verifies that the actual group contains the given sequence, without any other values between them.
 S doesNotContain(Object... values)
          Verifies that the actual group does not contain the given values.
 S doesNotContainNull()
          Verifies that the actual group does not contain null elements.
 S doesNotHaveDuplicates()
          Verifies that the actual group does not contain duplicates.
<E> S
doNotHave(Condition<E> condition)
          Verifies that each element value not satisfies the given condition
<E> S
doNotHaveAtLeast(int times, Condition<E> condition)
          This method is an alias ObjectEnumerableAssert.areNotAtLeast(int, Condition).
<E> S
doNotHaveAtMost(int times, Condition<E> condition)
          This method is an alias ObjectEnumerableAssert.areNotAtMost(int, Condition).
<E> S
doNotHaveExactly(int times, Condition<E> condition)
          This method is an alias ObjectEnumerableAssert.areNotExactly(int, Condition).
 S endsWith(Object... sequence)
          Verifies that the actual group ends with the given sequence of objects, without any other objects between them.
 S hasSize(int expected)
          Verifies that the number of values in the actual group is equal to the given one.
<E> S
have(Condition<E> condition)
          Verifies that each element value satisfies the given condition
<E> S
haveAtLeast(int times, Condition<E> condition)
          This method is an alias for ObjectEnumerableAssert.areAtLeast(int, Condition).
<E> S
haveAtMost(int times, Condition<E> condition)
          This method is an alias ObjectEnumerableAssert.areAtMost(int, Condition).
<E> S
haveExactly(int times, Condition<E> condition)
          This method is an alias ObjectEnumerableAssert.areExactly(int, Condition).
 void isEmpty()
          Verifies that the actual group of values is empty.
 S isNotEmpty()
          Verifies that the actual group of values is not empty.
 void isNullOrEmpty()
          Verifies that the actual group of values is null or empty.
 S isSubsetOf(Iterable<?> values)
          Verifies that all the elements of the actual Iterable are present in the given Iterable.
 S startsWith(Object... sequence)
          Verifies that the actual group starts with the given sequence of objects, without any other objects between them.
 S usingComparator(Comparator<?> customComparator)
          Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
 S usingDefaultComparator()
          Revert to standard comparison for incoming assertion checks.
 
Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, equals, has, hashCode, is, isEqualTo, isIn, isIn, isNot, isNotEqualTo, isNotIn, isNotIn, isNotNull, isNotSameAs, isNull, isSameAs
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractIterableAssert

protected AbstractIterableAssert(A actual,
                                 Class<S> selfType)
Method Detail

isNullOrEmpty

public final void isNullOrEmpty()
Verifies that the actual group of values is null or empty.

Specified by:
isNullOrEmpty in interface EnumerableAssert<S>

isEmpty

public final void isEmpty()
Verifies that the actual group of values is empty.

Specified by:
isEmpty in interface EnumerableAssert<S>

isNotEmpty

public final S isNotEmpty()
Verifies that the actual group of values is not empty.

Specified by:
isNotEmpty in interface EnumerableAssert<S>
Returns:
this assertion object.

hasSize

public final S hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.

Specified by:
hasSize in interface EnumerableAssert<S>
Parameters:
expected - the expected number of values in the actual group.
Returns:
this assertion object.

contains

public final S contains(Object... values)
Verifies that the actual group contains the given values, in any order.

Specified by:
contains in interface ObjectEnumerableAssert<S>
Parameters:
values - the given values.
Returns:
this assertion object.

containsOnly

public final S containsOnly(Object... values)
Verifies that the actual group contains only the given values and nothing else, in any order.

Specified by:
containsOnly in interface ObjectEnumerableAssert<S>
Parameters:
values - the given values.
Returns:
this assertion object.

isSubsetOf

public final S isSubsetOf(Iterable<?> values)
Verifies that all the elements of the actual Iterable are present in the given Iterable.

Parameters:
values - the Iterable that should contain all actual elements.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Iterable is null.
NullPointerException - if the given Iterable is null.
AssertionError - if the actual Iterable is not subset of set Iterable.

containsSequence

public final S containsSequence(Object... sequence)
Verifies that the actual group contains the given sequence, without any other values between them.

Specified by:
containsSequence in interface ObjectEnumerableAssert<S>
Parameters:
sequence - the sequence of objects to look for.
Returns:
this assertion object.

doesNotContain

public final S doesNotContain(Object... values)
Verifies that the actual group does not contain the given values.

Specified by:
doesNotContain in interface ObjectEnumerableAssert<S>
Parameters:
values - the given values.
Returns:
this assertion object.

doesNotHaveDuplicates

public final S doesNotHaveDuplicates()
Verifies that the actual group does not contain duplicates.

Specified by:
doesNotHaveDuplicates in interface ObjectEnumerableAssert<S>
Returns:
this assertion object.

startsWith

public final S startsWith(Object... sequence)
Verifies that the actual group starts with the given sequence of objects, without any other objects between them. Similar to ObjectEnumerableAssert.containsSequence(Object...), but it also verifies that the first element in the sequence is also first element of the actual group.

Specified by:
startsWith in interface ObjectEnumerableAssert<S>
Parameters:
sequence - the sequence of objects to look for.
Returns:
this assertion object.

endsWith

public final S endsWith(Object... sequence)
Verifies that the actual group ends with the given sequence of objects, without any other objects between them. Similar to ObjectEnumerableAssert.containsSequence(Object...), but it also verifies that the last element in the sequence is also last element of the actual group.

Specified by:
endsWith in interface ObjectEnumerableAssert<S>
Parameters:
sequence - the sequence of objects to look for.
Returns:
this assertion object.

containsNull

public S containsNull()
Verifies that the actual group contains at least a null element.

Specified by:
containsNull in interface ObjectEnumerableAssert<S>
Returns:
this assertion object.

doesNotContainNull

public S doesNotContainNull()
Verifies that the actual group does not contain null elements.

Specified by:
doesNotContainNull in interface ObjectEnumerableAssert<S>
Returns:
this assertion object.

are

public <E> S are(Condition<E> condition)
Verifies that each element value satisfies the given condition

Specified by:
are in interface ObjectEnumerableAssert<S>
Parameters:
condition - the given condition.
Returns:
this object.

areNot

public <E> S areNot(Condition<E> condition)
Verifies that each element value not satisfies the given condition

Specified by:
areNot in interface ObjectEnumerableAssert<S>
Parameters:
condition - the given condition.
Returns:
this object.

have

public <E> S have(Condition<E> condition)
Verifies that each element value satisfies the given condition

Specified by:
have in interface ObjectEnumerableAssert<S>
Parameters:
condition - the given condition.
Returns:
this object.

doNotHave

public <E> S doNotHave(Condition<E> condition)
Verifies that each element value not satisfies the given condition

Specified by:
doNotHave in interface ObjectEnumerableAssert<S>
Parameters:
condition - the given condition.
Returns:
this object.

areAtLeast

public <E> S areAtLeast(int times,
                        Condition<E> condition)
Verifies that there is at least n elements in the actual group satisfying the given condition.

Specified by:
areAtLeast in interface ObjectEnumerableAssert<S>
Parameters:
times - the minimum number of times the condition should be verified.
condition - the given condition.
Returns:
this object.

areNotAtLeast

public <E> S areNotAtLeast(int times,
                           Condition<E> condition)
Verifies that there is at least n elements in the actual group not satisfying the given condition.

Specified by:
areNotAtLeast in interface ObjectEnumerableAssert<S>
Parameters:
times - the number of times the condition should not be verified at least.
condition - the given condition.
Returns:
this object.

areAtMost

public <E> S areAtMost(int times,
                       Condition<E> condition)
Verifies that there is at most n elements in the actual group satisfying the given condition.

Specified by:
areAtMost in interface ObjectEnumerableAssert<S>
Parameters:
times - the number of times the condition should be at most verified.
condition - the given condition.
Returns:
this object.

areNotAtMost

public <E> S areNotAtMost(int times,
                          Condition<E> condition)
Verifies that there is at most n elements in the actual group not satisfying the given condition.

Specified by:
areNotAtMost in interface ObjectEnumerableAssert<S>
Parameters:
times - the number of times the condition should not be verified at most.
condition - the given condition.
Returns:
this object.

areExactly

public <E> S areExactly(int times,
                        Condition<E> condition)
Verifies that there is exactly n elements in the actual group satisfying the given condition.

Specified by:
areExactly in interface ObjectEnumerableAssert<S>
Parameters:
times - the exact number of times the condition should be verified.
condition - the given condition.
Returns:
this object.

areNotExactly

public <E> S areNotExactly(int times,
                           Condition<E> condition)
Verifies that there is exactly n elements in the actual group not satisfying the given condition.

Specified by:
areNotExactly in interface ObjectEnumerableAssert<S>
Parameters:
times - the exact number of times the condition should not be verified.
condition - the given condition.
Returns:
this object.

haveAtLeast

public <E> S haveAtLeast(int times,
                         Condition<E> condition)
This method is an alias for ObjectEnumerableAssert.areAtLeast(int, Condition).

Specified by:
haveAtLeast in interface ObjectEnumerableAssert<S>

doNotHaveAtLeast

public <E> S doNotHaveAtLeast(int times,
                              Condition<E> condition)
This method is an alias ObjectEnumerableAssert.areNotAtLeast(int, Condition).

Specified by:
doNotHaveAtLeast in interface ObjectEnumerableAssert<S>

haveAtMost

public <E> S haveAtMost(int times,
                        Condition<E> condition)
This method is an alias ObjectEnumerableAssert.areAtMost(int, Condition).

Specified by:
haveAtMost in interface ObjectEnumerableAssert<S>

doNotHaveAtMost

public <E> S doNotHaveAtMost(int times,
                             Condition<E> condition)
This method is an alias ObjectEnumerableAssert.areNotAtMost(int, Condition).

Specified by:
doNotHaveAtMost in interface ObjectEnumerableAssert<S>

haveExactly

public <E> S haveExactly(int times,
                         Condition<E> condition)
This method is an alias ObjectEnumerableAssert.areExactly(int, Condition).

Specified by:
haveExactly in interface ObjectEnumerableAssert<S>

doNotHaveExactly

public <E> S doNotHaveExactly(int times,
                              Condition<E> condition)
This method is an alias ObjectEnumerableAssert.areNotExactly(int, Condition).

Specified by:
doNotHaveExactly in interface ObjectEnumerableAssert<S>

usingComparator

public S usingComparator(Comparator<?> customComparator)
Description copied from class: AbstractAssert
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.

Example :
 // compares invoices by payee 
 assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList).
 
 // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator
 assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice)
 
 // as assertThat(invoiceList) creates a new assertion, it uses standard comparison strategy (Invoice's equal method) to compare invoiceList elements to lowestInvoice.                                                      
 assertThat(invoiceList).contains(lowestInvoice).
 
Custom comparator is not parameterized with actual type A (ie. Comparator<A>) because if it was, we could not write the following code :
 // frodo and sam are instances of Character (a Character having a Race)
 // raceComparator implements Comparator<Character> 
 // assertThat(frodo) returns an ObjectAssert and not a custom CharacterAssert implementing Assert<CharacterAssert, Character>  
 assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam); // won't compile !
 
 The code does not compile because assertThat(frodo) returns an ObjectAssert, thus usingComparator expects a Comparator<Object> 
 and Comparator<Character> is not a Comparator<Object> as generics are not reified.
 
 Note that, it would have worked if assertThat(frodo) returned a CharacterAssert implementing Assert<CharacterAssert, Character>. 
 

Specified by:
usingComparator in interface Assert<S,A extends Iterable<?>>
Overrides:
usingComparator in class AbstractAssert<S,A extends Iterable<?>>
Parameters:
customComparator - the comparator to use for incoming assertion checks.
Returns:
this assertion object.

usingDefaultComparator

public S usingDefaultComparator()
Description copied from class: AbstractAssert
Revert to standard comparison for incoming assertion checks.
This method should be used to disable a custom comparison strategy set by calling Assert.usingComparator(Comparator).

Specified by:
usingDefaultComparator in interface Assert<S,A extends Iterable<?>>
Overrides:
usingDefaultComparator in class AbstractAssert<S,A extends Iterable<?>>
Returns:
this assertion object.


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