Skip to content

Commit

Permalink
Merge branch '2.x' into checketts-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaarman committed Jul 5, 2019
2 parents 9c90f0f + b850ab1 commit 77bfcdd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ matrix:
- jdk: oraclejdk8
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.2.50
- jdk: oraclejdk8
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.3.0
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.3.40
- jdk: oraclejdk8
env: TERM=dumb KOTLIN_VERSION=1.0.7
- jdk: oraclejdk8
env: TERM=dumb KOTLIN_VERSION=1.1.61
- jdk: oraclejdk8
env: TERM=dumb KOTLIN_VERSION=1.2.50
- jdk: oraclejdk8
env: TERM=dumb KOTLIN_VERSION=1.3.0
env: TERM=dumb KOTLIN_VERSION=1.3.40


env:
Expand Down
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.invocation.InvocationOnMock
import org.mockito.stubbing.Answer

/**
Expand Down Expand Up @@ -60,8 +61,8 @@ infix fun <T> BDDMyOngoingStubbing<T>.will(value: Answer<T>): BDDMockito.BDDMyOn
/**
* Alias for [BBDMyOngoingStubbing.willAnswer], accepting a lambda.
*/
infix fun <T> BDDMyOngoingStubbing<T>.willAnswer(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> {
return willAnswer { value() }
infix fun <T> BDDMyOngoingStubbing<T>.willAnswer(value: (InvocationOnMock) -> T?): BDDMockito.BDDMyOngoingStubbing<T> {
return willAnswer { value(it) }
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/src/test/kotlin/test/BDDMockitoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ class BDDMockitoTest {
expect(mock.stringResult()).toBe("Test")
}

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

/* When */
given(mock.stringResult(any())) willAnswer { invocation ->
(invocation.arguments[0] as String)
.reversed()
}

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

@Test(expected = IllegalStateException::class)
fun given_willThrowInfix_properlyStubs() {
/* Given */
Expand Down

0 comments on commit 77bfcdd

Please sign in to comment.