2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
|
2014-02-21 12:43:30 +01:00
|
|
|
*/
|
|
|
|
|
|
2017-03-16 09:30:00 +01:00
|
|
|
package jdocs.actor;
|
2013-12-11 14:53:41 +01:00
|
|
|
|
|
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
import akka.actor.ActorSystem;
|
|
|
|
|
import akka.actor.Props;
|
2017-03-16 09:30:00 +01:00
|
|
|
import jdocs.AbstractJavaTest;
|
2017-03-17 03:02:47 +08:00
|
|
|
import akka.testkit.javadsl.TestKit;
|
2013-12-11 14:53:41 +01:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
2016-02-11 16:39:25 +01:00
|
|
|
public class SampleActorTest extends AbstractJavaTest {
|
2013-12-11 14:53:41 +01:00
|
|
|
|
|
|
|
|
static ActorSystem system;
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void setup() {
|
|
|
|
|
system = ActorSystem.create("SampleActorTest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void tearDown() {
|
2017-03-17 03:02:47 +08:00
|
|
|
TestKit.shutdownActorSystem(system);
|
2013-12-11 14:53:41 +01:00
|
|
|
system = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2019-01-12 04:00:53 +08:00
|
|
|
public void testSampleActor() {
|
|
|
|
|
new TestKit(system) {
|
|
|
|
|
{
|
|
|
|
|
final ActorRef subject = system.actorOf(Props.create(SampleActor.class), "sample-actor");
|
|
|
|
|
final ActorRef probeRef = getRef();
|
|
|
|
|
|
|
|
|
|
subject.tell(47.11, probeRef);
|
|
|
|
|
subject.tell("and no guard in the beginning", probeRef);
|
|
|
|
|
subject.tell("guard is a good thing", probeRef);
|
|
|
|
|
subject.tell(47.11, probeRef);
|
|
|
|
|
subject.tell(4711, probeRef);
|
|
|
|
|
subject.tell("and no guard in the beginning", probeRef);
|
|
|
|
|
subject.tell(4711, probeRef);
|
|
|
|
|
subject.tell("and an unmatched message", probeRef);
|
|
|
|
|
|
|
|
|
|
expectMsgEquals(47.11);
|
|
|
|
|
assertTrue(expectMsgClass(String.class).startsWith("startsWith(guard):"));
|
|
|
|
|
assertTrue(expectMsgClass(String.class).startsWith("contains(guard):"));
|
|
|
|
|
expectMsgEquals(47110);
|
|
|
|
|
expectNoMessage();
|
|
|
|
|
}
|
|
|
|
|
};
|
2013-12-11 14:53:41 +01:00
|
|
|
}
|
|
|
|
|
}
|