add TestFSMRefSpec and make TestFSMRef better accessible

- add address argument to TestFSMRef factory
- set address of TestKit.testActor to "testActor#" with monotonically
  increasing number #
This commit is contained in:
Roland 2011-06-05 10:45:27 +02:00
parent b1533cb3d8
commit 3d40a0f529
5 changed files with 132 additions and 49 deletions

View file

@ -5,7 +5,9 @@
package akka.testkit
import akka.actor._
import akka.util.Duration
import akka.util._
import com.eaio.uuid.UUID
/**
* This is a specialised form of the TestActorRef with support for querying and
@ -32,7 +34,7 @@ import akka.util.Duration
* @author Roland Kuhn
* @since 1.2
*/
class TestFSMRef[S, D, T <: Actor with FSM[S, D]](factory: () => T) extends TestActorRef(factory) {
class TestFSMRef[S, D, T <: Actor](factory: () T, address: String)(implicit ev: T <:< FSM[S, D]) extends TestActorRef(factory, address) {
private def fsm = underlyingActor
@ -52,9 +54,8 @@ class TestFSMRef[S, D, T <: Actor with FSM[S, D]](factory: () => T) extends Test
* corresponding transition initiated from within the FSM, including timeout
* and stop handling.
*/
def setState(stateName: S = fsm.stateName, stateData: D = fsm.stateData, timeout: Option[Duration] = None) {
val f = fsm // needed to make the following type-check
f.applyState(f.State(stateName, stateData, timeout))
def setState(stateName: S = fsm.stateName, stateData: D = fsm.stateData, timeout: Option[Duration] = None, stopReason: Option[FSM.Reason] = None) {
fsm.applyState(FSM.State(stateName, stateData, timeout, stopReason))
}
/**
@ -74,4 +75,17 @@ class TestFSMRef[S, D, T <: Actor with FSM[S, D]](factory: () => T) extends Test
*/
def timerActive_?(name: String) = fsm.timerActive_?(name)
override def start(): this.type = {
super.start()
this
}
}
object TestFSMRef {
def apply[S, D, T <: Actor](factory: T)(implicit ev: T <:< FSM[S, D]): TestFSMRef[S, D, T] = new TestFSMRef(() factory, new UUID().toString)
def apply[S, D, T <: Actor](factory: T, address: String)(implicit ev: T <:< FSM[S, D]): TestFSMRef[S, D, T] = new TestFSMRef(() factory, address)
}