Skip to content

Commit

Permalink
Merge pull request #313 from casadogg/2.x
Browse files Browse the repository at this point in the history
Add BDD will extension function
  • Loading branch information
nhaarman authored Dec 31, 2018
2 parents a6bd76f + a0648e2 commit efccc0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 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.stubbing.Answer

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

/**
* Alias for [BDDMyOngoingStubbing.will]
* */
infix fun <T> BDDMyOngoingStubbing<T>.will(value: Answer<T>): BDDMockito.BDDMyOngoingStubbing<T> {
return will(value)
}

/**
* Alias for [BBDMyOngoingStubbing.willAnswer], accepting a lambda.
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/src/test/kotlin/test/BDDMockitoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ package test
import com.nhaarman.expect.expect
import com.nhaarman.mockitokotlin2.*
import org.junit.Test
import org.mockito.stubbing.Answer

class BDDMockitoTest {

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

/* When */
given(mock.stringResult()) will Answer<String> { "Test" }

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

@Test
fun given_willReturn_properlyStubs() {
/* Given */
Expand Down

0 comments on commit efccc0b

Please sign in to comment.