bsky
bsky

Reputation: 20222

Type mismatch for expectMsg, required Int

I have the following test class for an actor:

class SomeActorSpec extends TestKit(ActorSystem("testSystem"))
  with ImplicitSender
  with WordSpecLike with MustMatchers {

  it should "check the id of a submitted job" {
    val tester = TestProbe()
    val someActorRef = system.actorOf(Props(classOf[SomeActor]))

    tester.send(someActorRef, SomeMessage(UUID.randomUUID))
    tester.expectMsg(SomeReply("Not running"))
  }

}

I'm getting this error:

type mismatch;
[error]  found   : your.package.SomeReply
[error]  required: Int
[error]     tester.expectMsg(SomeReply("Not running"))

Why would expectMsg require an Int? I looked over different examples of using expectMsg and it was able to receive subtypes of the Message class.

Upvotes: 0

Views: 137

Answers (1)

Nikita
Nikita

Reputation: 4515

Strange, it loads implicit from another scope. I suggest you to write (as in your earlier question) this way:

import java.util.UUID

import akka.actor.{Actor, ActorSystem, Props}
import akka.testkit.{TestKit, TestProbe}
import org.scalatest.FlatSpec

class SomeActorSpec extends FlatSpec {

  it should "check the id of a submitted job" in new TestScope {
    val tester = TestProbe()

    tester.send(someActorRef, SomeMessage(UUID.randomUUID))
    tester.expectMsg(SomeReply("Not running"))
  }

  abstract class TestScope extends TestKit(ActorSystem("testSystem")) {
    val someActorRef = system.actorOf(Props(classOf[SomeActor]))
  }
}

case class SomeMessage(v: UUID)
case class SomeReply(msg: String)

class SomeActor() extends Actor {
  def receive = {
    case msg => sender() ! SomeReply("Not running")
  }
}

Upvotes: 2

Related Questions