org.assertj.core.api
Class AbstractListAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>

java.lang.Object
  extended by org.assertj.core.api.AbstractAssert<S,A>
      extended by org.assertj.core.api.AbstractIterableAssert<S,A,T>
          extended by org.assertj.core.api.AbstractListAssert<S,A,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.
A - the type of the "actual" value.
T - the type of elements of the "actual" value.
All Implemented Interfaces:
Assert<S,A>, Descriptable<S>, EnumerableAssert<S,T>, ExtensionPoints<S,A>, IndexedObjectEnumerableAssert<S,T>, ObjectEnumerableAssert<S,T>
Direct Known Subclasses:
ListAssert

public abstract class AbstractListAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
extends AbstractIterableAssert<S,A,T>
implements IndexedObjectEnumerableAssert<S,T>

Base class for all implementations of assertions for Lists.

Author:
Yvonne Wang, Alex Ruiz, Joel Costigliola, Mikhail Mazursky

Field Summary
 
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself
 
Constructor Summary
protected AbstractListAssert(A actual, Class<?> selfType)
           
 
Method Summary
 S contains(T value, Index index)
          Verifies that the actual group contains the given object at the given index.
 S doesNotContain(T value, Index index)
          Verifies that the actual group does not contain the given object at the given index.
 S has(Condition<? super T> condition, Index index)
          Verifies that the actual object at the given index in the actual group satisfies the given condition.
 S is(Condition<? super T> condition, Index index)
          Verifies that the actual object at the given index in the actual group satisfies the given condition.
 S isSorted()
          Verifies that the actual list is sorted into ascending order according to the natural ordering of its elements.
 S isSortedAccordingTo(Comparator<? super T> comparator)
          Verifies that the actual list is sorted according to the given comparator.
Empty lists are considered sorted whatever the comparator is.
One element lists are considered sorted if element is compatible with comparator.
protected  S usingComparisonStrategy(ComparisonStrategy comparisonStrategy)
           
 S usingDefaultElementComparator()
          Revert to standard comparison for incoming assertion group element checks.
 S usingElementComparator(Comparator<? super T> customComparator)
          Use given custom comparator instead of relying on actual type A equals method to compare group elements for incoming assertion checks.
 
Methods inherited from class org.assertj.core.api.AbstractIterableAssert
are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, contains, containsAll, containsExactly, containsExactlyElementsOf, containsNull, containsOnly, containsOnlyElementsOf, containsOnlyOnce, containsSequence, containsSubsequence, doesNotContain, doesNotContainAnyElementsOf, doesNotContainNull, doesNotHaveDuplicates, doNotHave, endsWith, extracting, extracting, extracting, extracting, extractingResultOf, extractingResultOf, flatExtracting, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasSameElementsAs, hasSameSizeAs, hasSameSizeAs, hasSize, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, inBinary, inHexadecimal, isEmpty, isNotEmpty, isNullOrEmpty, isSubsetOf, startsWith, usingElementComparatorIgnoringFields, usingElementComparatorOnFields, usingFieldByFieldElementComparator
 
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.assertj.core.api.ObjectEnumerableAssert
are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, contains, containsAll, containsExactly, containsNull, containsOnly, containsOnlyOnce, containsSequence, containsSubsequence, doesNotContain, doesNotContainNull, doesNotHaveDuplicates, doNotHave, endsWith, hasAtLeastOneElementOfType, hasOnlyElementsOfType, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, startsWith
 
Methods inherited from interface org.assertj.core.api.EnumerableAssert
hasSameSizeAs, hasSameSizeAs, hasSize, isEmpty, isNotEmpty, isNullOrEmpty
 

Constructor Detail

AbstractListAssert

protected AbstractListAssert(A actual,
                             Class<?> selfType)
Method Detail

contains

public S contains(T value,
                  Index index)
Verifies that the actual group contains the given object at the given index.

Specified by:
contains in interface IndexedObjectEnumerableAssert<S extends AbstractListAssert<S,A,T>,T>
Parameters:
value - the object to look for.
index - the index where the object should be stored in the actual group.
Returns:
this assertion object.

doesNotContain

public S doesNotContain(T value,
                        Index index)
Verifies that the actual group does not contain the given object at the given index.

Specified by:
doesNotContain in interface IndexedObjectEnumerableAssert<S extends AbstractListAssert<S,A,T>,T>
Parameters:
value - the object to look for.
index - the index where the object should be stored in the actual group.
Returns:
this assertion object.

has

public S has(Condition<? super T> condition,
             Index index)
Verifies that the actual object at the given index in the actual group satisfies the given condition.

Parameters:
condition - the given condition.
index - the index where the object should be stored in the actual group.
Returns:
this assertion object.
Throws:
AssertionError - if the given List is null or empty.
NullPointerException - if the given Index is null.
IndexOutOfBoundsException - if the value of the given Index is equal to or greater than the size of the given List.
NullPointerException - if the given Condition is null.
AssertionError - if the value in the given List at the given index does not satisfy the given Condition .

is

public S is(Condition<? super T> condition,
            Index index)
Verifies that the actual object at the given index in the actual group satisfies the given condition.

Parameters:
condition - the given condition.
index - the index where the object should be stored in the actual group.
Returns:
this assertion object.
Throws:
AssertionError - if the given List is null or empty.
NullPointerException - if the given Index is null.
IndexOutOfBoundsException - if the value of the given Index is equal to or greater than the size of the given List.
NullPointerException - if the given Condition is null.
AssertionError - if the value in the given List at the given index does not satisfy the given Condition .

isSorted

public S isSorted()
Verifies that the actual list is sorted into ascending order according to the natural ordering of its elements.

All list elements must implement the Comparable interface and must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the list), examples :

Empty lists are considered sorted.
Unique element lists are considered sorted unless the element type is not Comparable.

Returns:
this assertion object.
Throws:
AssertionError - if the actual list is not sorted into ascending order according to the natural ordering of its elements.
AssertionError - if the actual list is null.
AssertionError - if the actual list element type does not implement Comparable.
AssertionError - if the actual list elements are not mutually Comparable.

isSortedAccordingTo

public S isSortedAccordingTo(Comparator<? super T> comparator)
Verifies that the actual list is sorted according to the given comparator.
Empty lists are considered sorted whatever the comparator is.
One element lists are considered sorted if element is compatible with comparator.

Parameters:
comparator - the Comparator used to compare list elements
Returns:
this assertion object.
Throws:
AssertionError - if the actual list is not sorted according to the given comparator.
AssertionError - if the actual list is null.
NullPointerException - if the given comparator is null.
AssertionError - if the actual list elements are not mutually comparable according to given Comparator.

usingElementComparator

public S usingElementComparator(Comparator<? super T> customComparator)
Description copied from class: AbstractIterableAssert
Use given custom comparator instead of relying on actual type A equals method to compare group elements 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.

Examples :

 // 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 falls back to standard comparison strategy 
 // based on Invoice's equal method to compare invoiceList elements to lowestInvoice.                                                      
 assertThat(invoiceList).contains(lowestInvoice).
 
 // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ...
 assertThat(fellowshipOfTheRing).contains(gandalf)
                                .doesNotContain(sauron);
 
 // ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf.
 assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator)
                                .contains(sauron);
 

Specified by:
usingElementComparator in interface EnumerableAssert<S extends AbstractListAssert<S,A,T>,T>
Overrides:
usingElementComparator in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
Parameters:
customComparator - the comparator to use for incoming assertion checks.
Returns:
this assertion object.

usingDefaultElementComparator

public S usingDefaultElementComparator()
Description copied from class: AbstractIterableAssert
Revert to standard comparison for incoming assertion group element checks.

This method should be used to disable a custom comparison strategy set by calling EnumerableAssert.usingElementComparator(Comparator).

Specified by:
usingDefaultElementComparator in interface EnumerableAssert<S extends AbstractListAssert<S,A,T>,T>
Overrides:
usingDefaultElementComparator in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
Returns:
this assertion object.

usingComparisonStrategy

protected S usingComparisonStrategy(ComparisonStrategy comparisonStrategy)
Overrides:
usingComparisonStrategy in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>


Copyright © 2013–2015 AssertJ. All rights reserved.