ELEMENT - the type of elements of the "actual" value.public class ListAssert<ELEMENT> extends FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
Lists.
To create an instance of this class, invoke .
Assertions.assertThat(List)
iterablesactual, info, myself| Modifier | Constructor and Description |
|---|---|
|
ListAssert(List<? extends ELEMENT> actual) |
protected |
ListAssert(Stream<? extends ELEMENT> actual) |
| Modifier and Type | Method and Description |
|---|---|
ListAssert<ELEMENT> |
contains(ELEMENT... values)
Verifies that the actual group contains the given values, in any order.
|
ListAssert<ELEMENT> |
containsExactly(ELEMENT... values)
Verifies that the actual group contains only the given values and nothing else, in order.
This assertion should only be used with groups that have a consistent iteration order (i.e. |
ListAssert<ELEMENT> |
containsExactlyInAnyOrder(ELEMENT... values)
Verifies that the actual group contains exactly the given values and nothing else, in any order.
|
ListAssert<ELEMENT> |
containsOnlyOnce(ELEMENT... values)
Verifies that the actual group contains the given values only once.
|
ListAssert<ELEMENT> |
containsSequence(ELEMENT... sequence)
Verifies that the actual group contains the given sequence in the correct order and without extra values between the sequence values.
|
ListAssert<ELEMENT> |
containsSubsequence(ELEMENT... sequence)
Verifies that the actual group contains the given subsequence in the correct order (possibly with other values between them).
|
ListAssert<ELEMENT> |
doesNotContain(ELEMENT... values)
Verifies that the actual group does not contain the given values.
|
ListAssert<ELEMENT> |
endsWith(ELEMENT... sequence)
Verifies that the actual group ends with the given sequence of objects, without any other objects between them.
|
ListAssert<ELEMENT> |
isEqualTo(Object expected)
Verifies that the actual value is equal to the given one.
|
ListAssert<ELEMENT> |
isExactlyInstanceOf(Class<?> type)
Verifies that the actual value is exactly an instance of the given type.
|
ListAssert<ELEMENT> |
isInstanceOf(Class<?> type)
Verifies that the actual value is an instance of the given type.
|
ListAssert<ELEMENT> |
isInstanceOfAny(Class<?>... types)
Verifies that the actual value is an instance of any of the given types.
|
ListAssert<ELEMENT> |
isNotExactlyInstanceOf(Class<?> type)
Verifies that the actual value is not exactly an instance of given type.
|
ListAssert<ELEMENT> |
isNotInstanceOf(Class<?> type)
Verifies that the actual value is not an instance of the given type.
|
ListAssert<ELEMENT> |
isNotInstanceOfAny(Class<?>... types)
Verifies that the actual value is not an instance of any of the given types.
|
ListAssert<ELEMENT> |
isNotOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is not in given types.
|
ListAssert<ELEMENT> |
isNotSameAs(Object expected)
Verifies that the actual value is not the same as the given one, ie using == comparison.
|
ListAssert<ELEMENT> |
isOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is in given types.
|
ListAssert<ELEMENT> |
isSameAs(Object expected)
Verifies that the actual value is the same as the given one, ie using == comparison.
|
ListAssert<ELEMENT> |
isSubsetOf(ELEMENT... values)
Verifies that all the elements of actual are present in the given values.
|
ListAssert<ELEMENT> |
startsWith(ELEMENT... sequence)
Verifies that the actual group starts with the given sequence of objects, without any other objects between them.
|
toAssertas, as, contains, describedAs, describedAs, doesNotContain, doesNotHave, doesNotHaveSameClassAs, has, has, hasSameClassAs, hasToString, is, is, isIn, isIn, isNot, isNotEqualTo, isNotIn, isNotIn, isNotNull, isSorted, isSortedAccordingTo, overridingErrorMessage, usingComparator, usingComparisonStrategy, usingDefaultComparator, usingDefaultElementComparator, usingElementComparator, withFailMessage, withThreadDumpOnErrorallMatch, allMatch, allSatisfy, are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, containsAll, containsExactlyElementsOf, containsNull, containsOnly, containsOnlyElementsOf, doesNotContainAnyElementsOf, doesNotContainNull, doesNotHaveDuplicates, doNotHave, element, extracting, extracting, extracting, extracting, extracting, extractingResultOf, extractingResultOf, filteredOn, filteredOn, filteredOn, filteredOn, filteredOnNull, first, flatExtracting, flatExtracting, flatExtracting, flatExtracting, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasOnlyOneElementSatisfying, hasSameElementsAs, hasSameSizeAs, hasSameSizeAs, hasSize, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, inBinary, inHexadecimal, isEmpty, isNotEmpty, isNullOrEmpty, isSubsetOf, last, navigationDescription, newListAssertInstance, size, toLazyIterable, usingComparatorForElementFieldsWithNames, usingComparatorForElementFieldsWithType, usingElementComparatorIgnoringFields, usingElementComparatorOnFields, usingFieldByFieldElementComparator, usingRecursiveFieldByFieldElementComparatorasList, asString, descriptionText, equals, failWithMessage, getWritableAssertionInfo, hashCode, isInstanceOfSatisfying, isNull, matches, matches, satisfies, setCustomRepresentation, throwAssertionError, withRepresentationclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitallMatch, allMatch, allSatisfy, are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, containsAll, containsExactlyElementsOf, containsNull, containsOnly, containsOnlyElementsOf, doesNotContainAnyElementsOf, doesNotContainNull, doesNotHaveDuplicates, doNotHave, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasSameElementsAs, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, isSubsetOfhasSameSizeAs, hasSameSizeAs, hasSize, isEmpty, isNotEmpty, isNullOrEmptypublic ListAssert<ELEMENT> isEqualTo(Object expected)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isEqualTo("abc");
assertThat(new HashMap<String, Integer>()).isEqualTo(new HashMap<String, Integer>());
// assertions will fail
assertThat("abc").isEqualTo("123");
assertThat(new ArrayList<String>()).isEqualTo(1);isEqualTo in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isEqualTo in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>expected - the given value to compare the actual value to.this assertion object.public ListAssert<ELEMENT> isInstanceOf(Class<?> type)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isInstanceOf(String.class);
assertThat(new HashMap<String, Integer>()).isInstanceOf(HashMap.class);
assertThat(new HashMap<String, Integer>()).isInstanceOf(Map.class);
// assertions will fail
assertThat(1).isInstanceOf(String.class);
assertThat(new ArrayList<String>()).isInstanceOf(LinkedList.class);isInstanceOf in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isInstanceOf in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>type - the type to check the actual value against.public ListAssert<ELEMENT> isInstanceOfAny(Class<?>... types)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isInstanceOfAny(String.class, Integer.class);
assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, ArrayList.class);
assertThat(new HashMap<String, Integer>()).isInstanceOfAny(TreeMap.class, Map.class);
// assertions will fail
assertThat(1).isInstanceOfAny(Double.class, Float.class);
assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, Vector.class);isInstanceOfAny in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isInstanceOfAny in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>types - the types to check the actual value against.public ListAssert<ELEMENT> isOfAnyClassIn(Class<?>... types)
AbstractAssertExample:
// assertions will pass
assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(HashMap.class, TreeMap.class);
assertThat(new ArrayList<String>()).isOfAnyClassIn(ArrayList.class, LinkedList.class);
// assertions will fail
assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(TreeMap.class, Map.class);
assertThat(new ArrayList<String>()).isOfAnyClassIn(LinkedList.class, List.class);isOfAnyClassIn in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isOfAnyClassIn in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>types - the types to check the actual value against.public ListAssert<ELEMENT> isExactlyInstanceOf(Class<?> type)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isExactlyInstanceOf(ArrayList.class);
assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(HashMap.class);
// assertions will fail
assertThat(1).isExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isExactlyInstanceOf(List.class);
assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(Map.class);isExactlyInstanceOf in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isExactlyInstanceOf in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>type - the type to check the actual value against.public ListAssert<ELEMENT> isNotInstanceOf(Class<?> type)
AbstractAssertExample:
// assertions will pass
assertThat(1).isNotInstanceOf(Double.class);
assertThat(new ArrayList<String>()).isNotInstanceOf(LinkedList.class);
// assertions will fail
assertThat("abc").isNotInstanceOf(String.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOf(HashMap.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOf(Map.class);isNotInstanceOf in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isNotInstanceOf in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>type - the type to check the actual value against.public ListAssert<ELEMENT> isNotInstanceOfAny(Class<?>... types)
AbstractAssertExample:
// assertions will pass
assertThat(1).isNotInstanceOfAny(Double.class, Float.class);
assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, Vector.class);
// assertions will fail
assertThat(1).isNotInstanceOfAny(Double.class, Integer.class);
assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, ArrayList.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOfAny(TreeMap.class, Map.class);isNotInstanceOfAny in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isNotInstanceOfAny in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>types - the types to check the actual value against.public ListAssert<ELEMENT> isNotOfAnyClassIn(Class<?>... types)
AbstractAssertExample:
// assertions will pass
assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(Map.class, TreeMap.class);
assertThat(new ArrayList<String>()).isNotOfAnyClassIn(LinkedList.class, List.class);
// assertions will fail
assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(HashMap.class, TreeMap.class);
assertThat(new ArrayList<String>()).isNotOfAnyClassIn(ArrayList.class, LinkedList.class);isNotOfAnyClassIn in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isNotOfAnyClassIn in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>types - the types to check the actual value against.public ListAssert<ELEMENT> isNotExactlyInstanceOf(Class<?> type)
AbstractAssertExample:
// assertions will pass
assertThat(1).isNotExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(List.class);
assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(Map.class);
// assertions will fail
assertThat("abc").isNotExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(ArrayList.class);
assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(HashMap.class);isNotExactlyInstanceOf in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isNotExactlyInstanceOf in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>type - the type to check the actual value against.public ListAssert<ELEMENT> isSameAs(Object expected)
AbstractAssertExample:
// Name is a class with first and last fields, two Names are equals if both first and last are equals.
Name tyrion = new Name("Tyrion", "Lannister");
Name alias = tyrion;
Name clone = new Name("Tyrion", "Lannister");
// assertions succeed:
assertThat(tyrion).isSameAs(alias)
.isEqualTo(clone);
// assertion fails:
assertThat(tyrion).isSameAs(clone);isSameAs in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isSameAs in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>expected - the given value to compare the actual value to.this assertion object.public ListAssert<ELEMENT> isNotSameAs(Object expected)
AbstractAssertExample:
// Name is a class with first and last fields, two Names are equals if both first and last are equals.
Name tyrion = new Name("Tyrion", "Lannister");
Name alias = tyrion;
Name clone = new Name("Tyrion", "Lannister");
// assertions succeed:
assertThat(clone).isNotSameAs(tyrion)
.isEqualTo(tyrion);
// assertion fails:
assertThat(alias).isNotSameAs(tyrion);isNotSameAs in interface Assert<ListAssert<ELEMENT>,List<? extends ELEMENT>>isNotSameAs in class AbstractListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>expected - the given value to compare the actual value to.this assertion object.@SafeVarargs public final ListAssert<ELEMENT> startsWith(ELEMENT... sequence)
AbstractIterableAssertObjectEnumerableAssert.containsSequence(Object...), but it also verifies that the first element in the
sequence is also first element of the actual group.
Example :
// an Iterable is used in the example but it would also work with an array
Iterable<String> abc = newArrayList("a", "b", "c");
// assertions will pass
assertThat(abc).startsWith("a");
assertThat(abc).startsWith("a", "b");
// assertion will fail
assertThat(abc).startsWith("c");startsWith in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>startsWith in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>sequence - the sequence of objects to look for.@SafeVarargs public final ListAssert<ELEMENT> contains(ELEMENT... values)
AbstractIterableAssertExample :
Iterable<String> abc = newArrayList("a", "b", "c");
// assertions will pass
assertThat(abc).contains("b", "a");
assertThat(abc).contains("b", "a", "b");
// assertion will fail
assertThat(abc).contains("d");contains in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>contains in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>values - the given values.this assertion object.@SafeVarargs public final ListAssert<ELEMENT> containsOnlyOnce(ELEMENT... values)
AbstractIterableAssertExamples :
// lists are used in the examples but it would also work with arrays
// assertions will pass
assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("winter");
assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("coming", "winter");
// assertions will fail
assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("Lannister");
assertThat(newArrayList("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark");
assertThat(newArrayList("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark", "Lannister", "Arya");containsOnlyOnce in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>containsOnlyOnce in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>values - the given values.this assertion object.@SafeVarargs public final ListAssert<ELEMENT> containsExactly(ELEMENT... values)
AbstractIterableAssertHashSet, prefer ObjectEnumerableAssert.containsOnly(Object...) in that case).
Example :
// an Iterable is used in the example but it would also work with an array
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertion will pass
assertThat(elvesRings).containsExactly(vilya, nenya, narya);
// assertion will fail as actual and expected order differ
assertThat(elvesRings).containsExactly(nenya, vilya, narya);containsExactly in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>containsExactly in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>values - the given values.this assertion object.@SafeVarargs public final ListAssert<ELEMENT> containsExactlyInAnyOrder(ELEMENT... values)
AbstractIterableAssertExample :
// an Iterable is used in the example but it would also work with an array
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya, vilya);
// assertion will pass
assertThat(elvesRings).containsExactlyInAnyOrder(vilya, vilya, nenya, narya);
// assertion will fail as vilya is contained twice in elvesRings.
assertThat(elvesRings).containsExactlyInAnyOrder(nenya, vilya, narya);containsExactlyInAnyOrder in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>containsExactlyInAnyOrder in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>values - the given values.this assertion object.@SafeVarargs public final ListAssert<ELEMENT> isSubsetOf(ELEMENT... values)
AbstractIterableAssertExample:
// an Iterable is used in the example but it would also work with an array
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass:
assertThat(elvesRings).isSubsetOf(vilya, nenya, narya);
assertThat(elvesRings).isSubsetOf(vilya, nenya, narya, dwarfRing);
// assertions will fail:
assertThat(elvesRings).isSubsetOf(vilya, nenya);
assertThat(elvesRings).isSubsetOf(vilya, nenya, dwarfRing);isSubsetOf in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>isSubsetOf in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>values - the values that should be used for checking the elements of actual.@SafeVarargs public final ListAssert<ELEMENT> containsSequence(ELEMENT... sequence)
AbstractIterableAssert
Use ObjectEnumerableAssert.containsSubsequence(Object...) to allow values between the expected sequence values.
Example:
// an Iterable is used in the example but it would also work with an array
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass
assertThat(elvesRings).containsSequence(vilya, nenya);
assertThat(elvesRings).containsSequence(nenya, narya);
// assertions will fail, the elements order is correct but there is a value between them (nenya)
assertThat(elvesRings).containsSequence(vilya, narya);
assertThat(elvesRings).containsSequence(nenya, vilya);containsSequence in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>containsSequence in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>sequence - the sequence of objects to look for.@SafeVarargs public final ListAssert<ELEMENT> containsSubsequence(ELEMENT... sequence)
AbstractIterableAssertExample:
// an Iterable is used in the example but it would also work with an array
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass
assertThat(elvesRings).containsSubsequence(vilya, nenya);
assertThat(elvesRings).containsSubsequence(vilya, narya);
// assertion will fail
assertThat(elvesRings).containsSubsequence(nenya, vilya);containsSubsequence in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>containsSubsequence in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>sequence - the sequence of objects to look for.@SafeVarargs public final ListAssert<ELEMENT> doesNotContain(ELEMENT... values)
ObjectEnumerableAssertExample :
// an Iterable is used in the example but it would also work with an array
Iterable<String> abc = newArrayList("a", "b", "c");
// assertions will pass
assertThat(abc).doesNotContain("d")
assertThat(abc).doesNotContain("d", "e");
// assertions will fail
assertThat(abc).doesNotContain("a");
assertThat(abc).doesNotContain("a", "b");
assertThat(abc).doesNotContain("c", "d");doesNotContain in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>doesNotContain in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>values - the given values.this assertion object.@SafeVarargs public final ListAssert<ELEMENT> endsWith(ELEMENT... sequence)
AbstractIterableAssertObjectEnumerableAssert.containsSequence(Object...), but it also verifies that the last element in the
sequence is also last element of the actual group.
Example :
// an Iterable is used in the example but it would also work with an array
Iterable<String> abc = newArrayList("a", "b", "c");
// assertions will pass
assertThat(abc).endsWith("c")
assertThat(abc).endsWith("b", "c");
// assertions will fail
assertThat(abc).endsWith("a");
assertThat(abc).endsWith("a", "b");endsWith in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>endsWith in class AbstractIterableAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>sequence - the sequence of objects to look for.Copyright © 2014–2017 AssertJ. All rights reserved.