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

itAnswers should allow original Mockito Answer types #83

Closed
jpopadak opened this issue Dec 8, 2017 · 1 comment
Closed

itAnswers should allow original Mockito Answer types #83

jpopadak opened this issue Dec 8, 2017 · 1 comment

Comments

@jpopadak
Copy link

jpopadak commented Dec 8, 2017

In order to return the first argument using the infix notations, this is what I am required to do without any additional functions:

When calling questionService.updateQuestion(any()) itAnswers { it.getArgument(0) }

Rather, in the original Mockito or even in com.nhaarman:mockito-kotlin I can do this notation:

whenever(questionService.updateQuestion(any())).then(returnsFirstArg<Question>())

In order to achieve this, I must use the following function that should be added to your API:

infix fun <T> OngoingStubbing<T>.itAnswers(value: Answer<T>): OngoingStubbing<T> = this.thenAnswer(value)

You could also include these to make the grammar more accurate with the arguments:

fun <T> withFirstArg(): Answer<T> = org.mockito.AdditionalAnswers.returnsFirstArg()
fun <T> withSecondArg(): Answer<T> = org.mockito.AdditionalAnswers.returnsSecondArg()
fun <T> withThirdArg(): Answer<T> = org.mockito.AdditionalAnswers.returnsArgAt(3)
fun <T> withFourthArg(): Answer<T> = org.mockito.AdditionalAnswers.returnsArgAt(4)
fun <T> withLastArg(): Answer<T> = org.mockito.AdditionalAnswers.returnsLastArg()

The combination of this all allows me to do the following:

When calling questionRepo.save(any(Question::class)) itAnswers withFirstArg()

MarkusAmshove added a commit that referenced this issue Dec 10, 2017
Resolves #83 - `itAnswers` should allow original Mockito Answer types
@MarkusAmshove
Copy link
Owner

I've just released v1.32 which contains these changes 👍

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

No branches or pull requests

2 participants