Improving send locations tasks tests
This commit is contained in:
parent
8d2a914c64
commit
8860dac759
@ -16,11 +16,14 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.session.room.location
|
package org.matrix.android.sdk.internal.session.room.location
|
||||||
|
|
||||||
|
import io.mockk.mockk
|
||||||
import io.mockk.unmockkAll
|
import io.mockk.unmockkAll
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Test
|
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.FakeEventSenderProcessor
|
||||||
import org.matrix.android.sdk.test.fakes.FakeLocalEchoEventFactory
|
import org.matrix.android.sdk.test.fakes.FakeLocalEchoEventFactory
|
||||||
|
|
||||||
@ -55,13 +58,15 @@ internal class DefaultSendLiveLocationTaskTest {
|
|||||||
longitude = A_LONGITUDE,
|
longitude = A_LONGITUDE,
|
||||||
uncertainty = AN_UNCERTAINTY
|
uncertainty = AN_UNCERTAINTY
|
||||||
)
|
)
|
||||||
|
|
||||||
val event = fakeLocalEchoEventFactory.givenCreateLiveLocationEvent(
|
val event = fakeLocalEchoEventFactory.givenCreateLiveLocationEvent(
|
||||||
withLocalEcho = true
|
withLocalEcho = true
|
||||||
)
|
)
|
||||||
|
val cancelable = mockk<Cancelable>()
|
||||||
|
fakeEventSenderProcessor.givenPostEventReturns(event, cancelable)
|
||||||
|
|
||||||
defaultSendLiveLocationTask.execute(params)
|
val result = defaultSendLiveLocationTask.execute(params)
|
||||||
|
|
||||||
|
result shouldBeEqualTo cancelable
|
||||||
fakeLocalEchoEventFactory.verifyCreateLiveLocationEvent(
|
fakeLocalEchoEventFactory.verifyCreateLiveLocationEvent(
|
||||||
roomId = params.roomId,
|
roomId = params.roomId,
|
||||||
beaconInfoEventId = params.beaconInfoEventId,
|
beaconInfoEventId = params.beaconInfoEventId,
|
||||||
|
@ -16,11 +16,14 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.session.room.location
|
package org.matrix.android.sdk.internal.session.room.location
|
||||||
|
|
||||||
|
import io.mockk.mockk
|
||||||
import io.mockk.unmockkAll
|
import io.mockk.unmockkAll
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Test
|
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.FakeEventSenderProcessor
|
||||||
import org.matrix.android.sdk.test.fakes.FakeLocalEchoEventFactory
|
import org.matrix.android.sdk.test.fakes.FakeLocalEchoEventFactory
|
||||||
|
|
||||||
@ -54,13 +57,15 @@ internal class DefaultSendStaticLocationTaskTest {
|
|||||||
uncertainty = AN_UNCERTAINTY,
|
uncertainty = AN_UNCERTAINTY,
|
||||||
isUserLocation = true
|
isUserLocation = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val event = fakeLocalEchoEventFactory.givenCreateStaticLocationEvent(
|
val event = fakeLocalEchoEventFactory.givenCreateStaticLocationEvent(
|
||||||
withLocalEcho = true
|
withLocalEcho = true
|
||||||
)
|
)
|
||||||
|
val cancelable = mockk<Cancelable>()
|
||||||
|
fakeEventSenderProcessor.givenPostEventReturns(event, cancelable)
|
||||||
|
|
||||||
defaultSendStaticLocationTask.execute(params)
|
val result = defaultSendStaticLocationTask.execute(params)
|
||||||
|
|
||||||
|
result shouldBeEqualTo cancelable
|
||||||
fakeLocalEchoEventFactory.verifyCreateStaticLocationEvent(
|
fakeLocalEchoEventFactory.verifyCreateStaticLocationEvent(
|
||||||
roomId = params.roomId,
|
roomId = params.roomId,
|
||||||
latitude = params.latitude,
|
latitude = params.latitude,
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.test.fakes
|
package org.matrix.android.sdk.test.fakes
|
||||||
|
|
||||||
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
import org.matrix.android.sdk.api.util.Cancelable
|
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() {
|
internal class FakeEventSenderProcessor : EventSenderProcessor by mockk() {
|
||||||
|
|
||||||
override fun postEvent(event: Event): Cancelable = mockk()
|
fun givenPostEventReturns(event: Event, cancelable: Cancelable) {
|
||||||
|
every { postEvent(event) } returns cancelable
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user