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

Document Argument Captors in README #52

Closed
TTransmit opened this issue Jul 25, 2016 · 1 comment
Closed

Document Argument Captors in README #52

TTransmit opened this issue Jul 25, 2016 · 1 comment

Comments

@TTransmit
Copy link

TTransmit commented Jul 25, 2016

It would be nice to have an example of the syntax for using Argument Captors in Mockito-Kotlin. I got caught out because I used argumentCaptor.capture() instead of capture(argumentCaptor).

Here is an example of what it could be.

Argument Captors

These overcome the issue that Mockito ArgumentCaptor.capture() returns null, which results in an IllegalStateException in Kotlin.

Kotlin:

val argumentCaptor = argumentCaptor<String>()
myClass.doSomething()
verify(classToMock).sendString(capture(argumentCaptor))

I can raise this as a pull request if helpful. I would suggest adding it below the Argument Matchers section.

@nhaarman
Copy link
Collaborator

The more idiomatic way is even:

myClass.doSomething()
verify(classToMock).sendString(capture { s ->
    assertEquals("test", s)
})

I will add an example to the readme.

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