title: Call doAnswer with function as argument in scala play 2.4
body: <p>I want to mock a method taking a callback in argument let's say:</p>
  
  <pre><code>methodToMock[T](callback: (String, String) =&gt; T)
  </code></pre>
  
  <p>With <strong>play 2.3</strong>, (specs2 version 2.3.8) I managed to do it with the method <code>doAnswer</code> from mockito:</p>
  
  <pre><code>doAnswer({ invocation =&gt;
    val method = invocation.asInstanceOf[(String, String) =&gt; Any] // L.34
    method(role, key)
  }).when(myMock).methodToMock[Any](any)
  </code></pre>
  
  <p>But since <strong>play 2.4</strong> (using special dependency <em>specs2</em>, version 2.4.2), the previous code won't work, telling me:</p>
  
  <pre><code>[Ljava.lang.Object; cannot be cast to scala.Function2 (MySpec.scala:34)
  </code></pre>
  
  <p>I don't really understand why mockito start using Java objects in my code, since I'm using the <a href="https://github.com/etorreborre/specs2/blob/master/mock/src/main/scala/org/specs2/mock/mockito/MockitoStubs.scala" rel="nofollow">specs2 implementation</a> and didn't find any documentation about modifications on <code>doAnswer</code>, nor usage example of my use case.</p>
  
  <p>Do you have any idea of what I did wrong and a way to solve this?</p>
  
  <p><em>EDIT</em>: </p>
  
  <p>I wanted to show a simplified case, but that deleted the source of the problem... The real definition of the method also takes an implicit arguments list:</p>
  
  <pre><code>methodToMock[T](callback: (String, String) =&gt; T)(implicit value: String)
  </code></pre>
  
  <p>Which means that <em>specs2</em> seems to return an array instead of a single element (its behaviour really changed between the two versions though).</p>
  
  <p>The following code now works </p>
  
  <pre><code>doAnswer({ invocation =&gt;
    val firstArgList = invocation.asInstanceOf[Array[Object]](0)
    val method = firstArgList.asInstanceOf[(String, String) =&gt; Any] // L.34
    method(role, key)
  }).when(myMock).methodToMock[Any](any)(any)
  </code></pre>