Whenever multiple functions with the same signature are mocked within the same mocker, they are treated as one.
In test below, I would expect that function1 and function2 are registered as separate entities, but unfortunately they are both registered with invoke() name.
class Test {
private val mocker = Mocker()
private val function1: () -> Int = mockFunction0(mocker) { 1 }
private val function2: () -> Int = mockFunction0(mocker) { 2 }
@Test
fun test() {
// this assertion fails
// function1 and function2 return 1
assertNotEquals(function1.invoke() , function2.invoke())
}
}
I can see that mockFunctionX does not really consider return type so () -> Int and () -> List<Int> are registered as the same entity and it leads to ClassCastException (on JVM).
Even if this behavior is intentional, it makes mocking functions less useful.
Whenever multiple functions with the same signature are mocked within the same mocker, they are treated as one.
In test below, I would expect that
function1
andfunction2
are registered as separate entities, but unfortunately they are both registered withinvoke()
name.I can see that
mockFunctionX
does not really consider return type so() -> Int
and() -> List<Int>
are registered as the same entity and it leads toClassCastException
(on JVM).Even if this behavior is intentional, it makes mocking functions less useful.