BehaviorTestKit: get child inbox by anonymous ActorRef
This commit is contained in:
parent
cc0705483b
commit
50e9b14d0b
4 changed files with 17 additions and 2 deletions
|
|
@ -50,6 +50,9 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
|
||||||
inbox.get
|
inbox.get
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def childInbox[U](ref: ActorRef[U]): TestInboxImpl[U] =
|
||||||
|
childInbox(ref.path.name)
|
||||||
|
|
||||||
override def childTestKit[U](child: ActorRef[U]): BehaviorTestKitImpl[U] = ctx.childTestKit(child)
|
override def childTestKit[U](child: ActorRef[U]): BehaviorTestKitImpl[U] = ctx.childTestKit(child)
|
||||||
|
|
||||||
override def selfInbox(): TestInboxImpl[T] = ctx.selfInbox
|
override def selfInbox(): TestInboxImpl[T] = ctx.selfInbox
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,12 @@ abstract class BehaviorTestKit[T] {
|
||||||
*/
|
*/
|
||||||
def childInbox[U](name: String): TestInbox[U]
|
def childInbox[U](name: String): TestInbox[U]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the child inbox for the child with the given name, or fail if there is no child with the given name
|
||||||
|
* spawned
|
||||||
|
*/
|
||||||
|
def childInbox[U](child: ActorRef[U]): TestInbox[U]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the [[akka.actor.typed.Behavior]] testkit for the given child [[akka.actor.typed.ActorRef]].
|
* Get the [[akka.actor.typed.Behavior]] testkit for the given child [[akka.actor.typed.ActorRef]].
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,11 @@ trait BehaviorTestKit[T] {
|
||||||
*/
|
*/
|
||||||
def childInbox[U](name: String): TestInbox[U]
|
def childInbox[U](name: String): TestInbox[U]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the child inbox for the child ActorRef, or fail if there is no such child.
|
||||||
|
*/
|
||||||
|
def childInbox[U](child: ActorRef[U]): TestInbox[U]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the [[akka.actor.typed.Behavior]] testkit for the given child [[akka.actor.typed.ActorRef]].
|
* Get the [[akka.actor.typed.Behavior]] testkit for the given child [[akka.actor.typed.ActorRef]].
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,9 @@ class SyncTestingExampleSpec extends WordSpec with Matchers {
|
||||||
//#test-child-message-anonymous
|
//#test-child-message-anonymous
|
||||||
val testKit = BehaviorTestKit(myBehavior)
|
val testKit = BehaviorTestKit(myBehavior)
|
||||||
testKit.run(SayHelloToAnonymousChild)
|
testKit.run(SayHelloToAnonymousChild)
|
||||||
// Anonymous actors are created as: $a $b etc
|
val child = testKit.expectEffectType[SpawnedAnonymous[String]]
|
||||||
val childInbox = testKit.childInbox[String](s"$$a")
|
|
||||||
|
val childInbox = testKit.childInbox(child.ref)
|
||||||
childInbox.expectMessage("hello stranger")
|
childInbox.expectMessage("hello stranger")
|
||||||
//#test-child-message-anonymous
|
//#test-child-message-anonymous
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue