使用Scala和Mockito在Spray/Akka路由器中调用验证函数

使用Scala和Mockito在Spray/Akka路由器中调用验证函数,scala,routing,mockito,akka,spray,Scala,Routing,Mockito,Akka,Spray,我试图验证路由器中的函数是否正在被调用,但每次调用时,我都会收到这样一个错误,即没有与模拟对象进行交互 我想验证的函数是doStuff函数,因此我模拟modelService对象 这是我的设置: //Router val foo(user: String, _: String, containerId: Long) => pathPrefix("foo"){ path("bar") { post { entity(as[someJson]) { report =>

我试图验证路由器中的函数是否正在被调用,但每次调用时,我都会收到这样一个错误,即没有与模拟对象进行交互

我想验证的函数是
doStuff
函数,因此我模拟
modelService
对象

这是我的设置:

//Router
val foo(user: String, _: String, containerId: Long) => pathPrefix("foo"){
path("bar") {
    post {
      entity(as[someJson]) { report =>
        val actions = () => (for {
          msg <- eitherT((someActor? reportFunction(report.name, report.modelsTasks, user)).mapTo[\/[String, reportJson]])
          id <- eitherT(Future.successful(msg.id.toRightDisjunction("Cannot obtain id")))
          model <- eitherT(modelService.doStuff(user, id, containerId, report.asReportComponent()).
            map(_.right[String]))
        } yield model).run
        handleResult(actions())
      }
    }
  }
}

 \\Test
    "do some stuff when asked" in {
       when(modelService.doStuff(eqTo("unknown"), 
        any[String], eqTo(1L), any[reportComponent]))
        .thenReturn(Future.successful(expectedApp))
     Post("/foo/bar", someJson("Test")) ~>
      foo("unknown", "127.0.0.1", 1L) ~> check {
       verify( modelService, times(1) ).doStuff(eqTo("unknown"), any[String], eqTo(1L), any[reportComponent])
  }
}
//路由器
val foo(user:String,u:String,containerId:Long)=>pathPrefix(“foo”){
路径(“条”){
职位{
实体(作为[someJson]){report=>
val操作=()=>(对于{
msg位于com.this.test.spec.apply(thistspec.scala:112)
实际上,与这个模拟没有任何交互。

您是如何注入模拟的?您能否在测试中发布您是如何创建路由器类的

另外,您是否检查了
msg
Wanted but not invoked:
modelService.doStuff(
     "unknown",
     <any>,
     1,
     <any>
 );
 -> at com.this.test.spec.apply(ThisTestSpec.scala:112)
 Actually, there were zero interactions with this mock.