Verifying by-name parameters in Mockito

2019-07-05 07:52发布

Given

class UnderTest {
    def f(arg1: Int)(arg2: => Int) = ???
}

Trying do do this:

import org.mockito.Matchers
val objUnderTest = mock[UnderTest]
verify(objUnderTest).f(Matchers.eq(1))(Matchers.any())

fails with an "Invalid use of argument matchers!" exception, complaining that 2 matchers were expected, 1 was recorded.

Is using Mockito to verify calls to functions with multiple argument lists including by-name parameters possible?

1条回答
狗以群分
2楼-- · 2019-07-05 08:28

To my knowledge you can not mock byname parameters with Mockito. I've done it in specs2 but that requires to override some of the Mockito classes, which makes it possible but it is an ugly solution.

查看更多
登录 后发表回答