Upgraded Turbine to 0.12.1.

This commit is contained in:
Neil Marietta 2023-01-13 16:23:54 +01:00
parent 5b4f9c2864
commit 1e29b3da4a
4 changed files with 14 additions and 31 deletions

View File

@ -93,29 +93,26 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.withTimeout
import kotlinx.coroutines.withTimeoutOrNull
import me.proton.core.domain.arch.DataResult
import me.proton.core.domain.arch.ResponseSource
import me.proton.core.domain.entity.UserId
import me.proton.core.test.android.ArchTest
import me.proton.core.test.kotlin.CoroutinesTest
import me.proton.core.test.kotlin.TestDispatcherProvider
import me.proton.core.test.kotlin.UnconfinedCoroutinesTest
import me.proton.core.test.kotlin.flowTest
import java.io.IOException
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlin.time.DurationUnit
import kotlin.time.seconds
import kotlin.time.toDuration
private const val STARRED_LABEL_ID = "10"
class ConversationsRepositoryImplTest : ArchTest by ArchTest(),
CoroutinesTest by CoroutinesTest({ TestDispatcherProvider(UnconfinedTestDispatcher()) }) {
class ConversationsRepositoryImplTest : ArchTest by ArchTest(), CoroutinesTest by UnconfinedCoroutinesTest() {
private val testUserId = UserId("id")
@ -1630,17 +1627,12 @@ class ConversationsRepositoryImplTest : ArchTest by ArchTest(),
@Test
fun getCountersIsCancelledWhenApiCallIsCancelled() = coroutinesTest {
// given
coEvery { api.fetchConversationsCounts(testUserId) } answers {
throw CancellationException("Cancelled")
}
coEvery { api.fetchConversationsCounts(testUserId) } throws(CancellationException("Cancelled"))
// when
val result = withTimeoutOrNull(3.toDuration(DurationUnit.SECONDS)) {
conversationsRepository.getUnreadCounters(testUserId).test {
awaitItem()
}
conversationsRepository.getUnreadCounters(testUserId).test(timeout = 1.seconds) {
expectNoEvents()
}
assertNull(result)
}
private fun setupUnreadCounterDaoToSimulateReplace() {

View File

@ -62,20 +62,17 @@ import io.mockk.runs
import io.mockk.slot
import io.mockk.spyk
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.withTimeout
import me.proton.core.domain.arch.DataResult
import me.proton.core.domain.arch.ResponseSource
import me.proton.core.domain.entity.UserId
import me.proton.core.test.kotlin.CoroutinesTest
import me.proton.core.test.kotlin.TestDispatcherProvider
import me.proton.core.test.kotlin.UnconfinedCoroutinesTest
import me.proton.core.util.kotlin.EMPTY_STRING
import org.junit.Before
import org.junit.Test
@ -83,10 +80,9 @@ import java.io.IOException
import kotlin.random.Random.Default.nextBytes
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.time.DurationUnit
import kotlin.time.toDuration
import kotlin.time.Duration.Companion.seconds
class MessageRepositoryTest: CoroutinesTest by CoroutinesTest({ TestDispatcherProvider(UnconfinedTestDispatcher()) }) {
class MessageRepositoryTest: CoroutinesTest by UnconfinedCoroutinesTest() {
private val messageDao: MessageDao = mockk(relaxUnitFun = true) {
coEvery { saveMessage(any()) } returns 123
@ -773,18 +769,14 @@ class MessageRepositoryTest: CoroutinesTest by CoroutinesTest({ TestDispatcherPr
}
}
@Test(expected = TimeoutCancellationException::class)
@Test
fun getCountersIsCancelledWhenApiCallIsCancelled() = coroutinesTest {
// given
coEvery { protonMailApiManager.fetchMessagesCounts(testUserId) } answers {
throw CancellationException("Cancelled")
}
coEvery { protonMailApiManager.fetchMessagesCounts(testUserId) } throws(CancellationException("Cancelled"))
// when
withTimeout(1.toDuration(DurationUnit.SECONDS)) {
messageRepository.getUnreadCounters(testUserId).test {
awaitItem()
}
messageRepository.getUnreadCounters(testUserId).test(timeout = 1.seconds) {
expectNoEvents()
}
}

View File

@ -75,7 +75,7 @@ const val `json-simple version` = "1.1.1" // Released: Mar
const val `browserstack-plugin version` = "3.0.1" // Released: Jun 10, 2020
const val `uiautomator version` = "2.3.0-alpha01"
const val `sun-mail-android version` = "1.5.5" // Released: Mar 06, 2020
const val `turbine version` = "0.9.0" // Released: Aug 01, 2022
const val `turbine version` = "0.12.1"
const val `junit-ktx version` = "1.1.4"
// Android

View File

@ -33,7 +33,6 @@ dependencies {
`Proton-user-domain`,
// Kotlin
`kotlin-jdk8`,
`coroutines-core`,
`serialization-json`,