import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.testkit.javadsl.TestKit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class MyActorTest {
private ActorSystem system;
@Before
public void setUp() {
system = ActorSystem.create();
}
@After
public void tearDown() {
TestKit.shutdownActorSystem(system);
system = null;
}
@Test
public void testMyActor() {
new TestKit(system) {{
final TestKit probe = new TestKit(system);
// Create an instance of the actor to be tested
final ActorRef myActor = system.actorOf(MyActor.props());
// Send a message to the actor
myActor.tell("Hello", probe.getRef());
// Expect a response
probe.expectMsgEquals("World");
}};
}
}