pekko/akka-testkit/src/test/scala/akka/testkit/TestFSMRefSpec.scala
Roland 2381ec54d0 introduce AkkaApplication
- remove global Config
- pull everything which depended on it into new AkkaApplication
- leave EventHandler alone for the moment: that evil sucker gets his
  very own AkkaApplication("akka-reference.conf") until we have settled
  on an acceptable logging API without globals
- make akka-actor and akka-testkit compile
- TestKit uses implicit AkkaApplication passing for maximum convenience
- Actor object nearly completely removed, actor creation possible via
  ActorRefFactory interface which is implemented by AkkaApplication and
  ActorContext
- serialization of ActorRef is probably broken, and so is the reflective
  RemoteSupport (now needs AkkaApplication constructor arg)
- everything else is still broken, including akka-actor-tests, so this
  is of course all not runtime-tested
2011-10-06 21:19:46 +02:00

62 lines
1.6 KiB
Scala

/**
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.testkit
import org.scalatest.matchers.MustMatchers
import org.scalatest.{ BeforeAndAfterEach, WordSpec }
import akka.actor._
import akka.util.duration._
class TestFSMRefSpec extends TestKit with WordSpec with MustMatchers {
import FSM._
"A TestFSMRef" must {
"allow access to state data" in {
val fsm = TestFSMRef(new Actor with FSM[Int, String] {
startWith(1, "")
when(1) {
case Ev("go") goto(2) using "go"
case Ev(StateTimeout) goto(2) using "timeout"
}
when(2) {
case Ev("back") goto(1) using "back"
}
})
fsm.stateName must be(1)
fsm.stateData must be("")
fsm ! "go"
fsm.stateName must be(2)
fsm.stateData must be("go")
fsm.setState(stateName = 1)
fsm.stateName must be(1)
fsm.stateData must be("go")
fsm.setState(stateData = "buh")
fsm.stateName must be(1)
fsm.stateData must be("buh")
fsm.setState(timeout = 100 millis)
within(80 millis, 500 millis) {
awaitCond(fsm.stateName == 2 && fsm.stateData == "timeout")
}
}
"allow access to timers" in {
val fsm = TestFSMRef(new Actor with FSM[Int, Null] {
startWith(1, null)
when(1) {
case x stay
}
})
fsm.timerActive_?("test") must be(false)
fsm.setTimer("test", 12, 10 millis, true)
fsm.timerActive_?("test") must be(true)
fsm.cancelTimer("test")
fsm.timerActive_?("test") must be(false)
}
}
}