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 |
---|---|
class |
IterableSubject.UsingCorrespondence<A,E>
A partially specified proposition in which the actual elements (normally the elements of the
Iterable under test) are compared to expected elements using a Correspondence . |
failureStrategy
Modifier | Constructor and Description |
---|---|
protected |
IterableSubject(FailureMetadata metadata,
Iterable<?> list) |
protected |
IterableSubject(FailureStrategy failureStrategy,
Iterable<?> list)
Deprecated.
Switch your
Subject from accepting FailureStrategy (and exposing a
SubjectFactory ) to accepting a FailureMetadata (and exposing a Subject.Factory ), at which point you'll call the FailureMetadata overload of this
constructor instead. |
Modifier and Type | Method and Description |
---|---|
<A,E> IterableSubject.UsingCorrespondence<A,E> |
comparingElementsUsing(Correspondence<A,E> correspondence)
Starts a method chain for a test proposition in which the actual elements (i.e.
|
void |
contains(Object element)
Attests (with a side-effect failure) that the subject contains the supplied item.
|
Ordered |
containsAllIn(Iterable<?> expected)
Attests that the actual iterable contains at least all of the expected elements or fails.
|
Ordered |
containsAllOf(Object firstExpected,
Object secondExpected,
Object... restOfExpected)
Attests that the actual iterable contains at least all of the expected elements or fails.
|
void |
containsAnyIn(Iterable<?> expected)
Attests that the subject contains at least one of the objects contained in the provided
collection or fails.
|
void |
containsAnyOf(Object first,
Object second,
Object... rest)
Attests that the subject contains at least one of the provided objects or fails.
|
Ordered |
containsExactly(Object... varargs)
Attests that a subject contains exactly the provided objects or fails.
|
Ordered |
containsExactlyElementsIn(Iterable<?> expected)
Attests that a subject contains exactly the provided objects or fails.
|
void |
containsNoDuplicates()
Attests that the subject does not contain duplicate elements.
|
void |
containsNoneIn(Iterable<?> excluded)
Attests that a actual iterable contains none of the elements contained in the excluded iterable
or fails.
|
void |
containsNoneOf(Object firstExcluded,
Object secondExcluded,
Object... restOfExcluded)
Attests that a actual iterable contains none of the excluded objects or fails.
|
void |
doesNotContain(Object element)
Attests (with a side-effect failure) that the subject does not contain the supplied item.
|
protected void |
failWithBadResultsAndSuffix(String verb,
Object expected,
String failVerb,
Object actual,
String suffix)
Fails with the bad results and a suffix.
|
void |
hasSize(int expectedSize)
Fails if the subject does not have the given size.
|
void |
isEmpty()
Fails if the subject is not empty.
|
void |
isNotEmpty()
Fails if the subject is empty.
|
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 |
isPartiallyOrdered()
Deprecated.
Use
isOrdered() instead. |
void |
isPartiallyOrdered(Comparator<?> comparator)
Deprecated.
Use
isOrdered(Comparator) instead. |
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, actualCustomStringRepresentation, check, equals, fail, fail, fail, failComparing, failComparing, failWithBadResults, failWithCustomSubject, failWithoutActual, failWithoutSubject, failWithRawMessage, failWithRawMessageAndCause, getDisplaySubject, getSubject, hashCode, ignoreCheck, internalCustomName, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameAs, isNull, isSameAs, named
@Deprecated protected IterableSubject(FailureStrategy failureStrategy, @Nullable Iterable<?> list)
Subject
from accepting FailureStrategy
(and exposing a
SubjectFactory
) to accepting a FailureMetadata
(and exposing a Subject.Factory
), at which point you'll call the FailureMetadata
overload of this
constructor instead.protected IterableSubject(FailureMetadata metadata, @Nullable Iterable<?> list)
public final void isEmpty()
public final void isNotEmpty()
public final void hasSize(int expectedSize)
public final void contains(@Nullable Object element)
public final void doesNotContain(@Nullable Object element)
public final void containsNoDuplicates()
public final void containsAnyOf(@Nullable Object first, @Nullable Object second, @Nullable Object... rest)
public final void containsAnyIn(Iterable<?> expected)
public final Ordered containsAllOf(@Nullable Object firstExpected, @Nullable Object secondExpected, @Nullable 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.
public final Ordered containsAllIn(Iterable<?> 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.
public final Ordered containsExactly(@Nullable 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.
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.
protected final void failWithBadResultsAndSuffix(String verb, Object expected, String failVerb, Object actual, String suffix)
verb
- the proposition being assertedexpected
- the expectations against which the subject is comparedfailVerb
- the failure of the proposition being assertedactual
- the actual value the subject was compared againstsuffix
- a suffix to append to the failure messagepublic final void containsNoneOf(@Nullable Object firstExcluded, @Nullable Object secondExcluded, @Nullable Object... restOfExcluded)
public final void containsNoneIn(Iterable<?> 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 null@Deprecated public final void isPartiallyOrdered()
isOrdered()
instead.public final void isOrdered(Comparator<?> comparator)
ClassCastException
- if any pair of elements is not mutually Comparable@Deprecated public final void isPartiallyOrdered(Comparator<?> comparator)
isOrdered(Comparator)
instead.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 proposition 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 © 2017. All rights reserved.