Scala:Specs2和Mockito:java.lang.NoSuchMethodError:org.mockito.internal.invocation.Invocation.isToString

时间:2013-10-25 23:12:44

标签: scala mockito specs2

我无法使用Specs2和Mockito运行我的Scala单元测试。

val response = mock[Response]

"MyResource" should {
    "handle NOT_FOUND from another WS" in {
      response.status returns NOT_FOUND // Exception thrown here
      anotherWS.getDetails("101010", "101") returns Future.successful(response)
      .....
    }

例外:

org.mockito.internal.invocation.Invocation.isToString(Lorg/mockito/invocation/InvocationOnMock;)Z
org.specs2.execute.Error$ThrowableException: NoSuchMethodError: org.mockito.internal.invocation.Invocation.isToString(Lorg/mockito/invocation/InvocationOnMock;)Z
Caused by: java.lang.NoSuchMethodError: org.mockito.internal.invocation.Invocation.isToString(Lorg/mockito/invocation/InvocationOnMock;)Z
    at org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues.answer(ReturnsEmptyValues.java:59)
    at org.mockito.internal.stubbing.defaultanswers.GloballyConfiguredAnswer.answer(GloballyConfiguredAnswer.java:24)
    at org.mockito.internal.MockHandler.handle(MockHandler.java:99)
    at org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodInterceptorFilter.java:47)

2 个答案:

答案 0 :(得分:1)

更新到mockito 1.9.5(使用1.8.5)修复了问题

答案 1 :(得分:0)

Mockito不支持模拟变量。 status对象上的response是变量吗?如果是这样,一个解决方案是定义一个getStatus()方法,然后模拟该方法。