diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultAddPusherTaskTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultAddPusherTaskTest.kt index c8be0f5487..31fd86fe65 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultAddPusherTaskTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultAddPusherTaskTest.kt @@ -16,7 +16,8 @@ package org.matrix.android.sdk.internal.session.pushers -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest import org.amshove.kluent.internal.assertFailsWith import org.amshove.kluent.shouldBeEqualTo import org.junit.Test @@ -39,6 +40,7 @@ private val A_JSON_PUSHER = JsonPusher( data = JsonPusherData(brand = "Element") ) +@ExperimentalCoroutinesApi class DefaultAddPusherTaskTest { private val pushersAPI = FakePushersAPI() @@ -55,7 +57,7 @@ class DefaultAddPusherTaskTest { fun `given no persisted pusher when adding Pusher then updates api and inserts result with Registered state`() { monarchy.givenWhereReturns(result = null) - runBlocking { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) } + runTest { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) } pushersAPI.verifySetPusher(A_JSON_PUSHER) monarchy.verifyInsertOrUpdate { @@ -70,7 +72,7 @@ class DefaultAddPusherTaskTest { val realmResult = PusherEntity(appDisplayName = null) monarchy.givenWhereReturns(result = realmResult) - runBlocking { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) } + runTest { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) } pushersAPI.verifySetPusher(A_JSON_PUSHER) @@ -85,7 +87,7 @@ class DefaultAddPusherTaskTest { pushersAPI.givenSetPusherErrors(SocketException()) assertFailsWith { - runBlocking { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) } + runTest { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) } } realmResult.state shouldBeEqualTo PusherState.FAILED_TO_REGISTER @@ -97,7 +99,7 @@ class DefaultAddPusherTaskTest { pushersAPI.givenSetPusherErrors(SocketException()) assertFailsWith { - runBlocking { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) } + runTest { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) } } } } diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/task/CoroutineSequencersTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/task/CoroutineSequencersTest.kt index 0abca8bee3..149b964fd2 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/task/CoroutineSequencersTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/task/CoroutineSequencersTest.kt @@ -21,7 +21,7 @@ import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.delay import kotlinx.coroutines.joinAll import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals import org.junit.Test import org.matrix.android.sdk.MatrixTest @@ -51,7 +51,7 @@ class CoroutineSequencersTest : MatrixTest { .also { results.add(it) } } ) - runBlocking { + runTest { jobs.joinAll() } assertEquals(3, results.size) @@ -81,7 +81,7 @@ class CoroutineSequencersTest : MatrixTest { .also { results.add(it) } } ) - runBlocking { + runTest { jobs.joinAll() } assertEquals(3, results.size) @@ -109,7 +109,7 @@ class CoroutineSequencersTest : MatrixTest { ) // We are canceling the second job jobs[1].cancel() - runBlocking { + runTest { jobs.joinAll() } assertEquals(2, results.size) diff --git a/vector/src/test/java/im/vector/app/features/crypto/keys/KeysExporterTest.kt b/vector/src/test/java/im/vector/app/features/crypto/keys/KeysExporterTest.kt index 57ad2a52ab..5d0317592d 100644 --- a/vector/src/test/java/im/vector/app/features/crypto/keys/KeysExporterTest.kt +++ b/vector/src/test/java/im/vector/app/features/crypto/keys/KeysExporterTest.kt @@ -26,7 +26,7 @@ import io.mockk.every import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest import org.amshove.kluent.internal.assertFailsWith import org.junit.Before import org.junit.Test @@ -55,7 +55,7 @@ class KeysExporterTest { givenFileDescriptorWithSize(size = A_ROOM_KEYS_EXPORT.size.toLong()) val outputStream = context.givenOutputStreamFor(A_URI) - runBlocking { keysExporter.export(A_PASSWORD, A_URI) } + runTest { keysExporter.export(A_PASSWORD, A_URI) } verify { outputStream.write(A_ROOM_KEYS_EXPORT) } } @@ -66,7 +66,7 @@ class KeysExporterTest { context.givenOutputStreamFor(A_URI) assertFailsWith { - runBlocking { keysExporter.export(A_PASSWORD, A_URI) } + runTest { keysExporter.export(A_PASSWORD, A_URI) } } } @@ -75,7 +75,7 @@ class KeysExporterTest { context.givenMissingOutputStreamFor(A_URI) assertFailsWith(message = "Unable to open file for writing") { - runBlocking { keysExporter.export(A_PASSWORD, A_URI) } + runTest { keysExporter.export(A_PASSWORD, A_URI) } } } @@ -85,7 +85,7 @@ class KeysExporterTest { context.givenOutputStreamFor(A_URI) assertFailsWith(message = "Exported file not found") { - runBlocking { keysExporter.export(A_PASSWORD, A_URI) } + runTest { keysExporter.export(A_PASSWORD, A_URI) } } }