Skip to content

Commit efccc0b

Browse files
authored
Merge pull request #313 from casadogg/2.x
Add BDD will extension function
2 parents a6bd76f + a0648e2 commit efccc0b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 8 additions & 0 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.stubbing.Answer
3031

3132
/**
3233
* Alias for [BDDMockito.given].
@@ -49,6 +50,13 @@ fun <T> then(mock: T): BDDMockito.Then<T> {
4950
return BDDMockito.then(mock)
5051
}
5152

53+
/**
54+
* Alias for [BDDMyOngoingStubbing.will]
55+
* */
56+
infix fun <T> BDDMyOngoingStubbing<T>.will(value: Answer<T>): BDDMockito.BDDMyOngoingStubbing<T> {
57+
return will(value)
58+
}
59+
5260
/**
5361
* Alias for [BBDMyOngoingStubbing.willAnswer], accepting a lambda.
5462
*/

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ package test
33
import com.nhaarman.expect.expect
44
import com.nhaarman.mockitokotlin2.*
55
import org.junit.Test
6+
import org.mockito.stubbing.Answer
67

78
class BDDMockitoTest {
89

10+
@Test
11+
fun given_will_properlyStubs() {
12+
/* Given */
13+
val mock = mock<Methods>()
14+
15+
/* When */
16+
given(mock.stringResult()) will Answer<String> { "Test" }
17+
18+
/* Then */
19+
expect(mock.stringResult()).toBe("Test")
20+
}
21+
922
@Test
1023
fun given_willReturn_properlyStubs() {
1124
/* Given */

0 commit comments

Comments
 (0)