Replace AccountCreatorHelper with DeletePolicyHelper

This commit is contained in:
Wolf-Martell Montwé 2023-12-04 17:03:57 +01:00
parent ee3e9c4eb4
commit 530a7b0524
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
7 changed files with 56 additions and 56 deletions

View file

@ -0,0 +1,15 @@
package com.fsck.k9.account
import app.k9mail.core.common.mail.Protocols
import com.fsck.k9.Account
object DeletePolicyHelper {
fun getDefaultDeletePolicy(type: String): Account.DeletePolicy {
return when (type) {
Protocols.IMAP -> Account.DeletePolicy.ON_DELETE
Protocols.POP3 -> Account.DeletePolicy.NEVER
"demo" -> Account.DeletePolicy.ON_DELETE
else -> throw AssertionError("Unhandled case: $type")
}
}
}

View file

@ -23,7 +23,6 @@ import com.fsck.k9.Account as K9Account
// TODO Move to feature/account/setup
class AccountCreator(
private val accountCreatorHelper: AccountCreatorHelper,
private val accountColorPicker: AccountColorPicker,
private val localFoldersCreator: SpecialLocalFoldersCreator,
private val preferences: Preferences,
@ -63,7 +62,7 @@ class AccountCreator(
newAccount.displayCount = account.options.messageDisplayCount
newAccount.folderPushMode = FolderMode.NONE
newAccount.deletePolicy = accountCreatorHelper.getDefaultDeletePolicy(newAccount.incomingServerSettings.type)
newAccount.deletePolicy = DeletePolicyHelper.getDefaultDeletePolicy(newAccount.incomingServerSettings.type)
newAccount.chipColor = accountColorPicker.pickColor()
localFoldersCreator.createSpecialLocalFolders(newAccount)

View file

@ -22,7 +22,6 @@ val newAccountModule = module {
factory<AccountSetupExternalContract.AccountCreator> {
AccountCreator(
accountCreatorHelper = get(),
accountColorPicker = get(),
localFoldersCreator = get(),
preferences = get(),

View file

@ -0,0 +1,40 @@
package com.fsck.k9.account
import app.k9mail.core.common.mail.Protocols
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isInstanceOf
import com.fsck.k9.Account
import org.junit.Test
class DeletePolicyHelperTest {
@Test
fun `getDefaultDeletePolicy with IMAP should return ON_DELETE`() {
val result = DeletePolicyHelper.getDefaultDeletePolicy(Protocols.IMAP)
assertThat(result).isEqualTo(Account.DeletePolicy.ON_DELETE)
}
@Test
fun `getDefaultDeletePolicy with POP3 should return NEVER`() {
val result = DeletePolicyHelper.getDefaultDeletePolicy(Protocols.POP3)
assertThat(result).isEqualTo(Account.DeletePolicy.NEVER)
}
@Test
fun `getDefaultDeletePolicy with demo should return ON_DELETE`() {
val result = DeletePolicyHelper.getDefaultDeletePolicy("demo")
assertThat(result).isEqualTo(Account.DeletePolicy.ON_DELETE)
}
@Test
fun `getDefaultDeletePolicy with SMTP should fail`() {
assertFailure {
DeletePolicyHelper.getDefaultDeletePolicy(Protocols.SMTP)
}.isInstanceOf<AssertionError>()
}
}

View file

@ -1,19 +0,0 @@
package com.fsck.k9.account
import app.k9mail.core.common.mail.Protocols
import com.fsck.k9.Account.DeletePolicy
/**
* Deals with logic surrounding account creation.
*/
class AccountCreatorHelper {
fun getDefaultDeletePolicy(type: String): DeletePolicy {
return when (type) {
Protocols.IMAP -> DeletePolicy.ON_DELETE
Protocols.POP3 -> DeletePolicy.NEVER
"demo" -> DeletePolicy.ON_DELETE
else -> throw AssertionError("Unhandled case: $type")
}
}
}

View file

@ -14,7 +14,6 @@ val accountModule = module {
)
}
factory { BackgroundAccountRemover(get()) }
factory { AccountCreatorHelper() }
factory { (parameters: WorkerParameters) ->
AccountRemoverWorker(accountRemover = get(), notificationController = get(), context = get(), parameters)
}

View file

@ -1,33 +0,0 @@
import app.k9mail.core.common.mail.Protocols
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isInstanceOf
import com.fsck.k9.Account.DeletePolicy
import com.fsck.k9.account.AccountCreatorHelper
import org.junit.Test
class AccountCreatorHelperTest {
private val accountCreatorHelper = AccountCreatorHelper()
@Test
fun `getDefaultDeletePolicy with IMAP should return ON_DELETE`() {
val result = accountCreatorHelper.getDefaultDeletePolicy(Protocols.IMAP)
assertThat(result).isEqualTo(DeletePolicy.ON_DELETE)
}
@Test
fun `getDefaultDeletePolicy with POP3 should return NEVER`() {
val result = accountCreatorHelper.getDefaultDeletePolicy(Protocols.POP3)
assertThat(result).isEqualTo(DeletePolicy.NEVER)
}
@Test
fun `getDefaultDeletePolicy with SMTP should fail`() {
assertFailure {
accountCreatorHelper.getDefaultDeletePolicy(Protocols.SMTP)
}.isInstanceOf<AssertionError>()
}
}