Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verifying by-name parameters in Mockito

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?

like image 703
MHarris Avatar asked Dec 11 '25 19:12

MHarris


1 Answers

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.

like image 127
Eric Avatar answered Dec 15 '25 00:12

Eric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!