Class LongStreamSubject
LongStream values.
Note: When you perform an assertion based on the contents of the stream, or when any assertion fails, the wrapped stream will be drained immediately into a private collection to provide more readable failure messages. This consumes the stream. Take care if you intend to leave the stream un-consumed or if the stream is very large or infinite.
If you intend to make multiple assertions on the contents of the same stream, you should instead first collect the contents of the stream into a collection and then assert directly on that. For example:
List<Integer> list = makeStream().map(...).filter(...).boxed().collect(toImmutableList());
assertThat(list).contains(5L);
assertThat(list).doesNotContain(2L);
For very large or infinite streams, you may want to first limit the stream before asserting on it.
- Since:
- 1.3.0 (previously part of
truth-java8-extension)
-
Nested Class Summary
Nested classes/interfaces inherited from class Subject
Subject.Factory<SubjectT,ActualT> -
Method Summary
Modifier and TypeMethodDescriptionprotected StringReturns a string representation of the actual value for inclusion in failure messages.voidcontains(long element) Checks that the actual stream contains the given element.voidcontainsAnyIn(@Nullable Iterable<?> expected) Checks that the actual stream contains at least one of the given elements.voidcontainsAnyOf(long first, long second, long... rest) Checks that the actual stream contains at least one of the given elements.containsAtLeast(long first, long second, long... rest) Checks that the actual stream contains all of the given elements.containsAtLeastElementsIn(@Nullable Iterable<?> expected) Checks that the actual stream contains all of the given elements.containsExactly(long @Nullable ... expected) Checks that the actual stream contains exactly the given elements.containsExactlyElementsIn(@Nullable Iterable<?> expected) Checks that the actual stream contains exactly the given elements.voidChecks that the actual stream does not contain duplicate elements.voidcontainsNoneIn(@Nullable Iterable<?> excluded) Checks that the actual stream does not contain any of the given elements.voidcontainsNoneOf(long first, long second, long... rest) Checks that the actual stream does not contain any of the given elements.voiddoesNotContain(long element) Checks that the actual stream does not contain the given element.voidhasSize(int size) Checks that the actual stream has the given size.voidisEmpty()Checks that the actual stream is empty.voidChecks that the actual stream is ordered, according to the natural ordering of its elements.voidisInOrder(Comparator<? super Long> comparator) Checks that the actual stream is ordered, according to the given comparator.voidChecks that the actual stream is strictly ordered, according to the natural ordering of its elements.voidisInStrictOrder(Comparator<? super Long> comparator) Checks that the actual stream is strictly ordered, according to the given comparator.voidChecks that the actual stream is not empty.static Subject.Factory<LongStreamSubject, LongStream> Deprecated.Methods inherited from class Subject
check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toStringModifier and TypeMethodDescriptionprotected final StandardSubjectBuilderReturns a builder for creating a derived subject.final booleanDeprecated.Object.equals(Object)is not supported on Truth subjects.protected final voidfailWithActual(Fact first, Fact... rest) Fails, reporting a message with the given facts, followed by an automatically added fact of the form: but was: actual value.protected final voidfailWithActual(String key, @Nullable Object value) Fails, reporting a message with two "facts": key: value but was: actual value.protected final voidfailWithoutActual(Fact first, Fact... rest) Fails, reporting a message with the given facts, without automatically adding the actual value.final inthashCode()Deprecated.Object.hashCode()is not supported on Truth subjects.protected final StandardSubjectBuilderBegins a new call chain that ignores any failures.voidChecks that the value under test is equal to any of the given elements.voidChecks that the value under test is equal to the given object.voidChecks that the value under test is equal to any element in the given iterable.voidisInstanceOf(@Nullable Class<?> clazz) Checks that the value under test is an instance of the given class.voidChecks that the value under test is not equal to any of the given elements.voidisNotEqualTo(@Nullable Object other) Checks that the value under test is not equal to the given object.voidChecks that the value under test is not equal to any element in the given iterable.voidisNotInstanceOf(@Nullable Class<?> clazz) Checks that the value under test is not an instance of the given class.voidChecks that the value under test is not null.final voidisNotSameInstanceAs(@Nullable Object other) Checks that the value under test is not the same instance as the given object.voidisNull()Checks that the value under test is null.final voidisSameInstanceAs(@Nullable Object expected) Checks that the value under test is the same instance as the given object.toString()Deprecated.Object.toString()is not supported on Truth subjects.
-
Method Details
-
actualCustomStringRepresentation
Description copied from class:SubjectReturns a string representation of the actual value for inclusion in failure messages.Subjects should override this with care.
By default, this method returns
String.valueOf(getActualValue())for most types. It does have some special logic for a few cases, like arrays.- Overrides:
actualCustomStringRepresentationin classSubject
-
longStreams
Deprecated.Instead ofabout(longStreams()).that(...), use justthat(...). Similarly, instead ofassertAbout(longStreams()).that(...), use justassertThat(...).Obsolete factory instance. This factory was previously necessary for assertions likeassertWithMessage(...).about(longStreams()).that(stream)..... Now, you can perform assertions like that without theabout(...)call. -
isEmpty
public void isEmpty()Checks that the actual stream is empty. -
isNotEmpty
public void isNotEmpty()Checks that the actual stream is not empty. -
hasSize
public void hasSize(int size) Checks that the actual stream has the given size.If you'd like to check that your stream contains more than
Integer.MAX_VALUEelements, useassertThat(stream.count()).isEqualTo(...). -
contains
public void contains(long element) Checks that the actual stream contains the given element. -
doesNotContain
public void doesNotContain(long element) Checks that the actual stream does not contain the given element. -
containsNoDuplicates
public void containsNoDuplicates()Checks that the actual stream does not contain duplicate elements. -
containsAnyOf
public void containsAnyOf(long first, long second, long... rest) Checks that the actual stream contains at least one of the given elements. -
containsAnyIn
-
containsAtLeast
Checks that the actual stream contains all of the given elements. If an element appears more than once in the given elements, then it must appear at least that number of times in the actual elements.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. -
containsAtLeastElementsIn
Checks that the actual stream contains all of the given elements. If an element appears more than once in the given elements, then it must appear at least that number of times in the actual elements.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. -
containsExactly
Checks that the actual stream contains exactly the given elements.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 actual stream.
To also test that the contents appear in the given order, make a call to
inOrder()on the object returned by this method. -
containsExactlyElementsIn
Checks that the actual stream contains exactly the given elements.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 actual stream.
To also test that the contents appear in the given order, make a call to
inOrder()on the object returned by this method. -
containsNoneOf
public void containsNoneOf(long first, long second, long... rest) Checks that the actual stream does not contain any of the given elements. -
containsNoneIn
-
isInStrictOrder
public void isInStrictOrder()Checks that the actual stream is strictly ordered, according to the natural ordering of its elements. Strictly ordered means that each element in the stream is strictly greater than the element that preceded it.- Throws:
ClassCastException- if any pair of elements is not mutually ComparableNullPointerException- if any element is null
-
isInStrictOrder
Checks that the actual stream is strictly ordered, according to the given comparator. Strictly ordered means that each element in the stream is strictly greater than the element that preceded it.- Throws:
ClassCastException- if any pair of elements is not mutually Comparable
-
isInOrder
public void isInOrder()Checks that the actual stream is ordered, according to the natural ordering of its elements. Ordered means that each element in the stream is greater than or equal to the element that preceded it.- Throws:
ClassCastException- if any pair of elements is not mutually ComparableNullPointerException- if any element is null
-
isInOrder
Checks that the actual stream is ordered, according to the given comparator. Ordered means that each element in the stream is greater than or equal to the element that preceded it.- Throws:
ClassCastException- if any pair of elements is not mutually Comparable
-
about(longStreams()).that(...), use justthat(...).