Top Description Fields Constructors Methods
org.assertj.core.internal

public Class Lists

extends Object
Class Inheritance
Static Imports
java.util.Objects.requireNonNull, java.util.stream.Collectors.toList, org.assertj.core.error.ShouldBeAtIndex.shouldBeAtIndex, .ShouldBeSorted.shouldBeSorted, .ShouldBeSorted.shouldBeSortedAccordingToGivenComparator, .ShouldBeSorted.shouldHaveComparableElementsAccordingToGivenComparator, .ShouldBeSorted.shouldHaveMutuallyComparableElements, .ShouldContainAtIndex.shouldContainAtIndex, .ShouldHaveAtIndex.shouldHaveAtIndex, .ShouldNotContainAtIndex.shouldNotContainAtIndex, org.assertj.core.internal.CommonValidations.checkIndexValueIsValid

Reusable assertions for Lists.
Authors
Alex Ruiz, Yvonne Wang, Joel Costigliola, Jacek Jackowiak

Field Summary

Modifier and TypeField and Description
private final ComparisonStrategy
pack-priv Failures
private static final Lists

Constructor Summary

AccessConstructor and Description
pack-priv
public
Lists(ComparisonStrategy comparisonStrategy)

Method Summary

Modifier and TypeMethod and Description
private boolean
areEqual(Object actual, Object other)

public void
assertContains(AssertionInfo
contains information about the assertion.
info
,
List<?>
the given List.
actual
,
Object
the object to look for.
value
,
Index
the index where the object should be stored in the given List.
index
)

Verifies that the given List contains the given object at the given index.

public void
assertDoesNotContain(AssertionInfo
contains information about the assertion.
info
,
List<?>
the given List.
actual
,
Object
the object to look for.
value
,
Index
the index where the object should be stored in the given List.
index
)

Verifies that the given List does not contain the given object at the given index.

public <
the type of the actual value and the type of values that given Condition takes.
T
>
void
assertHas(AssertionInfo
contains information about the assertion.
info
,
List<? extends T>
the given List.
actual
,
Condition<? super T>
the given Condition.
condition
,
Index
the index where the object should be stored in the given List.
index
)

Verifies that the given List satisfies the given Condition at the given index.

public <
the type of the actual value and the type of values that given Condition takes.
T
>
void
assertIs(AssertionInfo
contains information about the assertion.
info
,
List<? extends T>
the given List.
actual
,
Condition<? super T>
the given Condition.
condition
,
Index
the index where the object should be stored in the given List.
index
)

Verifies that the given List satisfies the given Condition at the given index.

public void
assertIsSorted(AssertionInfo
contains information about the assertion.
info
,
List<?>
the given List.
actual
)

Verifies that the actual list is sorted in ascending order according to the natural ordering of its elements.

public void
assertIsSortedAccordingToComparator(AssertionInfo
contains information about the assertion.
info
,
List<?>
the given List.
actual
,
Comparator<?>
the Comparator used to compare list elements
comparator
)

Verifies that the actual list is sorted according to the given comparator.

private void
assertNotNull(AssertionInfo info, List<?> actual)

private void
assertNotNull(Condition<?> condition)

private <T> boolean
conditionIsMetAtIndex(AssertionInfo info, List<T> actual, Condition<? super T> condition, Index index)

public Comparator<?>
public ComparisonStrategy
public static Lists

Returns:

the singleton instance of this class.
instance
()

Returns the singleton instance of this class.

private static List<Comparable<Object>>
public <T> void
satisfies(AssertionInfo info, List<? extends T> actual, Consumer<? super T> requirements, Index index)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

comparisonStrategyback to summary
private final ComparisonStrategy comparisonStrategy
failuresback to summary
pack-priv Failures failures
Annotations
@VisibleForTesting
INSTANCEback to summary
private static final Lists INSTANCE

Constructor Detail

Listsback to summary
pack-priv Lists()
Annotations
@VisibleForTesting
Listsback to summary
public Lists(ComparisonStrategy comparisonStrategy)

Method Detail

areEqualback to summary
private boolean areEqual(Object actual, Object other)
assertContainsback to summary
public void assertContains(AssertionInfo info, List<?> actual, Object value, Index index)

Verifies that the given List contains the given object at the given index.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:List<?>

the given List.

value:Object

the object to look for.

index:Index

the index where the object should be stored in the given List.

Exceptions
AssertionError:
  • if the given List is null or empty.
  • if the given List does not contain the given object at the given index.
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.
assertDoesNotContainback to summary
public void assertDoesNotContain(AssertionInfo info, List<?> actual, Object value, Index index)

Verifies that the given List does not contain the given object at the given index.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:List<?>

the given List.

value:Object

the object to look for.

index:Index

the index where the object should be stored in the given List.

Exceptions
AssertionError:
  • if the given List is null.
  • if the given List contains the given object at the given index.
NullPointerException:
if the given Index is null.
assertHasback to summary
public <T> void assertHas(AssertionInfo info, List<? extends T> actual, Condition<? super T> condition, Index index)

Verifies that the given List satisfies the given Condition at the given index.

Parameters
<T>
the type of the actual value and the type of values that given Condition takes.
info:AssertionInfo

contains information about the assertion.

actual:List<? extends T>

the given List.

condition:Condition<? super T>

the given Condition.

index:Index

the index where the object should be stored in the given List.

Exceptions
AssertionError:
  • if the given List is null or empty.
  • if the value in the given List at the given index does not satisfy the given Condition .
NullPointerException:
  • if the given Index is null.
  • if the given Condition is null.
IndexOutOfBoundsException:
if the value of the given Index is equal to or greater than the size of the given List.
assertIsback to summary
public <T> void assertIs(AssertionInfo info, List<? extends T> actual, Condition<? super T> condition, Index index)

Verifies that the given List satisfies the given Condition at the given index.

Parameters
<T>
the type of the actual value and the type of values that given Condition takes.
info:AssertionInfo

contains information about the assertion.

actual:List<? extends T>

the given List.

condition:Condition<? super T>

the given Condition.

index:Index

the index where the object should be stored in the given List.

Exceptions
AssertionError:
  • if the given List is null or empty.
  • if the value in the given List at the given index does not satisfy the given Condition .
NullPointerException:
  • if the given Index is null.
  • if the given Condition is null.
IndexOutOfBoundsException:
if the value of the given Index is equal to or greater than the size of the given List.
assertIsSortedback to summary
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 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
Empty lists are considered sorted.
Unique element lists are considered sorted unless the element type is not Comparable.
Parameters
info:AssertionInfo

contains information about the assertion.

actual:List<?>

the given List.

Exceptions
AssertionError:
  • if the actual list is not sorted in ascending order according to the natural ordering of its elements.
  • if the actual list is null.
  • if the actual list element type does not implement Comparable.
  • if the actual list elements are not mutually Comparable.
assertIsSortedAccordingToComparatorback to summary
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:AssertionInfo

contains information about the assertion.

actual:List<?>

the given List.

comparator:Comparator<?>

the Comparator used to compare list elements

Annotations
@SuppressWarnings:rawtypes, unchecked
Exceptions
AssertionError:
  • if the actual list is not sorted according to the given comparator.
  • if the actual list is null.
  • if the actual list elements are not mutually comparable according to given Comparator.
NullPointerException:
if the given comparator is null.
assertNotNullback to summary
private void assertNotNull(AssertionInfo info, List<?> actual)
assertNotNullback to summary
private void assertNotNull(Condition<?> condition)
conditionIsMetAtIndexback to summary
private <T> boolean conditionIsMetAtIndex(AssertionInfo info, List<T> actual, Condition<? super T> condition, Index index)
getComparatorback to summary
public Comparator<?> getComparator()
Annotations
@VisibleForTesting
getComparisonStrategyback to summary
public ComparisonStrategy getComparisonStrategy()
Annotations
@VisibleForTesting
instanceback to summary
public static Lists instance()

Returns the singleton instance of this class.

Returns:Lists

the singleton instance of this class.

listOfComparableElementsback to summary
private static List<Comparable<Object>> listOfComparableElements(List<?> collection)
Annotations
@SuppressWarnings:unchecked
satisfiesback to summary
public <T> void satisfies(AssertionInfo info, List<? extends T> actual, Consumer<? super T> requirements, Index index)