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

Invalid mock generation for suspending functions with default implementation #32

Closed
xpathexception opened this issue Jul 20, 2022 · 1 comment

Comments

@xpathexception
Copy link

Tested with:

mockmp 1.6.0, 1.8.1
kotlin 1.6.20, 1.7.10

For interfaces, where suspending functions have default implementations, @Mock generates invalid mock implementation.

interface Sample {
    suspend fun sampleSuspending(): String = throw NotImplementedError()
}

Generated code (formatted for readability):

import org.kodein.mock.Mocker

internal class MockSample(
    private val mocker: Mocker,
) : Sample {
    public override suspend fun sampleSuspending(): String {
        return this.mocker.registerSuspend(
            receiver = this,
            method = "sampleSuspending()",
            default = { super.sampleSuspending() } // <=== Suspension functions can be called only within coroutine body
        )
    }

    public override fun toString(): String {
        return this.mocker.register(
            receiver = this,
            method = "toString()",
            default = { super.toString() }
        )
    }
}
@SalomonBrys
Copy link
Member

Version 1.9.0 published with the fix.

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