Skip to content

Make inOrder inline#248

Merged
nhaarman merged 1 commit into
mockito:2.xfrom
matejdro:2.x
May 10, 2018
Merged

Make inOrder inline#248
nhaarman merged 1 commit into
mockito:2.xfrom
matejdro:2.x

Conversation

@matejdro

Copy link
Copy Markdown
Contributor

This code currently does not compile:

private interface SomeSuspendingClass {
    suspend fun doWork()
}

@Test
fun verifySuspendMethod() = runBlocking {
    val testSubject : SomeSuspendingClass = mock()
    val testSubject2 : SomeSuspendingClass = mock()

    //...

    inOrder(testSubject, testSubject2) {
        verify(testSubject).doWork()
        verify(testSubject2).doWork()
    }
}

Even though there is runBlocking wrapper outside, inOrder runs separately from it. Only workaround for current mockito-kotlin is ugly double runBlocking:

private interface SomeSuspendingClass {
    suspend fun doWork()
}

@Test
fun verifySuspendMethod() = runBlocking {
    val testSubject : SomeSuspendingClass = mock()
    val testSubject2 : SomeSuspendingClass = mock()

    //...

    inOrder(testSubject, testSubject2) {
        runBlocking {
            verify(testSubject).doWork()
            verify(testSubject2).doWork()
        }
    }
}

Making inOrder helper function inline fixes this issue.

@nhaarman nhaarman merged commit fb3581b into mockito:2.x May 10, 2018
@nhaarman

Copy link
Copy Markdown
Contributor

Thanks! I have included a test case for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants