Add expectNextChainingPF method to streams testkit #21614 (#21617)

Add expectNextChainingPF method to streams testkit #21614

Improved error messages on expectNextPf, expectNextPfChaining, expectEventPF
This commit is contained in:
Kirill Yankov 2016-10-17 18:08:09 +03:00 committed by Martynas Mickevičius
parent 375c032604
commit 7eb660b497
2 changed files with 56 additions and 4 deletions

View file

@ -530,14 +530,21 @@ object TestSubscriber {
def expectNextPF[T](f: PartialFunction[Any, T]): T = {
expectEventPF {
case OnNext(n)
assert(f.isDefinedAt(n))
f(n)
case OnNext(n) if f.isDefinedAt(n) f(n)
}
}
/**
* Expect next element and test it with partial function.
*
* Allows chaining probe methods.
*/
def expectNextChainingPF(f: PartialFunction[Any, Any]): Self = {
expectNextPF(f.andThen(_ self))
}
def expectEventPF[T](f: PartialFunction[SubscriberEvent, T]): T =
probe.expectMsgPF[T]()(f.asInstanceOf[PartialFunction[Any, T]])
probe.expectMsgPF[T](hint = "message matching partial function")(f.asInstanceOf[PartialFunction[Any, T]])
/**
* Receive messages for a given duration or until one does not match a given partial function.