Package org.fest.assertions.internal
Class Lists
- java.lang.Object
-
- org.fest.assertions.internal.Lists
-
public class Lists extends java.lang.Object
Reusable assertions for
s.List
- Author:
- Alex Ruiz, Yvonne Wang, Joel Costigliola
-
-
Constructor Summary
Constructors Constructor Description Lists(ComparisonStrategy comparisonStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertContains(AssertionInfo info, java.util.List<?> actual, java.lang.Object value, Index index)
Verifies that the givenList
contains the given object at the given index.void
assertDoesNotContain(AssertionInfo info, java.util.List<?> actual, java.lang.Object value, Index index)
Verifies that the givenList
does not contain the given object at the given index.<T> void
assertHas(AssertionInfo info, java.util.List<T> actual, Condition<? super T> condition, Index index)
Verifies that the givenList
satisfies the given
at the given index.Condition
<T> void
assertIs(AssertionInfo info, java.util.List<T> actual, Condition<? super T> condition, Index index)
Verifies that the givenList
satisfies the given
at the given index.Condition
void
assertIsSorted(AssertionInfo info, java.util.List<?> actual)
Verifies that the actual list is sorted into ascending order according to the natural ordering of its elements.void
assertIsSortedAccordingToComparator(AssertionInfo info, java.util.List<?> actual, java.util.Comparator<? extends java.lang.Object> 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.java.util.Comparator<?>
getComparator()
static Lists
instance()
Returns the singleton instance of this class.
-
-
-
Constructor Detail
-
Lists
public Lists(ComparisonStrategy comparisonStrategy)
-
-
Method Detail
-
instance
public static Lists instance()
Returns the singleton instance of this class.- Returns:
- the singleton instance of this class.
-
getComparator
public java.util.Comparator<?> getComparator()
-
assertContains
public void assertContains(AssertionInfo info, java.util.List<?> actual, java.lang.Object value, Index index)
Verifies that the givenList
contains the given object at the given index.- Parameters:
info
- contains information about the assertion.actual
- the givenList
.value
- the object to look for.index
- the index where the object should be stored in the givenList
.- 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.AssertionError
- if the givenList
does not contain the given object at the given index.
-
assertDoesNotContain
public void assertDoesNotContain(AssertionInfo info, java.util.List<?> actual, java.lang.Object value, Index index)
Verifies that the givenList
does not contain the given object at the given index.- Parameters:
info
- contains information about the assertion.actual
- the givenList
.value
- the object to look for.index
- the index where the object should be stored in the givenList
.- Throws:
java.lang.AssertionError
- if the givenList
isnull
.java.lang.NullPointerException
- if the givenIndex
isnull
.java.lang.AssertionError
- if the givenList
contains the given object at the given index.
-
assertIsSorted
public void assertIsSorted(AssertionInfo info, java.util.List<?> actual)
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
- Parameters:
info
- contains information about the assertion.actual
- the givenList
.- 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
.
-
assertIsSortedAccordingToComparator
public void assertIsSortedAccordingToComparator(AssertionInfo info, java.util.List<?> actual, java.util.Comparator<? extends java.lang.Object> 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:
info
- contains information about the assertion.actual
- the givenList
.comparator
- theComparator
used to compare list elements- 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 comparabe according to given Comparator.
-
assertHas
public <T> void assertHas(AssertionInfo info, java.util.List<T> actual, Condition<? super T> condition, Index index)
Verifies that the givenList
satisfies the given
at the given index.Condition
- Type Parameters:
T
- the type of the actual value and the type of values that givenCondition
takes.- Parameters:
info
- contains information about the assertion.actual
- the givenList
.condition
- the givenCondition
.index
- the index where the object should be stored in the givenList
.- 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
.
-
assertIs
public <T> void assertIs(AssertionInfo info, java.util.List<T> actual, Condition<? super T> condition, Index index)
Verifies that the givenList
satisfies the given
at the given index.Condition
- Type Parameters:
T
- the type of the actual value and the type of values that givenCondition
takes.- Parameters:
info
- contains information about the assertion.actual
- the givenList
.condition
- the givenCondition
.index
- the index where the object should be stored in the givenList
.- 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
.
-
-