diff --git a/app/core/src/main/java/com/fsck/k9/account/DeletePolicyHelper.kt b/app/core/src/main/java/com/fsck/k9/account/DeletePolicyHelper.kt new file mode 100644 index 000000000..86394ed39 --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/account/DeletePolicyHelper.kt @@ -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") + } + } +} diff --git a/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt b/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt index 674b8a2e7..2f23ab7dc 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt @@ -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) diff --git a/app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt b/app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt index 0df1d76c4..e0761974b 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt @@ -22,7 +22,6 @@ val newAccountModule = module { factory { AccountCreator( - accountCreatorHelper = get(), accountColorPicker = get(), localFoldersCreator = get(), preferences = get(), diff --git a/app/k9mail/src/test/java/com/fsck/k9/account/DeletePolicyHelperTest.kt b/app/k9mail/src/test/java/com/fsck/k9/account/DeletePolicyHelperTest.kt new file mode 100644 index 000000000..a42a2a345 --- /dev/null +++ b/app/k9mail/src/test/java/com/fsck/k9/account/DeletePolicyHelperTest.kt @@ -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() + } +} diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountCreatorHelper.kt b/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountCreatorHelper.kt deleted file mode 100644 index 4cff79515..000000000 --- a/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountCreatorHelper.kt +++ /dev/null @@ -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 - } -} diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/account/KoinModule.kt b/app/ui/legacy/src/main/java/com/fsck/k9/account/KoinModule.kt index 70ab597b7..589388616 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/account/KoinModule.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/account/KoinModule.kt @@ -14,7 +14,6 @@ val accountModule = module { ) } factory { BackgroundAccountRemover(get()) } - factory { AccountCreatorHelper() } factory { (parameters: WorkerParameters) -> AccountRemoverWorker(accountRemover = get(), notificationController = get(), context = get(), parameters) } diff --git a/app/ui/legacy/src/test/java/com/fsck/k9/account/AccountCreatorHelperTest.kt b/app/ui/legacy/src/test/java/com/fsck/k9/account/AccountCreatorHelperTest.kt deleted file mode 100644 index 903e5459a..000000000 --- a/app/ui/legacy/src/test/java/com/fsck/k9/account/AccountCreatorHelperTest.kt +++ /dev/null @@ -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() - } - - @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) - } -}