kosi-libs / MocKMP

A mocking processor for Kotlin Multiplatform
https://kosi-libs.org/mockmp
MIT License
189 stars 12 forks source link

Multiple mocks of the same function type require separate mockers #58

Closed lupuuss closed 1 year ago

lupuuss commented 1 year ago

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.

SalomonBrys commented 1 year ago

Fix released in v1.14.0.