org.assertj.core.api
Interface ObjectEnumerableAssert<S extends ObjectEnumerableAssert<S,T>,T>

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.
T - the type of elements of the "actual" value.
All Superinterfaces:
EnumerableAssert<S,T>
All Known Subinterfaces:
IndexedObjectEnumerableAssert<S,T>
All Known Implementing Classes:
AbstractIterableAssert, AbstractListAssert, AbstractObjectArrayAssert, IterableAssert, ListAssert, ObjectArrayAssert

public interface ObjectEnumerableAssert<S extends ObjectEnumerableAssert<S,T>,T>
extends EnumerableAssert<S,T>

Assertions methods applicable to groups of objects (e.g. arrays or collections.)

Author:
Yvonne Wang, Alex Ruiz, Nicolas François, Mikhail Mazursky, Joel Costigliola, Nicolas François

Method Summary
 S are(Condition<? super T> condition)
          Verifies that each element value satisfies the given condition
 S areAtLeast(int n, Condition<? super T> condition)
          Verifies that there is at least n elements in the actual group satisfying the given condition.
 S areAtLeastOne(Condition<? super T> condition)
          Verifies that there is at least one element in the actual group satisfying the given condition.
 S areAtMost(int n, Condition<? super T> condition)
          Verifies that there is at most n elements in the actual group satisfying the given condition.
 S areExactly(int n, Condition<? super T> condition)
          Verifies that there is exactly n elements in the actual group satisfying the given condition.
 S areNot(Condition<? super T> condition)
          Verifies that each element value does not satisfy the given condition
 S contains(T... values)
          Verifies that the actual group contains the given values, in any order.
 S containsAll(Iterable<? extends T> iterable)
          Verifies that the actual group contains all the elements of given Iterable, in any order.
 S containsExactly(T... values)
          Verifies that the actual group contains only the given values and nothing else, in order.
This assertion should only be used with group that have a consistent iteration order (i.e.
 S containsNull()
          Verifies that the actual group contains at least a null element.
 S containsOnly(T... values)
          Verifies that the actual group contains only the given values and nothing else, in any order.
 S containsOnlyOnce(T... values)
          Verifies that the actual array contains the given values only once.
 S containsSequence(T... sequence)
          Verifies that the actual group contains the given sequence, without any other values between them.
 S containsSubsequence(T... sequence)
          Verifies that the actual group contains the given subsequence (possibly with other values between them).
 S doesNotContain(T... 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.
 S doNotHave(Condition<? super T> condition)
          Verifies that each element value does not satisfy the given condition
 S endsWith(T... sequence)
          Verifies that the actual group ends with the given sequence of objects, without any other objects between them.
 S hasAtLeastOneElementOfType(Class<?> expectedType)
          Verifies that at least one element in the actual Object group belong to the specified type (matching includes subclasses of the given type).
 S hasOnlyElementsOfType(Class<?> expectedType)
          Verifies that all the elements in the actual Object group belong to the specified type (matching includes subclasses of the given type).
 S have(Condition<? super T> condition)
          Verifies that each element value satisfies the given condition
 S haveAtLeast(int n, Condition<? super T> condition)
          Verifies that there is at least n elements in the actual group satisfying the given condition.
 S haveAtLeastOne(Condition<? super T> condition)
          Verifies that there is at least one element in the actual group satisfying the given condition.
 S haveAtMost(int n, Condition<? super T> condition)
          This method is an alias areAtMost(int, Condition).
 S haveExactly(int n, Condition<? super T> condition)
          This method is an alias areExactly(int, Condition).
 S startsWith(T... sequence)
          Verifies that the actual group starts with the given sequence of objects, without any other objects between them.
 
Methods inherited from interface org.assertj.core.api.EnumerableAssert
hasSameSizeAs, hasSameSizeAs, hasSize, isEmpty, isNotEmpty, isNullOrEmpty, usingDefaultElementComparator, usingElementComparator
 

Method Detail

contains

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

Parameters:
values - the given values.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual group is null.
AssertionError - if the actual group does not contain the given values.

containsOnly

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

Parameters:
values - the given values.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual group is null.
AssertionError - if the actual group does not contain the given values, i.e. the actual group contains some or none of the given values, or the actual group contains more values than the given ones.

containsOnlyOnce

S containsOnlyOnce(T... values)
Verifies that the actual array contains the given values only once.

Examples :

 // assertion will pass
 assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("winter");
 assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("coming", "winter");
 
 // assertions will fail
 assertThat(newArrayList("Aria", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark");
 assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("Lannister");
 assertThat(newArrayList("Aria", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark", "Lannister",
                                                                                              "Aria");
 

Parameters:
values - the given values.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual group is null.
AssertionError - if the actual group does not contain the given values, i.e. the actual group contains some or none of the given values, or the actual group contains more than once these values.

containsExactly

S containsExactly(T... values)
Verifies that the actual group contains only the given values and nothing else, in order.
This assertion should only be used with group that have a consistent iteration order (i.e. don't use it with HashSet, prefer containsOnly(Object...) in that case).

Example :

 Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
 
 // assertion will pass
 assertThat(elvesRings).containsExactly(vilya, nenya, narya);
 
 // assertion will fail as actual and expected orders differ.
 assertThat(elvesRings).containsExactly(nenya, vilya, narya);
 

Parameters:
values - the given values.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
AssertionError - if the actual group is null.
AssertionError - if the actual group does not contain the given values with same order, i.e. the actual group contains some or none of the given values, or the actual group contains more values than the given ones or values are the same but the order is not.

containsSequence

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

 Example:
 Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
 
 // assertion will pass
 assertThat(elvesRings).containsSequence(vilya, nenya);
 
 // assertion will fail
 assertThat(elvesRings).containsSequence(vilya, narya);
 assertThat(elvesRings).containsSequence(nenya, vilya);
 

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

containsSubsequence

S containsSubsequence(T... sequence)
Verifies that the actual group contains the given subsequence (possibly with other values between them).

 Example:
 Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
 
 // assertion will pass
 assertThat(elvesRings).containsSubsequence(vilya, nenya);
 assertThat(elvesRings).containsSubsequence(vilya, narya);
 
 // assertion will fail
 assertThat(elvesRings).containsSubsequence(nenya, vilya);
 

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

doesNotContain

S doesNotContain(T... values)
Verifies that the actual group does not contain the given values.

Parameters:
values - the given values.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual group is null.
AssertionError - if the actual group contains any of the given values.

doesNotHaveDuplicates

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

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

startsWith

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

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

endsWith

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

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

containsNull

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

Returns:
this assertion object.
Throws:
AssertionError - if the actual group is null.
AssertionError - if the actual group does not contain a null element.

doesNotContainNull

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

Returns:
this assertion object.
Throws:
AssertionError - if the actual group is null.
AssertionError - if the actual group contains a null element.

are

S are(Condition<? super T> condition)
Verifies that each element value satisfies the given condition

Parameters:
condition - the given condition.
Returns:
this object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if one or more element not satisfy the given condition.

areNot

S areNot(Condition<? super T> condition)
Verifies that each element value does not satisfy the given condition

Parameters:
condition - the given condition.
Returns:
this object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if one or more element satisfy the given condition.

have

S have(Condition<? super T> condition)
Verifies that each element value satisfies the given condition

Parameters:
condition - the given condition.
Returns:
this object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if one or more element not satisfy the given condition.

doNotHave

S doNotHave(Condition<? super T> condition)
Verifies that each element value does not satisfy the given condition

Parameters:
condition - the given condition.
Returns:
this object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if one or more element satisfy the given condition.

areAtLeast

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

Parameters:
n - the minimum number of times the condition should be verified.
condition - the given condition.
Returns:
this object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if an element can not be cast to E.
AssertionError - if the number of elements satisfying the given condition is < n.

areAtLeastOne

S areAtLeastOne(Condition<? super T> condition)
Verifies that there is at least one element in the actual group satisfying the given condition.

This method is an alias for areAtLeast(1, condition).

Example:

 // jedi is a Condition<String>
 assertThat(newLinkedHashSet("Luke", "Solo", "Leia")).areAtLeastOne(jedi);
 

See Also:
haveAtLeast(int, Condition)

areAtMost

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

Parameters:
n - the number of times the condition should be at most verified.
condition - the given condition.
Returns:
this object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if the number of elements satisfying the given condition is > n.

areExactly

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

Parameters:
n - the exact number of times the condition should be verified.
condition - the given condition.
Returns:
this object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if the number of elements satisfying the given condition is ≠ n.

haveAtLeastOne

S haveAtLeastOne(Condition<? super T> condition)
Verifies that there is at least one element in the actual group satisfying the given condition.

This method is an alias for haveAtLeast(1, condition).

Example:

 List<BasketBallPlayer> bullsPlayers = newArrayList(noah, rose);
 
 // potentialMvp is a Condition<BasketBallPlayer>
 assertThat(bullsPlayers).haveAtLeastOne(potentialMvp);
 

See Also:
haveAtLeast(int, Condition)

haveAtLeast

S haveAtLeast(int n,
              Condition<? super T> condition)
Verifies that there is at least n elements in the actual group satisfying the given condition.

This method is an alias for areAtLeast(int, Condition).


haveAtMost

S haveAtMost(int n,
             Condition<? super T> condition)
This method is an alias areAtMost(int, Condition).


haveExactly

S haveExactly(int n,
              Condition<? super T> condition)
This method is an alias areExactly(int, Condition).


containsAll

S containsAll(Iterable<? extends T> iterable)
Verifies that the actual group contains all the elements of given Iterable, in any order.

Parameters:
iterable - the given Iterable we will get elements from.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
AssertionError - if the actual group is null.
AssertionError - if the actual group does not contain all the elements of given Iterable.

hasAtLeastOneElementOfType

S hasAtLeastOneElementOfType(Class<?> expectedType)
Verifies that at least one element in the actual Object group belong to the specified type (matching includes subclasses of the given type).

Example:

 Number[] numbers = { 2, 6L, 8.0 };
 
 // successful assertion:
 assertThat(numbers).hasAtLeastOneElementOfType(Long.class);
 
 // assertion failure:
 assertThat(numbers).hasAtLeastOneElementOfType(Float.class);
 

Parameters:
expectedType - the expected type.
Returns:
this assertion object.
Throws:
NullPointerException - if the given type is null.
AssertionError - if the actual Object group does not have any elements of the given type.

hasOnlyElementsOfType

S hasOnlyElementsOfType(Class<?> expectedType)
Verifies that all the elements in the actual Object group belong to the specified type (matching includes subclasses of the given type).

Example:

 Number[] numbers = { 2, 6, 8 };
 
 // successful assertion:
 assertThat(numbers).hasOnlyElementsOfType(Integer.class);
 
 // assertion failure:
 assertThat(numbers).hasOnlyElementsOfType(Long.class);
 

Parameters:
expectedType - the expected type.
Returns:
this assertion object.
Throws:
NullPointerException - if the given type is null.
AssertionError - if one element is not of the expected type.


Copyright © 2013–2015 AssertJ. All rights reserved.