Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BDD will extension function #313

Merged
merged 1 commit into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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