Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
Add JavaTestKit example
Browse files Browse the repository at this point in the history
  • Loading branch information
zapodot committed Sep 22, 2016
1 parent 9d7896d commit bea33b6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");


}


}
```

Expand Down

0 comments on commit bea33b6

Please sign in to comment.