Skip to content

Commit 0edd8fc

Browse files
committed
Merge branch 'unlimitedsola-2.x' into 2.x
2 parents 76198ea + 84783a5 commit 0edd8fc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/BDDMockito.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package com.nhaarman.mockitokotlin2
2727

2828
import org.mockito.BDDMockito
2929
import org.mockito.BDDMockito.BDDMyOngoingStubbing
30+
import org.mockito.invocation.InvocationOnMock
3031
import org.mockito.stubbing.Answer
3132

3233
/**
@@ -60,8 +61,8 @@ infix fun <T> BDDMyOngoingStubbing<T>.will(value: Answer<T>): BDDMockito.BDDMyOn
6061
/**
6162
* Alias for [BBDMyOngoingStubbing.willAnswer], accepting a lambda.
6263
*/
63-
infix fun <T> BDDMyOngoingStubbing<T>.willAnswer(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> {
64-
return willAnswer { value() }
64+
infix fun <T> BDDMyOngoingStubbing<T>.willAnswer(value: (InvocationOnMock) -> T?): BDDMockito.BDDMyOngoingStubbing<T> {
65+
return willAnswer { value(it) }
6566
}
6667

6768
/**

tests/src/test/kotlin/test/BDDMockitoTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ class BDDMockitoTest {
9191
expect(mock.stringResult()).toBe("Test")
9292
}
9393

94+
@Test
95+
fun given_willAnswerInfix_withInvocationInfo_properlyStubs() {
96+
/* Given */
97+
val mock = mock<Methods>()
98+
99+
/* When */
100+
given(mock.stringResult(any())) willAnswer { invocation ->
101+
(invocation.arguments[0] as String)
102+
.reversed()
103+
}
104+
105+
/* Then */
106+
expect(mock.stringResult("Test")).toBe("tseT")
107+
}
108+
94109
@Test(expected = IllegalStateException::class)
95110
fun given_willThrowInfix_properlyStubs() {
96111
/* Given */

0 commit comments

Comments
 (0)