Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lupuuss opened this issue Apr 27, 2023 · 1 comment
Closed

Comments

@lupuuss
Copy link

lupuuss commented Apr 27, 2023

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
Copy link
Member

Fix released in v1.14.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants