Package org.assertj.core.internal
Class Lists
- java.lang.Object
-
- org.assertj.core.internal.Lists
-
-
Field Summary
Fields Modifier and Type Field Description private ComparisonStrategycomparisonStrategy(package private) Failuresfailuresprivate static ListsINSTANCE
-
Constructor Summary
Constructors Constructor Description Lists()Lists(ComparisonStrategy comparisonStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanareEqual(Object actual, Object other)voidassertContains(AssertionInfo info, List<?> actual, Object value, Index index)Verifies that the givenListcontains the given object at the given index.voidassertDoesNotContain(AssertionInfo info, List<?> actual, Object value, Index index)Verifies that the givenListdoes not contain the given object at the given index.<T> voidassertHas(AssertionInfo info, List<? extends T> actual, Condition<? super T> condition, Index index)Verifies that the givenListsatisfies the givenat the given index.Condition<T> voidassertIs(AssertionInfo info, List<? extends T> actual, Condition<? super T> condition, Index index)Verifies that the givenListsatisfies the givenat the given index.ConditionvoidassertIsSorted(AssertionInfo info, List<?> actual)Verifies that the actual list is sorted in ascending order according to the natural ordering of its elements.voidassertIsSortedAccordingToComparator(AssertionInfo info, List<?> actual, Comparator<?> 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 the element is compatible with comparator.private voidassertNotNull(AssertionInfo info, List<?> actual)private voidassertNotNull(Condition<?> condition)private <T> booleanconditionIsMetAtIndex(AssertionInfo info, List<T> actual, Condition<? super T> condition, Index index)Comparator<?>getComparator()ComparisonStrategygetComparisonStrategy()static Listsinstance()Returns the singleton instance of this class.private static List<Comparable<Object>>listOfComparableElements(List<?> collection)<T> voidsatisfies(AssertionInfo info, List<? extends T> actual, Consumer<? super T> requirements, Index index)
-
-
-
Field Detail
-
INSTANCE
private static final Lists INSTANCE
-
comparisonStrategy
private final ComparisonStrategy comparisonStrategy
-
failures
Failures failures
-
-
Constructor Detail
-
Lists
Lists()
-
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 Comparator<?> getComparator()
-
assertContains
public void assertContains(AssertionInfo info, List<?> actual, Object value, Index index)
Verifies that the givenListcontains 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:
AssertionError- if the givenListisnullor empty.NullPointerException- if the givenIndexisnull.IndexOutOfBoundsException- if the value of the givenIndexis equal to or greater than the size of the givenList.AssertionError- if the givenListdoes not contain the given object at the given index.
-
assertDoesNotContain
public void assertDoesNotContain(AssertionInfo info, List<?> actual, Object value, Index index)
Verifies that the givenListdoes 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:
AssertionError- if the givenListisnull.NullPointerException- if the givenIndexisnull.AssertionError- if the givenListcontains the given object at the given index.
-
assertIsSorted
public void assertIsSorted(AssertionInfo info, List<?> actual)
Verifies that the actual list is sorted in ascending order according to the natural ordering of its elements.All list elements must implement the
Comparableinterface 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
Unique element lists are considered sorted unless the element type is not Comparable.- Parameters:
info- contains information about the assertion.actual- the givenList.- Throws:
AssertionError- if the actual list is not sorted in ascending order according to the natural ordering of its elements.AssertionError- if the actual list isnull.AssertionError- if the actual list element type does not implementComparable.AssertionError- if the actual list elements are not mutuallyComparable.
-
assertIsSortedAccordingToComparator
public void assertIsSortedAccordingToComparator(AssertionInfo info, List<?> actual, Comparator<?> 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 the element is compatible with comparator.- Parameters:
info- contains information about the assertion.actual- the givenList.comparator- theComparatorused to compare list elements- Throws:
AssertionError- if the actual list is not sorted according to the given comparator.AssertionError- if the actual list isnull.NullPointerException- if the given comparator isnull.AssertionError- if the actual list elements are not mutually comparable according to given Comparator.
-
assertHas
public <T> void assertHas(AssertionInfo info, List<? extends T> actual, Condition<? super T> condition, Index index)
Verifies that the givenListsatisfies the givenat the given index.Condition- Type Parameters:
T- the type of the actual value and the type of values that givenConditiontakes.- 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:
AssertionError- if the givenListisnullor empty.NullPointerException- if the givenIndexisnull.IndexOutOfBoundsException- if the value of the givenIndexis equal to or greater than the size of the givenList.NullPointerException- if the givenConditionisnull.AssertionError- if the value in the givenListat the given index does not satisfy the givenCondition.
-
assertIs
public <T> void assertIs(AssertionInfo info, List<? extends T> actual, Condition<? super T> condition, Index index)
Verifies that the givenListsatisfies the givenat the given index.Condition- Type Parameters:
T- the type of the actual value and the type of values that givenConditiontakes.- 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:
AssertionError- if the givenListisnullor empty.NullPointerException- if the givenIndexisnull.IndexOutOfBoundsException- if the value of the givenIndexis equal to or greater than the size of the givenList.NullPointerException- if the givenConditionisnull.AssertionError- if the value in the givenListat the given index does not satisfy the givenCondition.
-
satisfies
public <T> void satisfies(AssertionInfo info, List<? extends T> actual, Consumer<? super T> requirements, Index index)
-
conditionIsMetAtIndex
private <T> boolean conditionIsMetAtIndex(AssertionInfo info, List<T> actual, Condition<? super T> condition, Index index)
-
listOfComparableElements
private static List<Comparable<Object>> listOfComparableElements(List<?> collection)
-
assertNotNull
private void assertNotNull(AssertionInfo info, List<?> actual)
-
assertNotNull
private void assertNotNull(Condition<?> condition)
-
getComparisonStrategy
public ComparisonStrategy getComparisonStrategy()
-
-