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

Provide better java interop #1208

Open
Sineaggi opened this issue Jan 16, 2024 · 1 comment
Open

Provide better java interop #1208

Sineaggi opened this issue Jan 16, 2024 · 1 comment

Comments

@Sineaggi
Copy link

Expected Behavior

The ability to call mockk functions from java, without much hassle.

For example, something like the following

import org.junit.jupiter.api.Test;

import static io.mockk.MockKKt.*;

class JavaTest {
    @Test
    public void test() {
        var car = mockk(Car.class);
        every(scope -> car.drive(Direction.NORTH)).returns(Outcome.OK);
        car.drive(Direction.NORTH); // returns OK
        verify(scope -> car.drive(Direction.NORTH));
        confirmVerified(car);
    }
}

Current Behavior

Can't call entrypoints (mockk, spyk) due to functions being marked as inline.

Thoughts on improving java integration

By creating additional non-inlined overloads, annotated with @JvmOverloads, it should be possible to provide an ok java experience.

I've opened a draft PR #1207 to show what the overloads would look like to provide a better java interop.

@Raibaz
Copy link
Collaborator

Raibaz commented Jan 17, 2024

Thanks for looking into this!

The non-inlined overloads look good to me.

Feel free to finish the PR and I'll be super glad to review it :)

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