Package dev.aherscu.qa.testing.utils
Class StreamMatchersExtensions
- java.lang.Object
-
- dev.aherscu.qa.testing.utils.StreamMatchers
-
- dev.aherscu.qa.testing.utils.StreamMatchersExtensions
-
@ThreadSafe public class StreamMatchersExtensions extends StreamMatchers
Drop-in replacement for Java-8-matchers'StreamMatchers
.Can be statically imported along Hamcrest's
Matchers
.- Author:
- aherscu
-
-
Constructor Summary
Constructors Constructor Description StreamMatchersExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> org.hamcrest.Matcher<Stream<T>>
adapt(Supplier<Collection<T>> supplier, org.hamcrest.Matcher<Iterable<T>> matcher)
Adapts a Stream to be matched with an Iterable matcher.static <T,R>
org.hamcrest.Matcher<Stream<T>>adaptedStream(Function<T,R> converter, org.hamcrest.Matcher<Stream<R>> matcher)
Adapts a matcher of stream of objects by specified converter function.static <T> org.hamcrest.Matcher<Stream<T>>
anyStream(String... message)
static <T> org.hamcrest.Matcher<Stream<T>>
counts(long expectedNumberOfItems)
static <T> org.hamcrest.Matcher<Stream<T>>
counts(org.hamcrest.Matcher<Long> expectedNumberOfItems)
static <T> org.hamcrest.Matcher<Stream<T>>
emptyStream()
Fixes method signature fromStreamMatchers.empty()
.static <T> org.hamcrest.Matcher<Stream<T>>
hasItemsMatching(List<org.hamcrest.Matcher<T>> matchers)
A matcher for Stream of objects, must produce objects that match the given Matchers in given order.static <T> org.hamcrest.Matcher<Stream<T>>
hasItemsMatching(org.hamcrest.Matcher<T>... values)
A matcher for Stream of objects, must produce objects that match the given Matchers in given order.static <T> org.hamcrest.Matcher<Stream<T>>
hasItemsMatchingInAnyOrder(Set<org.hamcrest.Matcher<T>> matchers)
A matcher for Stream of objects, must produce objects that match the given Matchers.static <T> org.hamcrest.Matcher<Stream<T>>
hasItemsMatchingInAnyOrder(org.hamcrest.Matcher<T>... values)
A matcher for Stream of objects, must produce objects that match the given Matchers.static <T> org.hamcrest.Matcher<Stream<T>>
hasSpecificItems(List<T> values)
Wraps each of specified values intoCoreMatchers.is(org.hamcrest.Matcher<T>)
.static <T> org.hamcrest.Matcher<Stream<T>>
hasSpecificItems(T... values)
Wraps each of specified values intoCoreMatchers.is(org.hamcrest.Matcher<T>)
.static <T> org.hamcrest.Matcher<Stream<T>>
hasSpecificItemsInAnyOrder(Set<T> values)
Wraps each of specified values intoCoreMatchers.is(org.hamcrest.Matcher<T>)
.static <T> org.hamcrest.Matcher<Stream<T>>
hasSpecificItemsInAnyOrder(T... values)
Wraps each of specified values intoCoreMatchers.is(org.hamcrest.Matcher<T>)
.static <T> org.hamcrest.Matcher<Stream<T>>
orderedStream(com.google.common.collect.Ordering<T> ordering)
Matches an orderedStream
by specified ordering.static <T> org.hamcrest.Matcher<Stream<T>>
scanningAtMost(int limit, org.hamcrest.Matcher<Stream<T>> matcher)
Limits amount of scanned objects produced by a stream.-
Methods inherited from class dev.aherscu.qa.testing.utils.StreamMatchers
allMatch, allMatchDouble, allMatchInt, allMatchLong, anyMatch, anyMatchDouble, anyMatchInt, anyMatchLong, contains, contains, empty, equalTo, startsWith, startsWith, startsWith, startsWith, startsWith, startsWithAll, startsWithAllDouble, startsWithAllInt, startsWithAllLong, startsWithAny, startsWithAnyDouble, startsWithAnyInt, startsWithAnyLong, startsWithDouble, startsWithInt, startsWithLong, yieldsExactly, yieldsExactly, yieldsNothing, yieldsSameAs
-
-
-
-
Method Detail
-
adapt
public static <T> org.hamcrest.Matcher<Stream<T>> adapt(Supplier<Collection<T>> supplier, org.hamcrest.Matcher<Iterable<T>> matcher)
Adapts a Stream to be matched with an Iterable matcher. Use with combinable matchers.- Type Parameters:
T
- type of objects produced by the Stream- Parameters:
supplier
- the specific collection; e.g. ArrayList::newmatcher
- against which to compare objects from the Stream- Returns:
- adapted Iterable matcher
-
adaptedStream
public static <T,R> org.hamcrest.Matcher<Stream<T>> adaptedStream(Function<T,R> converter, org.hamcrest.Matcher<Stream<R>> matcher)
Adapts a matcher of stream of objects by specified converter function.- Type Parameters:
T
- type to be adaptedR
- type after adaption- Parameters:
converter
- the converter functionmatcher
- the matcher- Returns:
- adapted matcher
-
anyStream
public static <T> org.hamcrest.Matcher<Stream<T>> anyStream(String... message)
- Type Parameters:
T
- dummy matcher that matches anything- Parameters:
message
- optional, something to be added to description- Returns:
- something that matches any stream
-
counts
public static <T> org.hamcrest.Matcher<Stream<T>> counts(long expectedNumberOfItems)
-
counts
public static <T> org.hamcrest.Matcher<Stream<T>> counts(org.hamcrest.Matcher<Long> expectedNumberOfItems)
- Type Parameters:
T
- type of stream item- Parameters:
expectedNumberOfItems
- the expected number of items- Returns:
- the counting matcher
-
emptyStream
public static <T> org.hamcrest.Matcher<Stream<T>> emptyStream()
Fixes method signature fromStreamMatchers.empty()
.- Type Parameters:
T
- type of objects- Returns:
- an empty stream matcher
-
hasItemsMatching
public static <T> org.hamcrest.Matcher<Stream<T>> hasItemsMatching(List<org.hamcrest.Matcher<T>> matchers)
A matcher for Stream of objects, must produce objects that match the given Matchers in given order. Gaps between matched objects are acceptable.- Type Parameters:
T
- type of objects produced by the Stream- Parameters:
matchers
- against which to compare objects from the Stream- Returns:
- matcher for stream
-
hasItemsMatching
@SafeVarargs public static <T> org.hamcrest.Matcher<Stream<T>> hasItemsMatching(org.hamcrest.Matcher<T>... values)
A matcher for Stream of objects, must produce objects that match the given Matchers in given order. Gaps between matched objects are acceptable.- Type Parameters:
T
- type of objects produced by the Stream- Parameters:
values
- against which to compare objects from the Stream- Returns:
- matcher for stream
-
hasItemsMatchingInAnyOrder
public static <T> org.hamcrest.Matcher<Stream<T>> hasItemsMatchingInAnyOrder(Set<org.hamcrest.Matcher<T>> matchers)
A matcher for Stream of objects, must produce objects that match the given Matchers. Gaps between matched objects are acceptable.- Type Parameters:
T
- type of objects produced by the Stream- Parameters:
matchers
- against which to compare objects from the Stream- Returns:
- matcher for stream
-
hasItemsMatchingInAnyOrder
@SafeVarargs public static <T> org.hamcrest.Matcher<Stream<T>> hasItemsMatchingInAnyOrder(org.hamcrest.Matcher<T>... values)
A matcher for Stream of objects, must produce objects that match the given Matchers. Gaps between matched objects are acceptable.- Type Parameters:
T
- type of objects produced by the Stream- Parameters:
values
- against which to compare objects from the Stream- Returns:
- matcher for stream
-
hasSpecificItems
public static <T> org.hamcrest.Matcher<Stream<T>> hasSpecificItems(List<T> values)
Wraps each of specified values intoCoreMatchers.is(org.hamcrest.Matcher<T>)
.- Type Parameters:
T
- type of objects in stream- Parameters:
values
- expected objects- Returns:
- matcher for stream
- See Also:
hasItemsMatching(List)
-
hasSpecificItems
@SafeVarargs public static <T> org.hamcrest.Matcher<Stream<T>> hasSpecificItems(T... values)
Wraps each of specified values intoCoreMatchers.is(org.hamcrest.Matcher<T>)
.- Type Parameters:
T
- type of objects in stream- Parameters:
values
- expected objects- Returns:
- matcher for stream
- See Also:
hasItemsMatching(List)
-
hasSpecificItemsInAnyOrder
@SafeVarargs public static <T> org.hamcrest.Matcher<Stream<T>> hasSpecificItemsInAnyOrder(T... values)
Wraps each of specified values intoCoreMatchers.is(org.hamcrest.Matcher<T>)
.- Type Parameters:
T
- type of objects in stream- Parameters:
values
- expected objects- Returns:
- matcher for stream
- See Also:
hasItemsMatchingInAnyOrder(Set)
-
hasSpecificItemsInAnyOrder
public static <T> org.hamcrest.Matcher<Stream<T>> hasSpecificItemsInAnyOrder(Set<T> values)
Wraps each of specified values intoCoreMatchers.is(org.hamcrest.Matcher<T>)
.- Type Parameters:
T
- type of objects in stream- Parameters:
values
- expected objects- Returns:
- matcher for stream
- See Also:
hasItemsMatchingInAnyOrder(Set)
-
orderedStream
public static <T> org.hamcrest.Matcher<Stream<T>> orderedStream(com.google.common.collect.Ordering<T> ordering)
Matches an orderedStream
by specified ordering.- Parameters:
ordering
- the expected ordering- Returns:
- the ordering matcher
-
scanningAtMost
public static <T> org.hamcrest.Matcher<Stream<T>> scanningAtMost(int limit, org.hamcrest.Matcher<Stream<T>> matcher)
Limits amount of scanned objects produced by a stream.- Type Parameters:
T
- type of objects- Parameters:
limit
- how many objects to scan at mostmatcher
- delegate matcher- Returns:
- a stream limiting matcher
-
-