-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from nhaarman/release-1.1.0
Release 1.1.0
- Loading branch information
Showing
9 changed files
with
328 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/BDDMockito.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.nhaarman.mockito_kotlin | ||
|
||
import org.mockito.BDDMockito | ||
|
||
fun <T> given(methodCall: T): BDDMockito.BDDMyOngoingStubbing<T> = BDDMockito.given(methodCall) | ||
fun <T> given(methodCall: () -> T) = given(methodCall()) | ||
|
||
fun <T> then(mock: T): BDDMockito.Then<T> = BDDMockito.then(mock) | ||
|
||
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willAnswer(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> = willAnswer { value() } | ||
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willReturn(value: () -> T): BDDMockito.BDDMyOngoingStubbing<T> = willReturn(value()) | ||
infix fun <T> BDDMockito.BDDMyOngoingStubbing<T>.willThrow(value: () -> Throwable): BDDMockito.BDDMyOngoingStubbing<T> = willThrow(value()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package test | ||
|
||
import com.nhaarman.expect.expect | ||
import com.nhaarman.mockito_kotlin.* | ||
import org.junit.Test | ||
|
||
class BDDMockitoTest { | ||
|
||
@Test | ||
fun given_willReturn_properlyStubs() { | ||
/* Given */ | ||
val mock = mock<Methods>() | ||
|
||
/* When */ | ||
given(mock.stringResult()).willReturn("Test") | ||
|
||
/* Then */ | ||
expect(mock.stringResult()).toBe("Test") | ||
} | ||
|
||
@Test | ||
fun givenLambda_willReturn_properlyStubs() { | ||
/* Given */ | ||
val mock = mock<Methods>() | ||
|
||
/* When */ | ||
given { mock.stringResult() }.willReturn("Test") | ||
|
||
/* Then */ | ||
expect(mock.stringResult()).toBe("Test") | ||
} | ||
|
||
@Test | ||
fun given_willReturnLambda_properlyStubs() { | ||
/* Given */ | ||
val mock = mock<Methods>() | ||
|
||
/* When */ | ||
given(mock.stringResult()).willReturn { "Test" } | ||
|
||
/* Then */ | ||
expect(mock.stringResult()).toBe("Test") | ||
} | ||
|
||
@Test | ||
fun givenLambda_willReturnLambda_properlyStubs() { | ||
/* Given */ | ||
val mock = mock<Methods>() | ||
|
||
/* When */ | ||
given { mock.stringResult() } willReturn { "Test" } | ||
|
||
/* Then */ | ||
expect(mock.stringResult()).toBe("Test") | ||
} | ||
|
||
@Test | ||
fun given_willAnswer_properlyStubs() { | ||
/* Given */ | ||
val mock = mock<Methods>() | ||
|
||
/* When */ | ||
given(mock.stringResult()).willAnswer { "Test" } | ||
|
||
/* Then */ | ||
expect(mock.stringResult()).toBe("Test") | ||
} | ||
|
||
@Test | ||
fun given_willAnswerInfix_properlyStubs() { | ||
/* Given */ | ||
val mock = mock<Methods>() | ||
|
||
/* When */ | ||
given(mock.stringResult()) willAnswer { "Test" } | ||
|
||
/* Then */ | ||
expect(mock.stringResult()).toBe("Test") | ||
} | ||
|
||
@Test(expected = IllegalStateException::class) | ||
fun given_willThrowInfix_properlyStubs() { | ||
/* Given */ | ||
val mock = mock<Methods>() | ||
|
||
/* When */ | ||
given(mock.stringResult()) willThrow { IllegalStateException() } | ||
mock.stringResult() | ||
} | ||
|
||
@Test | ||
fun then() { | ||
/* Given */ | ||
val mock = mock<Methods>() | ||
whenever(mock.stringResult()).thenReturn("Test") | ||
|
||
/* When */ | ||
mock.stringResult() | ||
|
||
/* Then */ | ||
then(mock).should().stringResult() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.