With the following test I have an invalid stub setup. The mock requestBuilder
is stubbed with the param "INCORRECT"
, whereas the class under test invokes it with "/socket"
.
My experience with Mockito in JUnit tells me that the invocation at runtime will result in null
. However, I'm seeing a false positive. The test passes & the requestBuilder
is returning the mock request
, even though it is invoked with "/socket"
.
Why is this? Has it something to do with having more than one expectation? If so, the final expectation is the one that counts and it should fail.
class ChannelSpec extends Specification with Mockito with ScalaCheck with ArbitraryValues { def is = s2"""
A Channel must
send an open request to /socket with provided channel name on instantiation $sendToSocket
"""
def sendToSocket = prop{(name: String, key: Key, secret: Secret) =>
val requestBuilder = mock[(String, Seq[Map[String, String]]) => Req]
val request = mock[Req]
val httpRequestor = mock[(Req) => Future[String]]
val result = mock[Future[String]]
val params = Seq(Map("key" -> key.value, "timestamp" -> anyString, "token" -> anyString), Map("channel" -> name))
requestBuilder("INCORRECT", params) returns request
httpRequestor(request) returns result
new Channel(name, key, secret, requestBuilder = requestBuilder, httpRequestor = httpRequestor)
there was one(requestBuilder).apply("INCORRECT", params)
println("expecting " + request)
there was one(httpRequestor).apply(request)
}