Merge pull request #7411 from thunderbird/remove_account_creator_helper

Remove `AccountCreatorHelper`
This commit is contained in:
Wolf-Martell Montwé 2023-12-05 13:17:59 +00:00 committed by GitHub
commit 778ceecdab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 102 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,43 +0,0 @@
package com.fsck.k9.account
import app.k9mail.core.common.mail.Protocols
import com.fsck.k9.Account.DeletePolicy
import com.fsck.k9.mail.ConnectionSecurity
/**
* Deals with logic surrounding account creation.
*
* TODO move this close to account creator
*/
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")
}
}
fun getDefaultPort(securityType: ConnectionSecurity, serverType: String): Int {
return when (serverType) {
Protocols.IMAP -> getImapDefaultPort(securityType)
Protocols.POP3 -> getPop3DefaultPort(securityType)
Protocols.SMTP -> getSmtpDefaultPort(securityType)
else -> throw AssertionError("Unhandled case: $serverType")
}
}
private fun getImapDefaultPort(connectionSecurity: ConnectionSecurity): Int {
return if (connectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED) 993 else 143
}
private fun getPop3DefaultPort(connectionSecurity: ConnectionSecurity): Int {
return if (connectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED) 995 else 110
}
private fun getSmtpDefaultPort(connectionSecurity: ConnectionSecurity): Int {
return if (connectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED) 465 else 587
}
}

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,55 +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 com.fsck.k9.mail.ConnectionSecurity
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>()
}
@Test
fun `getDefaultPort with NoConnectionSecurity and IMAP should return default port`() {
val result = accountCreatorHelper.getDefaultPort(ConnectionSecurity.NONE, Protocols.IMAP)
assertThat(result).isEqualTo(143)
}
@Test
fun `getDefaultPort with StartTls and IMAP should return default port`() {
val result = accountCreatorHelper.getDefaultPort(ConnectionSecurity.STARTTLS_REQUIRED, Protocols.IMAP)
assertThat(result).isEqualTo(143)
}
@Test
fun `getDefaultPort with Tls and IMAP should return default Tls port`() {
val result = accountCreatorHelper.getDefaultPort(ConnectionSecurity.SSL_TLS_REQUIRED, Protocols.IMAP)
assertThat(result).isEqualTo(993)
}
}