In the Akka Scala API you can call receiveWhile to receive messages sent to a TestProbe:
val msgs = testProbe.receiveWhile(5.seconds) {
case x => ...
}
In the Java API you can do something similar, but I could not find a way to use ReceiveWhile with a TestProbe:
final CurrentState[] msgs =
new ReceiveWhile<CurrentState>(CurrentState.class, duration("5 seconds")) {
protected CurrentState match(Object in) {
if (in instanceof CurrentState) {
CurrentState cs = (CurrentState) in;
// ...
return cs;
}
throw noMatch();
}
}.get(); // this extracts the received messages
Is there a way to do this in the Java API where the messages are sent to a TestProbe?