Improving send locations tasks tests

This commit is contained in:
Maxime NATUREL 2022-06-14 14:30:24 +02:00
parent 8d2a914c64
commit 8860dac759
3 changed files with 18 additions and 5 deletions

View File

@ -16,11 +16,14 @@
package org.matrix.android.sdk.internal.session.room.location
import io.mockk.mockk
import io.mockk.unmockkAll
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.junit.After
import org.junit.Test
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.test.fakes.FakeEventSenderProcessor
import org.matrix.android.sdk.test.fakes.FakeLocalEchoEventFactory
@ -55,13 +58,15 @@ internal class DefaultSendLiveLocationTaskTest {
longitude = A_LONGITUDE,
uncertainty = AN_UNCERTAINTY
)
val event = fakeLocalEchoEventFactory.givenCreateLiveLocationEvent(
withLocalEcho = true
)
val cancelable = mockk<Cancelable>()
fakeEventSenderProcessor.givenPostEventReturns(event, cancelable)
defaultSendLiveLocationTask.execute(params)
val result = defaultSendLiveLocationTask.execute(params)
result shouldBeEqualTo cancelable
fakeLocalEchoEventFactory.verifyCreateLiveLocationEvent(
roomId = params.roomId,
beaconInfoEventId = params.beaconInfoEventId,

View File

@ -16,11 +16,14 @@
package org.matrix.android.sdk.internal.session.room.location
import io.mockk.mockk
import io.mockk.unmockkAll
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.junit.After
import org.junit.Test
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.test.fakes.FakeEventSenderProcessor
import org.matrix.android.sdk.test.fakes.FakeLocalEchoEventFactory
@ -54,13 +57,15 @@ internal class DefaultSendStaticLocationTaskTest {
uncertainty = AN_UNCERTAINTY,
isUserLocation = true
)
val event = fakeLocalEchoEventFactory.givenCreateStaticLocationEvent(
withLocalEcho = true
)
val cancelable = mockk<Cancelable>()
fakeEventSenderProcessor.givenPostEventReturns(event, cancelable)
defaultSendStaticLocationTask.execute(params)
val result = defaultSendStaticLocationTask.execute(params)
result shouldBeEqualTo cancelable
fakeLocalEchoEventFactory.verifyCreateStaticLocationEvent(
roomId = params.roomId,
latitude = params.latitude,

View File

@ -16,6 +16,7 @@
package org.matrix.android.sdk.test.fakes
import io.mockk.every
import io.mockk.mockk
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.util.Cancelable
@ -23,5 +24,7 @@ import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProces
internal class FakeEventSenderProcessor : EventSenderProcessor by mockk() {
override fun postEvent(event: Event): Cancelable = mockk()
fun givenPostEventReturns(event: Event, cancelable: Cancelable) {
every { postEvent(event) } returns cancelable
}
}