public class IterableSubject extends Subject<IterableSubject,Iterable<?>>
Iterable
subjects.
Note:
Iterable
more than once. If you have an
unusual implementation of Iterable
which does not support multiple iterations
(sometimes known as a "one-shot iterable"), you must copy your iterable into a collection
which does (e.g. ImmutableList.copyOf(iterable)
or, if your iterable may contain
null, newArrayList(iterable)
). If you don't, you may see surprising failures.
Iterable
implement
Object.hashCode()
correctly.
Modifier and Type | Class and Description |
---|---|
static class |
IterableSubject.UsingCorrespondence<A,E>
A partially specified check in which the actual elements (normally the elements of the
Iterable under test) are compared to expected elements using a Correspondence . |
Modifier | Constructor and Description |
---|---|
protected |
IterableSubject(FailureMetadata metadata,
Iterable<?> iterable)
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
protected String |
actualCustomStringRepresentation()
Supplies the direct string representation of the actual value to other methods which may prefix
or otherwise position it in an error message.
|
<A,E> IterableSubject.UsingCorrespondence<A,E> |
comparingElementsUsing(Correspondence<A,E> correspondence)
Starts a method chain for a check in which the actual elements (i.e.
|
void |
contains(Object element)
Checks (with a side-effect failure) that the subject contains the supplied item.
|
Ordered |
containsAllIn(Iterable<?> expectedIterable)
Checks that the actual iterable contains at least all of the expected elements or fails.
|
Ordered |
containsAllIn(Object[] expected)
Checks that the actual iterable contains at least all of the expected elements or fails.
|
Ordered |
containsAllOf(Object firstExpected,
Object secondExpected,
Object... restOfExpected)
Checks that the actual iterable contains at least all of the expected elements or fails.
|
void |
containsAnyIn(Iterable<?> expected)
Checks that the subject contains at least one of the objects contained in the provided
collection or fails.
|
void |
containsAnyIn(Object[] expected)
Checks that the subject contains at least one of the objects contained in the provided array or
fails.
|
void |
containsAnyOf(Object first,
Object second,
Object... rest)
Checks that the subject contains at least one of the provided objects or fails.
|
Ordered |
containsExactly(Object... varargs)
Checks that a subject contains exactly the provided objects or fails.
|
Ordered |
containsExactlyElementsIn(Iterable<?> expected)
Checks that a subject contains exactly the provided objects or fails.
|
Ordered |
containsExactlyElementsIn(Object[] expected)
Checks that a subject contains exactly the provided objects or fails.
|
void |
containsNoDuplicates()
Checks that the subject does not contain duplicate elements.
|
void |
containsNoneIn(Iterable<?> excluded)
Checks that the actual iterable contains none of the elements contained in the excluded
iterable or fails.
|
void |
containsNoneIn(Object[] excluded)
Checks that the actual iterable contains none of the elements contained in the excluded array
or fails.
|
void |
containsNoneOf(Object firstExcluded,
Object secondExcluded,
Object... restOfExcluded)
Checks that a actual iterable contains none of the excluded objects or fails.
|
void |
doesNotContain(Object element)
Checks (with a side-effect failure) that the subject does not contain the supplied item.
|
void |
hasSize(int expectedSize)
Fails if the subject does not have the given size.
|
void |
isEmpty()
Fails if the subject is not empty.
|
void |
isNoneOf(Object first,
Object second,
Object... rest)
Deprecated.
You probably meant to call
containsNoneOf(java.lang.Object, java.lang.Object, java.lang.Object...) instead. |
void |
isNotEmpty()
Fails if the subject is empty.
|
void |
isNotIn(Iterable<?> iterable)
Deprecated.
You probably meant to call
containsNoneIn(java.lang.Iterable<?>) instead. |
void |
isOrdered()
Fails if the iterable is not ordered, according to the natural ordering of its elements.
|
void |
isOrdered(Comparator<?> comparator)
Fails if the iterable is not ordered, according to the given comparator.
|
void |
isStrictlyOrdered()
Fails if the iterable is not strictly ordered, according to the natural ordering of its
elements.
|
void |
isStrictlyOrdered(Comparator<?> comparator)
Fails if the iterable is not strictly ordered, according to the given comparator.
|
actual, actualAsString, check, check, equals, fail, fail, fail, failComparing, failComparing, failWithActual, failWithActual, failWithBadResults, failWithCustomSubject, failWithoutActual, failWithoutActual, failWithoutSubject, failWithRawMessage, failWithRawMessageAndCause, getSubject, hashCode, ignoreCheck, internalCustomName, isAnyOf, isEqualTo, isIn, isInstanceOf, isNotEqualTo, isNotInstanceOf, isNotNull, isNotSameAs, isNull, isSameAs, named, toString
protected IterableSubject(FailureMetadata metadata, @NullableDecl Iterable<?> iterable)
Subject.check()
.that(actual)
.protected String actualCustomStringRepresentation()
Subject
Subjects should override this with care.
By default, this returns String.ValueOf(getActualValue())
.
actualCustomStringRepresentation
in class Subject<IterableSubject,Iterable<?>>
public final void isEmpty()
public final void isNotEmpty()
public final void hasSize(int expectedSize)
public final void contains(@NullableDecl Object element)
public final void doesNotContain(@NullableDecl Object element)
public final void containsNoDuplicates()
public final void containsAnyOf(@NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest)
public final void containsAnyIn(Iterable<?> expected)
public final void containsAnyIn(Object[] expected)
@CanIgnoreReturnValue public final Ordered containsAllOf(@NullableDecl Object firstExpected, @NullableDecl Object secondExpected, @NullableDecl Object... restOfExpected)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method. The expected elements must appear in the given order
within the actual elements, but they are not required to be consecutive.
@CanIgnoreReturnValue public final Ordered containsAllIn(Iterable<?> expectedIterable)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method. The expected elements must appear in the given order
within the actual elements, but they are not required to be consecutive.
@CanIgnoreReturnValue public final Ordered containsAllIn(Object[] expected)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method. The expected elements must appear in the given order
within the actual elements, but they are not required to be consecutive.
@CanIgnoreReturnValue public final Ordered containsExactly(@NullableDecl Object... varargs)
Multiplicity is respected. For example, an object duplicated exactly 3 times in the parameters asserts that the object must likewise be duplicated exactly 3 times in the subject.
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method.
To test that the iterable contains the same elements as an array, prefer containsExactlyElementsIn(Object[])
. It makes clear that the given array is a list of
elements, not an element itself. This helps human readers and avoids a compiler warning.
@CanIgnoreReturnValue public final Ordered containsExactlyElementsIn(Iterable<?> expected)
Multiplicity is respected. For example, an object duplicated exactly 3 times in the Iterable
parameter asserts that the object must likewise be duplicated exactly 3 times in the
subject.
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method.
@CanIgnoreReturnValue public final Ordered containsExactlyElementsIn(Object[] expected)
Multiplicity is respected. For example, an object duplicated exactly 3 times in the array parameter asserts that the object must likewise be duplicated exactly 3 times in the subject.
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method.
public final void containsNoneOf(@NullableDecl Object firstExcluded, @NullableDecl Object secondExcluded, @NullableDecl Object... restOfExcluded)
public final void containsNoneIn(Iterable<?> excluded)
public final void containsNoneIn(Object[] excluded)
public final void isStrictlyOrdered()
ClassCastException
- if any pair of elements is not mutually ComparableNullPointerException
- if any element is nullpublic final void isStrictlyOrdered(Comparator<?> comparator)
ClassCastException
- if any pair of elements is not mutually Comparablepublic final void isOrdered()
ClassCastException
- if any pair of elements is not mutually ComparableNullPointerException
- if any element is nullpublic final void isOrdered(Comparator<?> comparator)
ClassCastException
- if any pair of elements is not mutually Comparable@Deprecated public void isNoneOf(@NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest)
containsNoneOf(java.lang.Object, java.lang.Object, java.lang.Object...)
instead.Subject
isNoneOf
in class Subject<IterableSubject,Iterable<?>>
@Deprecated public void isNotIn(Iterable<?> iterable)
containsNoneIn(java.lang.Iterable<?>)
instead.Subject
isNotIn
in class Subject<IterableSubject,Iterable<?>>
public <A,E> IterableSubject.UsingCorrespondence<A,E> comparingElementsUsing(Correspondence<A,E> correspondence)
Iterable
under test) are compared to expected elements using the given Correspondence
.
The actual elements must be of type A
, the expected elements must be of type E
.
The check is actually executed by continuing the method chain. For example:
assertThat(actualIterable).comparingElementsUsing(correspondence).contains(expected);
where actualIterable
is an Iterable<A>
(or, more generally, an Iterable<? extends A>
), correspondence
is a Correspondence<A, E>
, and expected
is an E
.
Any of the methods on the returned object may throw ClassCastException
if they
encounter an actual element that is not of type A
.
Copyright © 2018. All rights reserved.