Loading app-feature-preview/src/main/java/app/k9mail/feature/preview/FeatureModule.kt +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ val accountModule: Module = module { single { InMemoryAccountStore() } .binds( arrayOf( AccountCommonExternalContract.AccountLoader::class, AccountCommonExternalContract.AccountStateLoader::class, AccountSetupExternalContract.AccountCreator::class, AccountEditExternalContract.AccountUpdater::class, ), Loading app-feature-preview/src/main/java/app/k9mail/feature/preview/account/InMemoryAccountStore.kt +3 −3 Original line number Diff line number Diff line package app.k9mail.feature.preview.account import app.k9mail.feature.account.common.AccountCommonExternalContract.AccountLoader import app.k9mail.feature.account.common.AccountCommonExternalContract.AccountStateLoader import app.k9mail.feature.account.common.domain.entity.Account import app.k9mail.feature.account.common.domain.entity.AccountState import app.k9mail.feature.account.common.domain.entity.AuthorizationState Loading @@ -11,13 +11,13 @@ import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCrea class InMemoryAccountStore( private val accountMap: MutableMap<String, Account> = mutableMapOf(), ) : AccountCreator, AccountUpdater, AccountLoader { ) : AccountCreator, AccountUpdater, AccountStateLoader { suspend fun load(accountUuid: String): Account? { return accountMap[accountUuid] } override suspend fun loadAccount(accountUuid: String): AccountState? { override suspend fun loadAccountState(accountUuid: String): AccountState? { return accountMap[accountUuid]?.let { mapToAccountState(it) } } Loading app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt +2 −2 Original line number Diff line number Diff line Loading @@ -22,8 +22,8 @@ val newAccountModule = module { ) } factory<AccountCommonExternalContract.AccountLoader> { AccountLoader( factory<AccountCommonExternalContract.AccountStateLoader> { AccountStateLoader( accountManager = get(), ) } Loading app/k9mail/src/main/java/com/fsck/k9/account/AccountLoader.kt→app/k9mail/src/main/java/com/fsck/k9/account/AccountStateLoader.kt +5 −5 Original line number Diff line number Diff line Loading @@ -10,13 +10,13 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import com.fsck.k9.Account as K9Account class AccountLoader( class AccountStateLoader( private val accountManager: AccountManager, private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO, ) : AccountCommonExternalContract.AccountLoader { ) : AccountCommonExternalContract.AccountStateLoader { @Suppress("TooGenericExceptionCaught") override suspend fun loadAccount(accountUuid: String): AccountState? { override suspend fun loadAccountState(accountUuid: String): AccountState? { return try { withContext(coroutineDispatcher) { load(accountUuid) Loading @@ -29,10 +29,10 @@ class AccountLoader( } private fun load(accountUuid: String): AccountState? { return accountManager.getAccount(accountUuid)?.let { mapToAccount(it) } return accountManager.getAccount(accountUuid)?.let { mapToAccountState(it) } } private fun mapToAccount(account: K9Account): AccountState { private fun mapToAccountState(account: K9Account): AccountState { return AccountState( uuid = account.uuid, emailAddress = account.email, Loading app/k9mail/src/test/java/com/fsck/k9/account/AccountLoaderTest.kt→app/k9mail/src/test/java/com/fsck/k9/account/AccountStateLoaderTest.kt +14 −16 Original line number Diff line number Diff line Loading @@ -5,43 +5,41 @@ import app.k9mail.feature.account.common.domain.entity.AuthorizationState import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isNull import com.fsck.k9.Account import com.fsck.k9.Identity import com.fsck.k9.mail.AuthType import com.fsck.k9.mail.ConnectionSecurity import com.fsck.k9.mail.ServerSettings import kotlinx.coroutines.test.runTest import org.junit.Test import com.fsck.k9.Account as K9Account class AccountLoaderTest { class AccountStateLoaderTest { @Test fun `loadAccount() should return null when accountManager returns null`() = runTest { fun `loadAccountState() should return null when accountManager returns null`() = runTest { val accountManager = FakeAccountManager() val accountLoader = AccountLoader(accountManager) val accountLoader = AccountStateLoader(accountManager) val result = accountLoader.loadAccount("accountUuid") val result = accountLoader.loadAccountState("accountUuid") assertThat(result).isNull() } @Test fun `loadAccount() should return account when present in accountManager`() = runTest { fun `loadAccountState() should return account when present in accountManager`() = runTest { val accounts = mapOf( "accountUuid" to K9Account( uuid = "accountUuid", ).also { it.identities = mutableListOf(Identity()) it.email = "emailAddress" it.incomingServerSettings = INCOMING_SERVER_SETTINGS it.outgoingServerSettings = OUTGOING_SERVER_SETTINGS it.oAuthState = "oAuthState" "accountUuid" to Account(uuid = "accountUuid").apply { identities = mutableListOf(Identity()) email = "emailAddress" incomingServerSettings = INCOMING_SERVER_SETTINGS outgoingServerSettings = OUTGOING_SERVER_SETTINGS oAuthState = "oAuthState" }, ) val accountManager = FakeAccountManager(accounts = accounts) val accountLoader = AccountLoader(accountManager) val accountLoader = AccountStateLoader(accountManager) val result = accountLoader.loadAccount("accountUuid") val result = accountLoader.loadAccountState("accountUuid") assertThat(result).isEqualTo( AccountState( Loading Loading
app-feature-preview/src/main/java/app/k9mail/feature/preview/FeatureModule.kt +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ val accountModule: Module = module { single { InMemoryAccountStore() } .binds( arrayOf( AccountCommonExternalContract.AccountLoader::class, AccountCommonExternalContract.AccountStateLoader::class, AccountSetupExternalContract.AccountCreator::class, AccountEditExternalContract.AccountUpdater::class, ), Loading
app-feature-preview/src/main/java/app/k9mail/feature/preview/account/InMemoryAccountStore.kt +3 −3 Original line number Diff line number Diff line package app.k9mail.feature.preview.account import app.k9mail.feature.account.common.AccountCommonExternalContract.AccountLoader import app.k9mail.feature.account.common.AccountCommonExternalContract.AccountStateLoader import app.k9mail.feature.account.common.domain.entity.Account import app.k9mail.feature.account.common.domain.entity.AccountState import app.k9mail.feature.account.common.domain.entity.AuthorizationState Loading @@ -11,13 +11,13 @@ import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCrea class InMemoryAccountStore( private val accountMap: MutableMap<String, Account> = mutableMapOf(), ) : AccountCreator, AccountUpdater, AccountLoader { ) : AccountCreator, AccountUpdater, AccountStateLoader { suspend fun load(accountUuid: String): Account? { return accountMap[accountUuid] } override suspend fun loadAccount(accountUuid: String): AccountState? { override suspend fun loadAccountState(accountUuid: String): AccountState? { return accountMap[accountUuid]?.let { mapToAccountState(it) } } Loading
app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt +2 −2 Original line number Diff line number Diff line Loading @@ -22,8 +22,8 @@ val newAccountModule = module { ) } factory<AccountCommonExternalContract.AccountLoader> { AccountLoader( factory<AccountCommonExternalContract.AccountStateLoader> { AccountStateLoader( accountManager = get(), ) } Loading
app/k9mail/src/main/java/com/fsck/k9/account/AccountLoader.kt→app/k9mail/src/main/java/com/fsck/k9/account/AccountStateLoader.kt +5 −5 Original line number Diff line number Diff line Loading @@ -10,13 +10,13 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import com.fsck.k9.Account as K9Account class AccountLoader( class AccountStateLoader( private val accountManager: AccountManager, private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO, ) : AccountCommonExternalContract.AccountLoader { ) : AccountCommonExternalContract.AccountStateLoader { @Suppress("TooGenericExceptionCaught") override suspend fun loadAccount(accountUuid: String): AccountState? { override suspend fun loadAccountState(accountUuid: String): AccountState? { return try { withContext(coroutineDispatcher) { load(accountUuid) Loading @@ -29,10 +29,10 @@ class AccountLoader( } private fun load(accountUuid: String): AccountState? { return accountManager.getAccount(accountUuid)?.let { mapToAccount(it) } return accountManager.getAccount(accountUuid)?.let { mapToAccountState(it) } } private fun mapToAccount(account: K9Account): AccountState { private fun mapToAccountState(account: K9Account): AccountState { return AccountState( uuid = account.uuid, emailAddress = account.email, Loading
app/k9mail/src/test/java/com/fsck/k9/account/AccountLoaderTest.kt→app/k9mail/src/test/java/com/fsck/k9/account/AccountStateLoaderTest.kt +14 −16 Original line number Diff line number Diff line Loading @@ -5,43 +5,41 @@ import app.k9mail.feature.account.common.domain.entity.AuthorizationState import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isNull import com.fsck.k9.Account import com.fsck.k9.Identity import com.fsck.k9.mail.AuthType import com.fsck.k9.mail.ConnectionSecurity import com.fsck.k9.mail.ServerSettings import kotlinx.coroutines.test.runTest import org.junit.Test import com.fsck.k9.Account as K9Account class AccountLoaderTest { class AccountStateLoaderTest { @Test fun `loadAccount() should return null when accountManager returns null`() = runTest { fun `loadAccountState() should return null when accountManager returns null`() = runTest { val accountManager = FakeAccountManager() val accountLoader = AccountLoader(accountManager) val accountLoader = AccountStateLoader(accountManager) val result = accountLoader.loadAccount("accountUuid") val result = accountLoader.loadAccountState("accountUuid") assertThat(result).isNull() } @Test fun `loadAccount() should return account when present in accountManager`() = runTest { fun `loadAccountState() should return account when present in accountManager`() = runTest { val accounts = mapOf( "accountUuid" to K9Account( uuid = "accountUuid", ).also { it.identities = mutableListOf(Identity()) it.email = "emailAddress" it.incomingServerSettings = INCOMING_SERVER_SETTINGS it.outgoingServerSettings = OUTGOING_SERVER_SETTINGS it.oAuthState = "oAuthState" "accountUuid" to Account(uuid = "accountUuid").apply { identities = mutableListOf(Identity()) email = "emailAddress" incomingServerSettings = INCOMING_SERVER_SETTINGS outgoingServerSettings = OUTGOING_SERVER_SETTINGS oAuthState = "oAuthState" }, ) val accountManager = FakeAccountManager(accounts = accounts) val accountLoader = AccountLoader(accountManager) val accountLoader = AccountStateLoader(accountManager) val result = accountLoader.loadAccount("accountUuid") val result = accountLoader.loadAccountState("accountUuid") assertThat(result).isEqualTo( AccountState( Loading