0

我正在 akk-http 中编写其余测试用例,我在语句中收到此错误。when(mockedRepository.getAllFromModule).thenReturn(x)我的类如下:

class GetModulesRestTest extends WordSpec with Matchers with ScalatestRouteTest with MockitoSugar {


  val mockedRepository = mock[ImplModuleRepository]
  val dummyRoutes = new GetModulesRest().routes
  val inputData = Modules(1L,Some("ModuleName"), Some("SomeDescription"), false)


val dataJson = """[{"id": 1,"name": "HR","description": "This is about HR module","isRemoved": false}]"""

  "Check Software Test" should {

"check for java and zookeeper installation" in {

  val x = Future(Seq(inputData))

  when(mockedRepository.getAllFromModule).thenReturn(x)
  Get("/getmodules") ~> dummyRoutes ~> check {

    responseAs[String] shouldBe dataJson
  }
}
  }
}

ImplModuleRepository是一个抽象类,它从 postgres 数据库返回所有模块的列表,程序显示如上所述的错误,实际上语句 theReturn(x) 没有编译并且在编译时显示此错误:

Error:(32, 47) overloaded method value thenReturn with alternatives:

  (x$1: scala.concurrent.Future[Seq[com.reactore.launchpad.entity.Modules]],x$2: scala.concurrent.Future[Seq[com.reactore.launchpad.entity.Modules]]*)org.mockito.stubbing.OngoingStubbing[scala.concurrent.Future[Seq[com.reactore.launchpad.entity.Modules]]] <and>
  (x$1: scala.concurrent.Future[Seq[com.reactore.launchpad.entity.Modules]])org.mockito.stubbing.OngoingStubbing[scala.concurrent.Future[Seq[com.reactore.launchpad.entity.Modules]]]
 cannot be applied to (scalaz.concurrent.Future[Seq[com.reactore.launchpad.entity.Modules]])
      when(mockedRepository.getAllFromModule).thenReturn(x)

我不知道出了什么问题。

4

1 回答 1

1

(来自评论):

看起来您正在导入并在测试中使用 Future 的 Scalaz 版本,但不是在ImplModuleRepository.

于 2015-09-13T08:49:57.073 回答