https://kotlinlang.org logo
#coroutines
Title
# coroutines
r

rafal

07/26/2017, 4:04 PM
Copy code
class SuspendableClass {
    suspend fun fetch(updateOnly: Boolean = true): Int {
//uncomment to fix mocking
//        runBlocking {
        fetchConcrete()
//        }
        return 2
    }

    suspend fun fetchConcrete() = 1
}

fun main(args: Array<String>) = runBlocking<Unit> {
    val mockClass = Mockito.mock(SuspendableClass::class.java)

    Mockito.`when`(mockClass.fetch()).thenReturn(10)

    MatcherAssert.assertThat(mockClass.fetch(), IsEqual(10))
    Mockito.verify(mockClass).fetch()
}