changeset 6:230a3627b7d7

add test for 1.. 10
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 30 Jan 2018 12:57:59 +0900
parents 1265935f283c
children 3b99f171603d
files src/main/scala/IncrementSample.scala src/test/scala/IncrementSampleSpec.scala
diffstat 2 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/IncrementSample.scala	Mon Jan 29 18:25:05 2018 +0900
+++ b/src/main/scala/IncrementSample.scala	Tue Jan 30 12:57:59 2018 +0900
@@ -21,12 +21,10 @@
 
   def receive = {
     case SendData(data) =>
+        printerActor ! Println(data.toString)
         if (data < MAX_SIZE) {
           val send_data = data + 1
           otherActor ! SendData(send_data)
-          printerActor ! Println(send_data.toString)
-        } else {
-          printerActor ! Println("fin")
         }
     case SetActor(actor :ActorRef) =>
       otherActor = actor
--- a/src/test/scala/IncrementSampleSpec.scala	Mon Jan 29 18:25:05 2018 +0900
+++ b/src/test/scala/IncrementSampleSpec.scala	Tue Jan 30 12:57:59 2018 +0900
@@ -3,11 +3,13 @@
 import IncrementSample.Incrementer
 import IncrementSample.Incrementer._
 import IncrementSample.Incrementer.SetActor
-
+import IncrementSample.Printer.Println
 import akka.actor.ActorSystem
-import akka.testkit.{TestKit, TestProbe}
+import akka.pattern.ask
+import akka.testkit.{TestActorRef, TestFSMRef, TestKit, TestProbe}
 import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
 
+import scala.concurrent.duration._
 
 class IncrementSampleSpec(_system: ActorSystem)
   extends TestKit(_system) with WordSpecLike with Matchers with BeforeAndAfterAll {
@@ -21,12 +23,19 @@
   " Increment 1 to 10" in {
     val testProbe = TestProbe()
 
-    val actorOne = system.actorOf(Incrementer.props(testProbe.ref),"ActorOne")
-    val actorTwo = system.actorOf(Incrementer.props(testProbe.ref),"ActorTwo")
+
+    val actorOne = TestActorRef(Incrementer.props(testProbe.ref),"ActorOne")
+    val actorTwo = TestActorRef(Incrementer.props(testProbe.ref),"ActorTwo")
 
     actorOne ! SetActor(actorTwo)
     actorTwo ! SetActor(actorOne)
 
 
+    actorOne ! SendData(1)
+
+    for ( i <- 1 to 10 ) {
+      testProbe.expectMsg(500 millis, Println(s"$i"))
+    }
   }
+
 }
\ No newline at end of file