From fb3581b67f9bf5a18dbc1e5a6ebb995d4ccb3387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Drobni=C4=8D?= Date: Sat, 14 Apr 2018 07:37:47 +0200 Subject: [PATCH 1/3] Make inOrder inline --- .../src/main/kotlin/com/nhaarman/mockitokotlin2/Verification.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Verification.kt b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Verification.kt index 19191654..66d21acf 100644 --- a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Verification.kt +++ b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/Verification.kt @@ -192,7 +192,7 @@ fun inOrder(vararg mocks: Any): InOrder { * * Alias for [Mockito.inOrder]. */ -fun inOrder( +inline fun inOrder( vararg mocks: Any, evaluation: InOrder.() -> Unit ) { From 76cb7cba2b125265f8b463bb5d63f53cb758c3e9 Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Thu, 10 May 2018 11:32:40 +0200 Subject: [PATCH 2/3] Include tests for default arguments --- tests/src/test/kotlin/test/VerifyTest.kt | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/src/test/kotlin/test/VerifyTest.kt b/tests/src/test/kotlin/test/VerifyTest.kt index 5807c8f3..85915f3a 100644 --- a/tests/src/test/kotlin/test/VerifyTest.kt +++ b/tests/src/test/kotlin/test/VerifyTest.kt @@ -52,7 +52,45 @@ class VerifyTest : TestBase() { } } + @Test + fun verifyDefaultArgs_firstParameter() { + /* Given */ + val m = mock() + + /* When */ + m.defaultArgs(a = 2) + + /* Then */ + verify(m).defaultArgs(2) + } + + @Test + fun verifyDefaultArgs_secondParameter() { + /* Given */ + val m = mock() + + /* When */ + m.defaultArgs(b = 2) + + /* Then */ + verify(m).defaultArgs(b = 2) + } + + @Test + fun verifyDefaultArgs_verifyDefaultValue() { + /* Given */ + val m = mock() + + /* When */ + m.defaultArgs(b = 2) + + /* Then */ + verify(m).defaultArgs(a = 3, b = 2) + } + interface TestInterface { fun call(arg: Int) + + fun defaultArgs(a: Int = 3, b: Int = 42) } } \ No newline at end of file From d247f0788187d98910f56f728cb4196c615b0119 Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Thu, 10 May 2018 12:09:43 +0200 Subject: [PATCH 3/3] Include test case for calling suspend functions in inOrder --- .../src/test/kotlin/test/CoroutinesTest.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mockito-kotlin/src/test/kotlin/test/CoroutinesTest.kt b/mockito-kotlin/src/test/kotlin/test/CoroutinesTest.kt index 16118ee2..8f593035 100644 --- a/mockito-kotlin/src/test/kotlin/test/CoroutinesTest.kt +++ b/mockito-kotlin/src/test/kotlin/test/CoroutinesTest.kt @@ -3,10 +3,7 @@ package test import com.nhaarman.expect.expect -import com.nhaarman.mockitokotlin2.doReturn -import com.nhaarman.mockitokotlin2.mock -import com.nhaarman.mockitokotlin2.verify -import com.nhaarman.mockitokotlin2.verifyBlocking +import com.nhaarman.mockitokotlin2.* import kotlinx.coroutines.experimental.CommonPool import kotlinx.coroutines.experimental.delay import kotlinx.coroutines.experimental.runBlocking @@ -139,6 +136,17 @@ class CoroutinesTest { verifyBlocking(m) { suspending() } } + + @Test + fun verifySuspendMethod() = runBlocking { + val testSubject : SomeInterface = mock() + + testSubject.suspending() + + inOrder(testSubject) { + verify(testSubject).suspending() + } + } } interface SomeInterface {