I've got some code dealing with HTTP requests and I want to unit-test it.
Thus I'm trying to mock dispatch.Http or even better dispatch.HttpExecutor (0.8.5) with Scala (2.9.1.final), Mockito (1.9.0-rc1) and ScalaTest (1.6.1) but even can't make my test code compilable.
Here in MyHttpTest I want to receive certain HTTP response for any HTTP request:
import org.scalatest.FunSuite
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito.when
import org.mockito.Matchers.any
import dispatch._
class MyHttpTest extends FunSuite with MockitoSugar {
test("example") {
val httpMock = mock[HttpExecutor]
when(httpMock.apply(any(classOf[Handler[String]]))).thenReturn("Some_HTTP_response")
}
}
But it produces compilation error:
error: overloaded method value thenReturn with alternatives:
(httpMock.HttpPackage[String],<repeated...>[httpMock.HttpPackage[String]])org.mockito.stubbing.OngoingStubbing[httpMock.HttpPackage[String]] <and>
(httpMock.HttpPackage[String])org.mockito.stubbing.OngoingStubbing[httpMock.HttpPackage[String]]
cannot be applied to (java.lang.String)
when(httpMock.apply(any(classOf[Handler[String]]))).thenReturn("Some_response")
So how to mock dispatch client?