Skip to content

Commit

Permalink
Merge pull request #318 from dpreussler/2.x
Browse files Browse the repository at this point in the history
#317 coroutines verify with verification mode
  • Loading branch information
nhaarman authored Dec 31, 2018
2 parents ec75b8a + a8072cb commit a8c0688
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ fun <T> verifyBlocking(mock: T, f: suspend T.() -> Unit) {
runBlocking { m.f() }
}

/**
* Verifies certain behavior happened at least once / exact number of times / never.
*
* Warning: Only one method call can be verified in the function.
* Subsequent method calls are ignored!
*/
fun <T> verifyBlocking(mock: T, mode: VerificationMode, f: suspend T.() -> Unit) {
val m = Mockito.verify(mock, mode)
runBlocking { m.f() }
}
/**
* Verifies certain behavior happened at least once / exact number of times / never.
*
Expand Down
10 changes: 10 additions & 0 deletions mockito-kotlin/src/test/kotlin/test/CoroutinesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ class CoroutinesTest {
verifyBlocking(m) { suspending() }
}

@Test
fun verifyAtLeastOnceSuspendFunctionCalled_verifyBlocking() {
val m = mock<SomeInterface>()

runBlocking { m.suspending() }
runBlocking { m.suspending() }

verifyBlocking(m, atLeastOnce()) { suspending() }
}

@Test
fun verifySuspendMethod() = runBlocking {
val testSubject: SomeInterface = mock()
Expand Down

0 comments on commit a8c0688

Please sign in to comment.