aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test/kotlin/test/BDDMockitoTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/test/kotlin/test/BDDMockitoTest.kt')
-rw-r--r--tests/src/test/kotlin/test/BDDMockitoTest.kt131
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/src/test/kotlin/test/BDDMockitoTest.kt b/tests/src/test/kotlin/test/BDDMockitoTest.kt
new file mode 100644
index 0000000..0472163
--- /dev/null
+++ b/tests/src/test/kotlin/test/BDDMockitoTest.kt
@@ -0,0 +1,131 @@
+package test
+
+import com.nhaarman.expect.expect
+import org.junit.Test
+import org.mockito.kotlin.*
+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 */
+ 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
+ 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 */
+ 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 */
+ org.mockito.kotlin.then(mock).should().stringResult()
+ }
+}