Skip to content

Commit

Permalink
Merge branch 'unlimitedsola-2.x' into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaarman committed Jun 19, 2019
2 parents 76198ea + 84783a5 commit 0edd8fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package com.nhaarman.mockitokotlin2

import org.mockito.BDDMockito
import org.mockito.BDDMockito.BDDMyOngoingStubbing
import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer

/**
Expand Down Expand Up @@ -60,8 +61,8 @@ infix fun <T> BDDMyOngoingStubbing<T>.will(value: Answer<T>): BDDMockito.BDDMyOn
/**
* Alias for [BBDMyOngoingStubbing.willAnswer], accepting a lambda.
*/
infix fun <T> BDDMyOngoingStubbing<T>.willAnswer(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> {
return willAnswer { value() }
infix fun <T> BDDMyOngoingStubbing<T>.willAnswer(value: (InvocationOnMock) -> T?): BDDMockito.BDDMyOngoingStubbing<T> {
return willAnswer { value(it) }
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/src/test/kotlin/test/BDDMockitoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ class BDDMockitoTest {
expect(mock.stringResult()).toBe("Test")
}

@Test
fun given_willAnswerInfix_withInvocationInfo_properlyStubs() {
/* Given */
val mock = mock<Methods>()

/* When */
given(mock.stringResult(any())) willAnswer { invocation ->
(invocation.arguments[0] as String)
.reversed()
}

/* Then */
expect(mock.stringResult("Test")).toBe("tseT")
}

@Test(expected = IllegalStateException::class)
fun given_willThrowInfix_properlyStubs() {
/* Given */
Expand Down

0 comments on commit 0edd8fc

Please sign in to comment.