Skip to content

Commit

Permalink
Add BDD will extension function
Browse files Browse the repository at this point in the history
  • Loading branch information
gaburielcasado committed Dec 15, 2018
1 parent ec75b8a commit a0648e2
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 a0648e2

Please sign in to comment.