So I have this main() method that calls printResult() method and the printResult() has a lambda argument on second parameter like this:
class SomeClass() {
fun main(value: Int) {
printResult(value){ it ->
it + it
}
}
fun printResult(value: Int, sum: (Int) -> Int) {
val result = sum(value)
println(result)
}
}
Then in the unit test, I want to verify that every time the main() method is called, the printResult() should be invoked as well. So I write the unit test like this:
@Test
fun testMain_shouldInvokePrintResult() {
someClass.main(10)
verify(someClass).printResult(10){ any() }
}
I don't know what argument I should pass for printResult() method, that's why I used any(). But when I run the test, the compiler said:
Argument(s) are different! Wanted:
someClass.main(
10,
() (kotlin.Exception /* = java.lang.Exception */) -> kotlin.Unit
);
-> at com.mydomain.test.testMain_shouldInvokePrintResult(SomeClassTest.kt:49)
Actual invocations have different arguments:
someClass.main(
10,
() (kotlin.Exception /* = java.lang.Exception */) -> kotlin.Unit
);
-> at com.mydomain.SomeClass.printResult$lambda-27(SomeClass.kt:20)
So the compiler basically said different arguments but showed me no different on both invocation. What should I do? any help would be appreciated..