Benoit Marty 2022-03-22 16:52:18 +01:00
parent 86829008c3
commit 012cdf4b4d
3 changed files with 16 additions and 14 deletions

View File

@ -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<PusherEntity>(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<PusherEntity> {
@ -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<SocketException> {
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<SocketException> {
runBlocking { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) }
runTest { addPusherTask.execute(AddPusherTask.Params(A_JSON_PUSHER)) }
}
}
}

View File

@ -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)

View File

@ -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<UnexpectedExportKeysFileSizeException> {
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<IllegalStateException>(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<IllegalStateException>(message = "Exported file not found") {
runBlocking { keysExporter.export(A_PASSWORD, A_URI) }
runTest { keysExporter.export(A_PASSWORD, A_URI) }
}
}