Verifying by-name parameters in Mockito

我与影子孤独终老i 提交于 2019-12-10 19:28:38

问题


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:


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.



来源:https://stackoverflow.com/questions/24323213/verifying-by-name-parameters-in-mockito

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!