Package org.fest.assertions.api
Class ListAssert<T>
- java.lang.Object
-
- org.fest.assertions.api.AbstractAssert<S,A>
-
- org.fest.assertions.api.AbstractIterableAssert<ListAssert<T>,java.util.List<T>,T>
-
- org.fest.assertions.api.ListAssert<T>
-
- Type Parameters:
T
- the type of elements of the "actual" value.
- All Implemented Interfaces:
Assert<ListAssert<T>,java.util.List<T>>
,Descriptable<ListAssert<T>>
,EnumerableAssert<ListAssert<T>,T>
,ExtensionPoints<ListAssert<T>,java.util.List<T>>
,IndexedObjectEnumerableAssert<ListAssert<T>,T>
,ObjectEnumerableAssert<ListAssert<T>,T>
public class ListAssert<T> extends AbstractIterableAssert<ListAssert<T>,java.util.List<T>,T> implements IndexedObjectEnumerableAssert<ListAssert<T>,T>
Assertion methods for
s.List
To create an instance of this class, invoke
.Assertions.assertThat(List)
- Author:
- Yvonne Wang, Alex Ruiz, Joel Costigliola, Mikhail Mazursky
-
-
Field Summary
-
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ListAssert(java.util.List<T> actual)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ListAssert<T>
contains(T value, Index index)
Verifies that the actual group contains the given object at the given index.ListAssert<T>
doesNotContain(T value, Index index)
Verifies that the actual group does not contain the given object at the given index.ListAssert<T>
has(Condition<? super T> condition, Index index)
Verifies that the actual object at the given index in the actual group satisfies the given condition.ListAssert<T>
is(Condition<? super T> condition, Index index)
Verifies that the actual object at the given index in the actual group satisfies the given condition.ListAssert<T>
isSorted()
Verifies that the actual list is sorted into ascending order according to the natural ordering of its elements.ListAssert<T>
isSortedAccordingTo(java.util.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.ListAssert<T>
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.ListAssert<T>
usingElementComparator(java.util.Comparator<? super T> customComparator)
Use given custom comparator instead of relying on actual type Aequals
method to compare group elements for incoming assertion checks.-
Methods inherited from class org.fest.assertions.api.AbstractIterableAssert
are, areAtLeast, areAtMost, areExactly, areNot, areNotAtLeast, areNotAtMost, areNotExactly, contains, containsAll, containsExactly, containsNull, containsOnly, containsSequence, doesNotContain, doesNotContainNull, doesNotHaveDuplicates, doNotHave, doNotHaveAtLeast, doNotHaveAtMost, doNotHaveExactly, endsWith, hasSameSizeAs, hasSameSizeAs, hasSize, have, haveAtLeast, haveAtMost, haveExactly, isEmpty, isNotEmpty, isNullOrEmpty, isSubsetOf, startsWith
-
Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, 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.fest.assertions.core.EnumerableAssert
hasSameSizeAs, hasSameSizeAs, hasSize, isEmpty, isNotEmpty, isNullOrEmpty
-
Methods inherited from interface org.fest.assertions.core.ObjectEnumerableAssert
are, areAtLeast, areAtMost, areExactly, areNot, areNotAtLeast, areNotAtMost, areNotExactly, contains, containsAll, containsExactly, containsNull, containsOnly, containsSequence, doesNotContain, doesNotContainNull, doesNotHaveDuplicates, doNotHave, doNotHaveAtLeast, doNotHaveAtMost, doNotHaveExactly, endsWith, have, haveAtLeast, haveAtMost, haveExactly, startsWith
-
-
-
-
Constructor Detail
-
ListAssert
protected ListAssert(java.util.List<T> actual)
-
-
Method Detail
-
contains
public ListAssert<T> contains(T value, Index index)
Verifies that the actual group contains the given object at the given index.- Specified by:
contains
in interfaceIndexedObjectEnumerableAssert<ListAssert<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 ListAssert<T> doesNotContain(T value, Index index)
Verifies that the actual group does not contain the given object at the given index.- Specified by:
doesNotContain
in interfaceIndexedObjectEnumerableAssert<ListAssert<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 ListAssert<T> 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:
java.lang.AssertionError
- if the givenList
isnull
or empty.java.lang.NullPointerException
- if the givenIndex
isnull
.java.lang.IndexOutOfBoundsException
- if the value of the givenIndex
is equal to or greater than the size of the givenList
.java.lang.NullPointerException
- if the givenCondition
isnull
.java.lang.AssertionError
- if the value in the givenList
at the given index does not satisfy the givenCondition
.
-
is
public ListAssert<T> 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:
java.lang.AssertionError
- if the givenList
isnull
or empty.java.lang.NullPointerException
- if the givenIndex
isnull
.java.lang.IndexOutOfBoundsException
- if the value of the givenIndex
is equal to or greater than the size of the givenList
.java.lang.NullPointerException
- if the givenCondition
isnull
.java.lang.AssertionError
- if the value in the givenList
at the given index does not satisfy the givenCondition
.
-
isSorted
public ListAssert<T> 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 :- a list composed of {"a1", "a2", "a3"} is ok because the element type (String) is Comparable
- a list composed of Rectangle {r1, r2, r3} is NOT ok because Rectangle is not Comparable
- a list composed of {True, "abc", False} is NOT ok because elements are not mutually comparable
- Returns:
this
assertion object.- Throws:
java.lang.AssertionError
- if the actual list is not sorted into ascending order according to the natural ordering of its elements.java.lang.AssertionError
- if the actual list isnull
.java.lang.AssertionError
- if the actual list element type does not implementComparable
.java.lang.AssertionError
- if the actual list elements are not mutuallyComparable
.
-
isSortedAccordingTo
public ListAssert<T> isSortedAccordingTo(java.util.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
- theComparator
used to compare list elements- Returns:
this
assertion object.- Throws:
java.lang.AssertionError
- if the actual list is not sorted according to the given comparator.java.lang.AssertionError
- if the actual list isnull
.java.lang.NullPointerException
- if the given comparator isnull
.java.lang.AssertionError
- if the actual list elements are not mutually comparable according to given Comparator.
-
usingElementComparator
public ListAssert<T> usingElementComparator(java.util.Comparator<? super T> customComparator)
Description copied from class:AbstractIterableAssert
Use given custom comparator instead of relying on actual type Aequals
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 interfaceEnumerableAssert<ListAssert<T>,T>
- Overrides:
usingElementComparator
in classAbstractIterableAssert<ListAssert<T>,java.util.List<T>,T>
- Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultElementComparator
public ListAssert<T> 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 interfaceEnumerableAssert<ListAssert<T>,T>
- Overrides:
usingDefaultElementComparator
in classAbstractIterableAssert<ListAssert<T>,java.util.List<T>,T>
- Returns:
this
assertion object.
-
-