Here is simple example:

import akka.actor.{TypedActor, ActorSystem, TypedProps}
import akka.testkit.CallingThreadDispatcher
import org.mockito.Mockito
import org.scalatest.{BeforeAndAfterAll, WordSpec}

class FooTest extends WordSpec with BeforeAndAfterAll{
  trait Foo {
    def foo():Unit
  }

  class Bar {
    def bar():String = "bar"
  }

  class FooActor(bar: Bar) extends Foo {
    override def foo(): Unit = println(bar.bar())
  }

  val barSpy = Mockito.spy(new Bar)
  val typedProps = TypedProps(classOf[Foo], new 
FooActor(barSpy)).withDispatcher(CallingThreadDispatcher.Id)
  val actorSystem = ActorSystem("FooTest")



  "FooActor" should {
    "call Bar#bar() when foo is called" in {
      val fooActor : Foo = TypedActor(actorSystem).typedActorOf(typedProps)
      fooActor.foo()
      Mockito.verify(barSpy).bar()
    }
  }

  override protected def afterAll(): Unit = actorSystem.shutdown()
}




W dniu niedziela, 25 stycznia 2015 14:07:43 UTC+1 użytkownik Wojciech 
Pituła napisał:
>
> Is there any way of using TestActorRef with TypedActors ? Or any other way 
> of testing TypedActors with mocks?
>
> My problem is that with TestActorRef I can use Mockito and verify() works 
> fine. When using TypedActor with CallingThreadDispatcher verify() 
> works nondeterministic.
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to