ELEMENT
- the type of elements of the "actual" value.public class ListAssert<ELEMENT> extends FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>>
List
s.
To create an instance of this class, invoke
.
Assertions.assertThat(List)
iterables
actual, info, myself
Constructor and Description |
---|
ListAssert(List<? 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> |
containsOnly(ELEMENT... values)
Verifies that the actual group contains only 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> |
doesNotContainSequence(ELEMENT... sequence)
Verifies that the actual group does not contain the given sequence,
a sequence is defined by an ordered group of values without extra values between them.
|
ListAssert<ELEMENT> |
doesNotContainSubsequence(ELEMENT... sequence)
Verifies that the actual group does not contain the given subsequence,
a subsequence is defined by an ordered group of values with possibly extra values between them.
|
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> |
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.
|
toAssert
as, as, contains, describedAs, describedAs, doesNotContain, doesNotHave, doesNotHaveSameClassAs, has, has, hasSameClassAs, hasToString, is, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isOfAnyClassIn, isSameAs, isSorted, isSortedAccordingTo, overridingErrorMessage, usingComparator, usingComparisonStrategy, usingDefaultComparator, usingDefaultElementComparator, usingElementComparator, withFailMessage, withThreadDumpOnError
are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, containsAll, containsExactlyElementsOf, containsNull, containsOnlyElementsOf, containsSequence, containsSubsequence, doesNotContainAnyElementsOf, doesNotContainNull, doesNotContainSequence, doesNotContainSubsequence, doesNotHaveDuplicates, doNotHave, element, extracting, extracting, extracting, extracting, extractingResultOf, extractingResultOf, filteredOn, filteredOn, filteredOn, filteredOnNull, first, flatExtracting, flatExtracting, flatExtracting, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasOnlyElementsOfTypes, 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, usingRecursiveFieldByFieldElementComparator
asList, asString, descriptionText, equals, failWithMessage, getWritableAssertionInfo, hashCode, isNull, setCustomRepresentation, throwAssertionError, withRepresentation
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, containsAll, containsExactlyElementsOf, containsNull, containsOnlyElementsOf, containsSequence, containsSubsequence, doesNotContainAnyElementsOf, doesNotContainNull, doesNotContainSequence, doesNotContainSubsequence, doesNotHaveDuplicates, doNotHave, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasOnlyElementsOfTypes, hasSameElementsAs, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, isSubsetOf
hasSameSizeAs, hasSameSizeAs, hasSize, isEmpty, isNotEmpty, isNullOrEmpty
@SafeVarargs public final ListAssert<ELEMENT> contains(ELEMENT... values)
AbstractIterableAssert
Example :
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> containsOnly(ELEMENT... values)
AbstractIterableAssert
Example :
Iterable<String> abc = newArrayList("a", "b", "c");
// assertion will pass
assertThat(abc).containsOnly("c", "b", "a");
// assertion will fail because "c" is missing
assertThat(abc).containsOnly("a", "b");
containsOnly
in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>
containsOnly
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)
AbstractIterableAssert
Examples :
// 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)
AbstractIterableAssert
HashSet
, 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)
AbstractIterableAssert
Example :
// 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)
AbstractIterableAssert
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).isSubsetOf(vilya, nenya, narya)
.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)
.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> doesNotContainSequence(ELEMENT... sequence)
AbstractIterableAssert
Use ObjectEnumerableAssert.doesNotContainSubsequence(Object...)
to also ensure the sequence does not exist with 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, the elements order is correct but there is a value between them (nenya)
assertThat(elvesRings).doesNotContainSequence(vilya, narya)
.doesNotContainSequence(nenya, vilya);
// assertions will fail
assertThat(elvesRings).doesNotContainSequence(vilya, nenya);
assertThat(elvesRings).doesNotContainSequence(nenya, narya);
doesNotContainSequence
in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>
doesNotContainSequence
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)
AbstractIterableAssert
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).containsSubsequence(vilya, nenya)
.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> doesNotContainSubsequence(ELEMENT... sequence)
AbstractIterableAssert
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).doesNotContainSubsequence(nenya, vilya)
.doesNotContainSubsequence(narya, vilya);
// assertion will fail
assertThat(elvesRings).doesNotContainSubsequence(vilya, nenya);
assertThat(elvesRings).doesNotContainSubsequence(vilya, narya);
doesNotContainSubsequence
in interface ObjectEnumerableAssert<ListAssert<ELEMENT>,ELEMENT>
doesNotContainSubsequence
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)
ObjectEnumerableAssert
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).doesNotContain("d")
.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> startsWith(ELEMENT... sequence)
AbstractIterableAssert
ObjectEnumerableAssert.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")
.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> endsWith(ELEMENT... sequence)
AbstractIterableAssert
ObjectEnumerableAssert.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")
.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 © 2013–2017 AssertJ. All rights reserved.