Use bufferedMutableSharedFlow where appropriate (#476)

This commit is contained in:
Brian Yencho 2024-01-02 22:08:06 -06:00 committed by Álison Fernandes
parent b3bee9ae20
commit 0d3038a717
34 changed files with 92 additions and 170 deletions

View file

@ -4,6 +4,7 @@ import android.content.SharedPreferences
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
import com.x8bit.bitwarden.data.platform.datasource.disk.BaseDiskSource
import com.x8bit.bitwarden.data.platform.datasource.disk.BaseDiskSource.Companion.BASE_KEY
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.vault.datasource.network.model.SyncResponseJson
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
@ -58,10 +59,7 @@ class AuthDiskSourceImpl(
get() = mutableUserStateFlow
.onSubscription { emit(userState) }
private val mutableUserStateFlow = MutableSharedFlow<UserStateJson?>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableUserStateFlow = bufferedMutableSharedFlow<UserStateJson?>(replay = 1)
override fun getUserKey(userId: String): String? =
getString(key = "${MASTER_KEY_ENCRYPTION_USER_KEY}_$userId")
@ -132,9 +130,6 @@ class AuthDiskSourceImpl(
userId: String,
): MutableSharedFlow<List<SyncResponseJson.Profile.Organization>?> =
mutableOrganizationsFlowMap.getOrPut(userId) {
MutableSharedFlow(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
bufferedMutableSharedFlow(replay = 1)
}
}

View file

@ -33,6 +33,7 @@ import com.x8bit.bitwarden.data.auth.util.KdfParamsConstants.DEFAULT_PBKDF2_ITER
import com.x8bit.bitwarden.data.auth.util.toSdkParams
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.platform.util.asFailure
import com.x8bit.bitwarden.data.platform.util.flatMap
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
@ -40,7 +41,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
@ -124,7 +124,7 @@ class AuthRepositoryImpl constructor(
)
private val mutableCaptchaTokenFlow =
MutableSharedFlow<CaptchaCallbackTokenResult>(extraBufferCapacity = Int.MAX_VALUE)
bufferedMutableSharedFlow<CaptchaCallbackTokenResult>()
override val captchaTokenResultFlow: Flow<CaptchaCallbackTokenResult> =
mutableCaptchaTokenFlow.asSharedFlow()

View file

@ -3,8 +3,8 @@ package com.x8bit.bitwarden.data.platform.datasource.disk
import android.content.SharedPreferences
import com.x8bit.bitwarden.data.auth.datasource.disk.model.EnvironmentUrlDataJson
import com.x8bit.bitwarden.data.platform.datasource.disk.BaseDiskSource.Companion.BASE_KEY
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.onSubscription
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
@ -33,8 +33,6 @@ class EnvironmentDiskSourceImpl(
get() = mutableEnvironmentUrlDataFlow
.onSubscription { emit(preAuthEnvironmentUrlData) }
private val mutableEnvironmentUrlDataFlow = MutableSharedFlow<EnvironmentUrlDataJson?>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEnvironmentUrlDataFlow =
bufferedMutableSharedFlow<EnvironmentUrlDataJson?>(replay = 1)
}

View file

@ -3,7 +3,12 @@ package com.x8bit.bitwarden.data.platform.repository.util
import kotlinx.coroutines.flow.MutableSharedFlow
/**
* Creates a [MutableSharedFlow] with a buffer of [Int.MAX_VALUE].
* Creates a [MutableSharedFlow] with a buffer of [Int.MAX_VALUE] and the given [replay] count.
*/
fun <T> bufferedMutableSharedFlow(): MutableSharedFlow<T> =
MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE)
fun <T> bufferedMutableSharedFlow(
replay: Int = 0,
): MutableSharedFlow<T> =
MutableSharedFlow(
replay = replay,
extraBufferCapacity = Int.MAX_VALUE,
)

View file

@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.auth.datasource.disk.util
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.vault.datasource.network.model.SyncResponseJson
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
@ -16,11 +17,7 @@ class FakeAuthDiskSource : AuthDiskSource {
private val mutableOrganizationsFlowMap =
mutableMapOf<String, MutableSharedFlow<List<SyncResponseJson.Profile.Organization>?>>()
private val mutableUserStateFlow =
MutableSharedFlow<UserStateJson?>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableUserStateFlow = bufferedMutableSharedFlow<UserStateJson?>(replay = 1)
private val storedUserKeys = mutableMapOf<String, String?>()
private val storedPrivateKeys = mutableMapOf<String, String?>()
@ -121,10 +118,7 @@ class FakeAuthDiskSource : AuthDiskSource {
userId: String,
): MutableSharedFlow<List<SyncResponseJson.Profile.Organization>?> =
mutableOrganizationsFlowMap.getOrPut(userId) {
MutableSharedFlow(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
bufferedMutableSharedFlow(replay = 1)
}
//endregion Private helper functions

View file

@ -9,13 +9,13 @@ import com.x8bit.bitwarden.data.platform.base.FakeDispatcherManager
import com.x8bit.bitwarden.data.platform.datasource.disk.EnvironmentDiskSource
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
import com.x8bit.bitwarden.data.platform.repository.model.Environment
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.platform.repository.util.toEnvironmentUrls
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.unmockkStatic
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.onSubscription
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.AfterEach
@ -179,8 +179,5 @@ private class FakeEnvironmentDiskSource : EnvironmentDiskSource {
.onSubscription { emit(preAuthEnvironmentUrlData) }
private val mutablePreAuthEnvironmentUrlDataFlow =
MutableSharedFlow<EnvironmentUrlDataJson?>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
bufferedMutableSharedFlow<EnvironmentUrlDataJson?>(replay = 1)
}

View file

@ -1,17 +1,15 @@
package com.x8bit.bitwarden.data.tools.generator.datasource.disk.dao
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.tools.generator.datasource.disk.entity.PasswordHistoryEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.map
class FakePasswordHistoryDao : PasswordHistoryDao {
val storedPasswordHistories = mutableListOf<PasswordHistoryEntity>()
private val passwordHistoriesFlow = MutableSharedFlow<List<PasswordHistoryEntity>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
private val passwordHistoriesFlow =
bufferedMutableSharedFlow<List<PasswordHistoryEntity>>(replay = 1)
init {
passwordHistoriesFlow.tryEmit(emptyList())

View file

@ -1,8 +1,8 @@
package com.x8bit.bitwarden.data.vault.datasource.disk.dao
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.vault.datasource.disk.entity.CipherEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.map
class FakeCiphersDao : CiphersDao {
@ -11,10 +11,7 @@ class FakeCiphersDao : CiphersDao {
var deleteCiphersCalled: Boolean = false
private val ciphersFlow = MutableSharedFlow<List<CipherEntity>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
private val ciphersFlow = bufferedMutableSharedFlow<List<CipherEntity>>(replay = 1)
init {
ciphersFlow.tryEmit(emptyList())

View file

@ -1,8 +1,8 @@
package com.x8bit.bitwarden.data.vault.datasource.disk.dao
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.vault.datasource.disk.entity.CollectionEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.map
class FakeCollectionsDao : CollectionsDao {
@ -12,10 +12,7 @@ class FakeCollectionsDao : CollectionsDao {
var deleteCollectionCalled: Boolean = false
var deleteCollectionsCalled: Boolean = false
private val collectionsFlow = MutableSharedFlow<List<CollectionEntity>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
private val collectionsFlow = bufferedMutableSharedFlow<List<CollectionEntity>>(replay = 1)
init {
collectionsFlow.tryEmit(emptyList())

View file

@ -1,8 +1,8 @@
package com.x8bit.bitwarden.data.vault.datasource.disk.dao
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.vault.datasource.disk.entity.FolderEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.map
class FakeFoldersDao : FoldersDao {
@ -12,10 +12,7 @@ class FakeFoldersDao : FoldersDao {
var deleteFolderCalled: Boolean = false
var deleteFoldersCalled: Boolean = false
private val foldersFlow = MutableSharedFlow<List<FolderEntity>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
private val foldersFlow = bufferedMutableSharedFlow<List<FolderEntity>>(replay = 1)
init {
foldersFlow.tryEmit(emptyList())

View file

@ -60,7 +60,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
@ -92,10 +91,8 @@ class VaultRepositoryTest {
val mockCipherList = listOf(createMockCipher(number = 1))
val mockEncryptedCipherList = mockCipherList.toEncryptedSdkCipherList()
val mockCipherViewList = listOf(createMockCipherView(number = 1))
val mutableCiphersStateFlow = MutableSharedFlow<List<SyncResponseJson.Cipher>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
val mutableCiphersStateFlow =
bufferedMutableSharedFlow<List<SyncResponseJson.Cipher>>(replay = 1)
every {
vaultDiskSource.getCiphers(userId = MOCK_USER_STATE.activeUserId)
} returns mutableCiphersStateFlow
@ -118,10 +115,8 @@ class VaultRepositoryTest {
val throwable = Throwable("Fail")
val mockCipherList = listOf(createMockCipher(number = 1))
val mockEncryptedCipherList = mockCipherList.toEncryptedSdkCipherList()
val mutableCiphersStateFlow = MutableSharedFlow<List<SyncResponseJson.Cipher>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
val mutableCiphersStateFlow =
bufferedMutableSharedFlow<List<SyncResponseJson.Cipher>>(replay = 1)
every {
vaultDiskSource.getCiphers(userId = MOCK_USER_STATE.activeUserId)
} returns mutableCiphersStateFlow
@ -146,10 +141,8 @@ class VaultRepositoryTest {
val mockCollectionList = listOf(createMockCollection(number = 1))
val mockEncryptedCollectionList = mockCollectionList.toEncryptedSdkCollectionList()
val mockCollectionViewList = listOf(createMockCollectionView(number = 1))
val mutableCollectionsStateFlow = MutableSharedFlow<List<SyncResponseJson.Collection>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
val mutableCollectionsStateFlow =
bufferedMutableSharedFlow<List<SyncResponseJson.Collection>>(replay = 1)
every {
vaultDiskSource.getCollections(userId = MOCK_USER_STATE.activeUserId)
} returns mutableCollectionsStateFlow
@ -172,10 +165,8 @@ class VaultRepositoryTest {
val throwable = Throwable("Fail")
val mockCollectionList = listOf(createMockCollection(number = 1))
val mockEncryptedCollectionList = mockCollectionList.toEncryptedSdkCollectionList()
val mutableCollectionStateFlow = MutableSharedFlow<List<SyncResponseJson.Collection>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
val mutableCollectionStateFlow =
bufferedMutableSharedFlow<List<SyncResponseJson.Collection>>(replay = 1)
every {
vaultDiskSource.getCollections(userId = MOCK_USER_STATE.activeUserId)
} returns mutableCollectionStateFlow
@ -200,10 +191,8 @@ class VaultRepositoryTest {
val mockFolderList = listOf(createMockFolder(number = 1))
val mockEncryptedFolderList = mockFolderList.toEncryptedSdkFolderList()
val mockFolderViewList = listOf(createMockFolderView(number = 1))
val mutableFoldersStateFlow = MutableSharedFlow<List<SyncResponseJson.Folder>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
val mutableFoldersStateFlow =
bufferedMutableSharedFlow<List<SyncResponseJson.Folder>>(replay = 1)
every {
vaultDiskSource.getFolders(userId = MOCK_USER_STATE.activeUserId)
} returns mutableFoldersStateFlow
@ -226,10 +215,8 @@ class VaultRepositoryTest {
val throwable = Throwable("Fail")
val mockFolderList = listOf(createMockFolder(number = 1))
val mockEncryptedFolderList = mockFolderList.toEncryptedSdkFolderList()
val mutableFoldersStateFlow = MutableSharedFlow<List<SyncResponseJson.Folder>>(
replay = 1,
extraBufferCapacity = Int.MAX_VALUE,
)
val mutableFoldersStateFlow =
bufferedMutableSharedFlow<List<SyncResponseJson.Folder>>(replay = 1)
every {
vaultDiskSource.getFolders(userId = MOCK_USER_STATE.activeUserId)
} returns mutableFoldersStateFlow

View file

@ -11,13 +11,13 @@ import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Before
@ -25,9 +25,7 @@ import org.junit.Test
class EnterpriseSignOnScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private val mutableEventFlow = MutableSharedFlow<EnterpriseSignOnEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<EnterpriseSignOnEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<EnterpriseSignOnViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -11,11 +11,11 @@ import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertTrue
@ -24,9 +24,7 @@ import org.junit.Test
class EnvironmentScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private val mutableEventFlow = MutableSharedFlow<EnvironmentEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<EnvironmentEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<EnvironmentViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -19,6 +19,7 @@ import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextInput
import androidx.test.core.app.ApplicationProvider
import com.x8bit.bitwarden.data.platform.repository.model.Environment
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
@ -36,7 +37,6 @@ import com.x8bit.bitwarden.ui.util.performLogoutAccountConfirmationClick
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Before
@ -49,9 +49,7 @@ class LandingScreenTest : BaseComposeTest() {
private var onNavigateToCreateAccountCalled = false
private var onNavigateToLoginCalled = false
private var onNavigateToEnvironmentCalled = false
private val mutableEventFlow = MutableSharedFlow<LandingEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<LandingEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<LandingViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -13,6 +13,7 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextInput
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler
import com.x8bit.bitwarden.ui.platform.components.BasicDialogState
@ -34,7 +35,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Before
@ -47,9 +47,7 @@ class LoginScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private var onNavigateToEnterpriseSignOnCalled = false
private var onNavigateToLoginWithDeviceCalled = false
private val mutableEventFlow = MutableSharedFlow<LoginEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<LoginEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<LoginViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -12,6 +12,7 @@ import com.x8bit.bitwarden.data.auth.repository.util.CaptchaCallbackTokenResult
import com.x8bit.bitwarden.data.auth.repository.util.generateUriForCaptcha
import com.x8bit.bitwarden.data.platform.repository.model.Environment
import com.x8bit.bitwarden.data.platform.repository.util.FakeEnvironmentRepository
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
@ -28,7 +29,6 @@ import io.mockk.mockkStatic
import io.mockk.runs
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.AfterEach
@ -41,9 +41,8 @@ class LoginViewModelTest : BaseViewModelTest() {
private val savedStateHandle = SavedStateHandle().also {
it["email_address"] = "test@gmail.com"
}
private val mutableCaptchaTokenResultFlow = MutableSharedFlow<CaptchaCallbackTokenResult>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableCaptchaTokenResultFlow =
bufferedMutableSharedFlow<CaptchaCallbackTokenResult>()
private val mutableUserStateFlow = MutableStateFlow<UserState?>(null)
private val authRepository: AuthRepository = mockk(relaxed = true) {
every { captchaTokenResultFlow } returns mutableCaptchaTokenResultFlow

View file

@ -5,6 +5,7 @@ import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.util.isProgressBar
@ -12,7 +13,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import junit.framework.TestCase
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Before
@ -20,9 +20,7 @@ import org.junit.Test
class LoginWithDeviceScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private val mutableEventFlow = MutableSharedFlow<LoginWithDeviceEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<LoginWithDeviceEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<LoginWithDeviceViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -13,6 +13,7 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextInput
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
import com.x8bit.bitwarden.ui.util.assertLockOrLogoutDialogIsDisplayed
@ -30,7 +31,6 @@ import com.x8bit.bitwarden.ui.util.performLogoutAccountConfirmationClick
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Before
@ -38,9 +38,7 @@ import org.junit.Test
class VaultUnlockScreenTest : BaseComposeTest() {
private val mutableEventFlow = MutableSharedFlow<VaultUnlockEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<VaultUnlockEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<VaultUnlockViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -15,6 +15,7 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.core.net.toUri
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler
import com.x8bit.bitwarden.ui.platform.base.util.asText
@ -23,7 +24,6 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertTrue
@ -38,9 +38,7 @@ class AccountSecurityScreenTest : BaseComposeTest() {
private val intentHandler = mockk<IntentHandler> {
every { launchUri(any()) } just runs
}
private val mutableEventFlow = MutableSharedFlow<AccountSecurityEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<AccountSecurityEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<AccountSecurityViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -11,12 +11,12 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextInput
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertTrue
@ -27,9 +27,7 @@ class DeleteAccountScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private val mutableEventFlow = MutableSharedFlow<DeleteAccountEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<DeleteAccountEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<DeleteAccountViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -11,11 +11,11 @@ import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertTrue
@ -26,9 +26,7 @@ class AutoFillScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private val mutableEventFlow = MutableSharedFlow<AutoFillEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<AutoFillEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<AutoFillViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -2,11 +2,11 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.folders
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Assert.assertTrue
import org.junit.Before
@ -15,9 +15,7 @@ import org.junit.Test
class FoldersScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private val mutableEventFlow = MutableSharedFlow<FoldersEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<FoldersEvent>()
private val mutableStateFlow = MutableStateFlow(Unit)
val viewModel = mockk<FoldersViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -7,11 +7,11 @@ import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Assert.assertTrue
import org.junit.Before
@ -21,9 +21,7 @@ class VaultSettingsScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private var onNavigateToFoldersCalled = false
private val mutableEventFlow = MutableSharedFlow<VaultSettingsEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<VaultSettingsEvent>()
private val mutableStateFlow = MutableStateFlow(Unit)
val viewModel = mockk<VaultSettingsViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -3,21 +3,19 @@ package com.x8bit.bitwarden.ui.platform.feature.vaultunlockednavbar
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.navigation.navOptions
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.FakeNavHostController
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Before
import org.junit.Test
class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
private val fakeNavHostController = FakeNavHostController()
private val mutableEventFlow = MutableSharedFlow<VaultUnlockedNavBarEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<VaultUnlockedNavBarEvent>()
private val mutableStateFlow = MutableStateFlow(Unit)
val viewModel = mockk<VaultUnlockedNavBarViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -24,12 +24,12 @@ import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.swipeRight
import androidx.compose.ui.text.AnnotatedString
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Before
import org.junit.Test
@ -54,10 +54,7 @@ class GeneratorScreenTest : BaseComposeTest() {
),
)
private val mutableEventFlow = MutableSharedFlow<GeneratorEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<GeneratorEvent>()
private val viewModel = mockk<GeneratorViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow
every { stateFlow } returns mutableStateFlow

View file

@ -4,12 +4,12 @@ import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Before
import org.junit.Test
@ -18,9 +18,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
class PasswordHistoryScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private val mutableEventFlow = MutableSharedFlow<PasswordHistoryEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<PasswordHistoryEvent>()
private val mutableStateFlow = MutableStateFlow(
PasswordHistoryState(PasswordHistoryState.ViewState.Loading),

View file

@ -11,11 +11,11 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextInput
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.test.runTest
@ -25,9 +25,7 @@ import org.junit.Test
class AddSendScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private val mutableEventFlow = MutableSharedFlow<AddSendEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<AddSendEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<NewSendViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -25,6 +25,7 @@ import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.performTouchInput
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.FakePermissionManager
import com.x8bit.bitwarden.ui.platform.base.util.asText
@ -40,7 +41,6 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertTrue
@ -55,7 +55,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
private val clipboardManager = mockk<ClipboardManager>()
private val mutableEventFlow = MutableSharedFlow<VaultAddItemEvent>(Int.MAX_VALUE)
private val mutableEventFlow = bufferedMutableSharedFlow<VaultAddItemEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE_LOGIN)
private val fakePermissionManager: FakePermissionManager = FakePermissionManager()

View file

@ -5,6 +5,7 @@ import app.cash.turbine.test
import com.bitwarden.core.CipherView
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.platform.repository.model.DataState
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
import com.x8bit.bitwarden.data.vault.repository.model.CreateCipherResult
import com.x8bit.bitwarden.data.vault.repository.model.UpdateCipherResult
@ -43,9 +44,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
vaultAddEditType = VaultAddEditType.AddItem,
)
private val totpTestCodeFlow: MutableSharedFlow<String> = MutableSharedFlow(
extraBufferCapacity = Int.MAX_VALUE,
)
private val totpTestCodeFlow: MutableSharedFlow<String> = bufferedMutableSharedFlow()
private val mutableVaultItemFlow = MutableStateFlow<DataState<CipherView?>>(DataState.Loading)
private val vaultRepository: VaultRepository = mockk {

View file

@ -16,6 +16,7 @@ import androidx.compose.ui.test.onSiblings
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.core.net.toUri
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler
import com.x8bit.bitwarden.ui.platform.base.util.asText
@ -30,7 +31,6 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertEquals
@ -47,9 +47,7 @@ class VaultItemScreenTest : BaseComposeTest() {
private val clipboardManager = mockk<ClipboardManager>()
private val intentHandler = mockk<IntentHandler>()
private val mutableEventFlow = MutableSharedFlow<VaultItemEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<VaultItemEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<VaultItemViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -9,20 +9,20 @@ import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollToNode
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.util.isProgressBar
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import com.x8bit.bitwarden.R
class VaultItemListingScreenTest : BaseComposeTest() {
@ -30,9 +30,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
private var onNavigateToVaultAddItemScreenCalled = false
private var onNavigateToVaultItemId: String? = null
private val mutableEventFlow = MutableSharedFlow<VaultItemListingEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<VaultItemListingEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<VaultItemListingViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -3,13 +3,13 @@ package com.x8bit.bitwarden.ui.vault.feature.qrcodescan
import androidx.camera.core.ImageProxy
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.vault.feature.qrcodescan.util.FakeQrCodeAnalyzer
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
@ -21,9 +21,7 @@ class QrCodeScanScreenTest : BaseComposeTest() {
private val imageProxy: ImageProxy = mockk()
private val qrCodeAnalyzer = FakeQrCodeAnalyzer()
private val mutableEventFlow = MutableSharedFlow<QrCodeScanEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<QrCodeScanEvent>()
private val viewModel = mockk<QrCodeScanViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow

View file

@ -1,6 +1,7 @@
package com.x8bit.bitwarden.ui.vault.feature.qrcodescan
import app.cash.turbine.test
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
@ -10,16 +11,13 @@ import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class QrCodeScanViewModelTest : BaseViewModelTest() {
private val totpTestCodeFlow: Flow<String> = MutableSharedFlow(
extraBufferCapacity = Int.MAX_VALUE,
)
private val totpTestCodeFlow: Flow<String> = bufferedMutableSharedFlow()
private val vaultRepository: VaultRepository = mockk {
every { totpCodeFlow } returns totpTestCodeFlow
every { emitTotpCode(any()) } just runs

View file

@ -15,6 +15,7 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollToNode
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler
import com.x8bit.bitwarden.ui.platform.base.util.asText
@ -40,7 +41,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertEquals
@ -59,9 +59,7 @@ class VaultScreenTest : BaseComposeTest() {
private var onDimBottomNavBarRequestCalled = false
private val intentHandler = mockk<IntentHandler>(relaxed = true)
private val mutableEventFlow = MutableSharedFlow<VaultEvent>(
extraBufferCapacity = Int.MAX_VALUE,
)
private val mutableEventFlow = bufferedMutableSharedFlow<VaultEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
private val viewModel = mockk<VaultViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow