I am using scalamock and am trying to verify that the close()
method in the RabbitMQ com.rabbitmq.client.Channel
class is getting called. The problem is the close()
method is overloaded with two options: close()
and close(int, String)
. I want to verify that the no arg version is getting called.
I have tried the following code:
import com.rabbit.client.Channel
import org.scalatest.Wordspec
import org.scalamock.scalatest.MockFactory
class MessageSubscriberSpecs extends WordSpec with MockFactory {
"A message subscriber" when {
"closing a connection" should {
// ... More test setup
"close the underlying connection" in {
val channelStub = stub[Channel]
(channelStub.close _).verify()
}
}
}
}
The line with verify()
on it does not compile because the compiler is confused about which overloaded function to call.
How do I verify that the no arg version of an overloaded function gets called?
Yes, it's confused of which function it should create:
Function0
orFunction2
(i.e. a function with 0 or 2 parameters)So let's solve this by explicitly defining a function with 0 parameters!