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

Simplify function mocking #105

Open
dalewking opened this issue Apr 30, 2024 · 0 comments
Open

Simplify function mocking #105

dalewking opened this issue Apr 30, 2024 · 0 comments

Comments

@dalewking
Copy link

dalewking commented Apr 30, 2024

The way you have the Funx types set up to allow for mocking functions is slightly verbose for setting up the mocks. If you turn the types into fun interfaces like this:

fun interface Fun0<R> : () -> R
fun interface Fun1<T1, R> : (T1) -> R
fun interface Fun2<T1, T2, R> : (T1, T2) -> R
fun interface Fun3<T1, T2, T3, R> : (T1, T2, T3) -> R
fun interface Fun4<T1, T2, T3, T4, R> : (T1, T2, T3, T4) -> R
fun interface Fun5<T1, T2, T3, T4, T5, R> : (T1, T2, T3, T4, T5) -> R

This lets you simplify your example for mocking functions down to this, eliminating all the references to invoke:

// Stub the mock function
every(block(response))
  .returns(file)

// Call something that calls the mock function
s3Client.getObject(request, block)

// Verify the call to the mock function
verify { block(response) }
    .wasInvoked(exactly = once)

In addition you need to add suspend versions of these.

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

1 participant