From bea33b6d92ae8be68d0e3480bef1911f2f57a7cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Thu, 22 Sep 2016 22:22:56 +0200 Subject: [PATCH] Add JavaTestKit example --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5305ada..4a2f6c7 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ The ActorSystemRule may be used either as a @Rule (invoked around test methods) public class SimpleAkkaTest { @Rule - public ActorSystemRule actorSystemRule = ActorSystemRule.builder().setName(getClass().getSimpleName()).build(); + public ActorSystemRule actorSystemRule = new ActorSystemRuleBuilder().setName(getClass().getSimpleName()).build(); @Test public void testRuleUsingASingleActor() throws Exception { @@ -52,8 +52,19 @@ public class SimpleAkkaTest { final String message = "test"; actorTestActorRef.tell(message, ActorRef.noSender()); assertEquals(message, actorTestActorRef.underlyingActor().received.peek()); + + // Use the testKit() to get an instance of JavaTestKit directly + // In this example EchoActor simply sends the message to the designated sender actor + final JavaTestKit testKit = actorSystemRule.testKit(); + final Props simpleActorProps = Props.create(EchoActor.class); + final ActorRef simpleActor = actorSystemRule.system().actorOf(simpleActorProps); + simpleActor.tell("A great message", testKit.getTestActor()); // Use testActor as sender + testKit.expectMsgEquals(FiniteDuration.apply(1L, TimeUnit.SECONDS), "A great message"); + } + + } ```