Loading feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/AccountEditModule.kt +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ val featureAccountEditModule = module { factory<AccountEditDomainContract.UseCase.LoadAccountState> { LoadAccountState( accountLoader = get(), accountStateLoader = get(), accountStateRepository = get(), ) } Loading feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountState.kt +3 −15 Original line number Diff line number Diff line Loading @@ -2,13 +2,11 @@ package app.k9mail.feature.account.edit.domain.usecase import app.k9mail.feature.account.common.AccountCommonExternalContract import app.k9mail.feature.account.common.domain.AccountDomainContract 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 import app.k9mail.feature.account.edit.domain.AccountEditDomainContract class LoadAccountState( private val accountLoader: AccountCommonExternalContract.AccountLoader, private val accountStateLoader: AccountCommonExternalContract.AccountStateLoader, private val accountStateRepository: AccountDomainContract.AccountStateRepository, ) : AccountEditDomainContract.UseCase.LoadAccountState { override suspend fun execute(accountUuid: String): AccountState { Loading @@ -21,21 +19,11 @@ class LoadAccountState( } private suspend fun loadState(accountUuid: String): AccountState { val account = accountLoader.loadAccount(accountUuid) return if (account != null) { val accountState = account.mapToAccountState() val accountState = accountStateLoader.loadAccountState(accountUuid) return if (accountState != null) { accountState } else { AccountState(uuid = accountUuid) }.also { accountStateRepository.setState(it) } } private fun Account.mapToAccountState() = AccountState( uuid = uuid, emailAddress = emailAddress, incomingServerSettings = incomingServerSettings, outgoingServerSettings = outgoingServerSettings, authorizationState = AuthorizationState(authorizationState), options = options, ) } feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/AccountEditModuleKtTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ import org.robolectric.RuntimeEnvironment class AccountEditModuleKtTest : KoinTest { private val externalModule: Module = module { single<AccountCommonExternalContract.AccountLoader> { Mockito.mock() } single<AccountCommonExternalContract.AccountStateLoader> { Mockito.mock() } single<LocalKeyStore> { Mockito.mock() } single<TrustedSocketFactory> { TrustedSocketFactory { _, _, _, _ -> null } Loading feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountStateTest.kt +24 −54 Original line number Diff line number Diff line package app.k9mail.feature.account.edit.domain.usecase import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository import app.k9mail.feature.account.common.domain.entity.Account import app.k9mail.feature.account.common.domain.entity.AccountOptions import app.k9mail.feature.account.common.domain.entity.AccountState import app.k9mail.feature.account.common.domain.entity.AuthorizationState Loading @@ -10,6 +9,7 @@ import assertk.assertThat import assertk.assertions.isEqualTo import com.fsck.k9.mail.AuthType import com.fsck.k9.mail.ServerSettings import kotlin.test.DefaultAsserter.fail import kotlinx.coroutines.test.runTest import org.junit.Test Loading @@ -18,78 +18,39 @@ class LoadAccountStateTest { @Test fun `should load account state WHEN account in state repository has different UUID`() = runTest { val testSubject = LoadAccountState( accountLoader = { accountUuid -> Account( uuid = accountUuid, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AUTHORIZATION_STATE, options = OPTIONS, ) accountStateLoader = { _ -> ACCOUNT_STATE }, accountStateRepository = InMemoryAccountStateRepository(), accountStateRepository = InMemoryAccountStateRepository( state = ACCOUNT_STATE.copy(uuid = "differentUuid"), ), ) val result = testSubject.execute(ACCOUNT_UUID) assertThat(result).isEqualTo( AccountState( uuid = ACCOUNT_UUID, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AuthorizationState(AUTHORIZATION_STATE), options = OPTIONS, ), ) assertThat(result).isEqualTo(ACCOUNT_STATE) } @Test fun `should return account state WHEN account in state repository has same UUID`() = runTest { val testSubject = LoadAccountState( accountLoader = { accountUuid -> Account( uuid = accountUuid, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AUTHORIZATION_STATE, options = OPTIONS, ) accountStateLoader = { _ -> fail("AccountStateLoader should not be called in this test") }, accountStateRepository = InMemoryAccountStateRepository().apply { setState( AccountState( uuid = ACCOUNT_UUID, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AuthorizationState(AUTHORIZATION_STATE), options = OPTIONS, accountStateRepository = InMemoryAccountStateRepository( state = ACCOUNT_STATE, ), ) }, ) val result = testSubject.execute(ACCOUNT_UUID) assertThat(result).isEqualTo( AccountState( uuid = ACCOUNT_UUID, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AuthorizationState(AUTHORIZATION_STATE), options = OPTIONS, ), ) assertThat(result).isEqualTo(ACCOUNT_STATE) } @Test fun `should return empty account state WHEN account loader returns null`() = runTest { val testSubject = LoadAccountState( accountLoader = { null }, accountStateLoader = { null }, accountStateRepository = InMemoryAccountStateRepository(), ) Loading Loading @@ -131,7 +92,7 @@ class LoadAccountStateTest { clientCertificateAlias = null, ) const val AUTHORIZATION_STATE = "authorization state" val AUTHORIZATION_STATE = AuthorizationState("authorization state") val OPTIONS = AccountOptions( accountName = "accountName", Loading @@ -141,5 +102,14 @@ class LoadAccountStateTest { messageDisplayCount = 25, showNotification = true, ) val ACCOUNT_STATE = AccountState( uuid = ACCOUNT_UUID, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AUTHORIZATION_STATE, options = OPTIONS, ) } } Loading
feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/AccountEditModule.kt +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ val featureAccountEditModule = module { factory<AccountEditDomainContract.UseCase.LoadAccountState> { LoadAccountState( accountLoader = get(), accountStateLoader = get(), accountStateRepository = get(), ) } Loading
feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountState.kt +3 −15 Original line number Diff line number Diff line Loading @@ -2,13 +2,11 @@ package app.k9mail.feature.account.edit.domain.usecase import app.k9mail.feature.account.common.AccountCommonExternalContract import app.k9mail.feature.account.common.domain.AccountDomainContract 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 import app.k9mail.feature.account.edit.domain.AccountEditDomainContract class LoadAccountState( private val accountLoader: AccountCommonExternalContract.AccountLoader, private val accountStateLoader: AccountCommonExternalContract.AccountStateLoader, private val accountStateRepository: AccountDomainContract.AccountStateRepository, ) : AccountEditDomainContract.UseCase.LoadAccountState { override suspend fun execute(accountUuid: String): AccountState { Loading @@ -21,21 +19,11 @@ class LoadAccountState( } private suspend fun loadState(accountUuid: String): AccountState { val account = accountLoader.loadAccount(accountUuid) return if (account != null) { val accountState = account.mapToAccountState() val accountState = accountStateLoader.loadAccountState(accountUuid) return if (accountState != null) { accountState } else { AccountState(uuid = accountUuid) }.also { accountStateRepository.setState(it) } } private fun Account.mapToAccountState() = AccountState( uuid = uuid, emailAddress = emailAddress, incomingServerSettings = incomingServerSettings, outgoingServerSettings = outgoingServerSettings, authorizationState = AuthorizationState(authorizationState), options = options, ) }
feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/AccountEditModuleKtTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ import org.robolectric.RuntimeEnvironment class AccountEditModuleKtTest : KoinTest { private val externalModule: Module = module { single<AccountCommonExternalContract.AccountLoader> { Mockito.mock() } single<AccountCommonExternalContract.AccountStateLoader> { Mockito.mock() } single<LocalKeyStore> { Mockito.mock() } single<TrustedSocketFactory> { TrustedSocketFactory { _, _, _, _ -> null } Loading
feature/account/edit/src/test/kotlin/app/k9mail/feature/account/edit/domain/usecase/LoadAccountStateTest.kt +24 −54 Original line number Diff line number Diff line package app.k9mail.feature.account.edit.domain.usecase import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository import app.k9mail.feature.account.common.domain.entity.Account import app.k9mail.feature.account.common.domain.entity.AccountOptions import app.k9mail.feature.account.common.domain.entity.AccountState import app.k9mail.feature.account.common.domain.entity.AuthorizationState Loading @@ -10,6 +9,7 @@ import assertk.assertThat import assertk.assertions.isEqualTo import com.fsck.k9.mail.AuthType import com.fsck.k9.mail.ServerSettings import kotlin.test.DefaultAsserter.fail import kotlinx.coroutines.test.runTest import org.junit.Test Loading @@ -18,78 +18,39 @@ class LoadAccountStateTest { @Test fun `should load account state WHEN account in state repository has different UUID`() = runTest { val testSubject = LoadAccountState( accountLoader = { accountUuid -> Account( uuid = accountUuid, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AUTHORIZATION_STATE, options = OPTIONS, ) accountStateLoader = { _ -> ACCOUNT_STATE }, accountStateRepository = InMemoryAccountStateRepository(), accountStateRepository = InMemoryAccountStateRepository( state = ACCOUNT_STATE.copy(uuid = "differentUuid"), ), ) val result = testSubject.execute(ACCOUNT_UUID) assertThat(result).isEqualTo( AccountState( uuid = ACCOUNT_UUID, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AuthorizationState(AUTHORIZATION_STATE), options = OPTIONS, ), ) assertThat(result).isEqualTo(ACCOUNT_STATE) } @Test fun `should return account state WHEN account in state repository has same UUID`() = runTest { val testSubject = LoadAccountState( accountLoader = { accountUuid -> Account( uuid = accountUuid, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AUTHORIZATION_STATE, options = OPTIONS, ) accountStateLoader = { _ -> fail("AccountStateLoader should not be called in this test") }, accountStateRepository = InMemoryAccountStateRepository().apply { setState( AccountState( uuid = ACCOUNT_UUID, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AuthorizationState(AUTHORIZATION_STATE), options = OPTIONS, accountStateRepository = InMemoryAccountStateRepository( state = ACCOUNT_STATE, ), ) }, ) val result = testSubject.execute(ACCOUNT_UUID) assertThat(result).isEqualTo( AccountState( uuid = ACCOUNT_UUID, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AuthorizationState(AUTHORIZATION_STATE), options = OPTIONS, ), ) assertThat(result).isEqualTo(ACCOUNT_STATE) } @Test fun `should return empty account state WHEN account loader returns null`() = runTest { val testSubject = LoadAccountState( accountLoader = { null }, accountStateLoader = { null }, accountStateRepository = InMemoryAccountStateRepository(), ) Loading Loading @@ -131,7 +92,7 @@ class LoadAccountStateTest { clientCertificateAlias = null, ) const val AUTHORIZATION_STATE = "authorization state" val AUTHORIZATION_STATE = AuthorizationState("authorization state") val OPTIONS = AccountOptions( accountName = "accountName", Loading @@ -141,5 +102,14 @@ class LoadAccountStateTest { messageDisplayCount = 25, showNotification = true, ) val ACCOUNT_STATE = AccountState( uuid = ACCOUNT_UUID, emailAddress = EMAIL_ADDRESS, incomingServerSettings = INCOMING_SERVER_SETTINGS, outgoingServerSettings = OUTGOING_SERVER_SETTINGS, authorizationState = AUTHORIZATION_STATE, options = OPTIONS, ) } }