Rename AccountCreator to AccountCreatorHelper

This commit is contained in:
Wolf-Martell Montwé 2023-06-27 17:41:19 +02:00
parent 10aab087dd
commit 09c00f3bf8
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
7 changed files with 27 additions and 29 deletions

View file

@ -12,7 +12,7 @@ import com.fsck.k9.mail.ConnectionSecurity
*
* TODO Move much of the code from com.fsck.k9.activity.setup.* into here
*/
class AccountCreator(private val preferences: Preferences, private val resources: Resources) {
class AccountCreatorHelper(private val preferences: Preferences, private val resources: Resources) {
fun getDefaultDeletePolicy(type: String): DeletePolicy {
return when (type) {

View file

@ -13,5 +13,5 @@ val accountModule = module {
)
}
factory { BackgroundAccountRemover(get()) }
factory { AccountCreator(get(), get()) }
factory { AccountCreatorHelper(get(), get()) }
}

View file

@ -16,7 +16,7 @@ import com.fsck.k9.Account
import com.fsck.k9.Core
import com.fsck.k9.EmailAddressValidator
import com.fsck.k9.Preferences
import com.fsck.k9.account.AccountCreator
import com.fsck.k9.account.AccountCreatorHelper
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection
import com.fsck.k9.helper.SimpleTextWatcher
import com.fsck.k9.helper.Utility.requiredFieldValid
@ -42,7 +42,7 @@ import org.koin.android.ext.android.inject
*/
class AccountSetupBasics : K9Activity() {
private val providersXmlDiscovery: ProvidersXmlDiscovery by inject()
private val accountCreator: AccountCreator by inject()
private val accountCreatorHelper: AccountCreatorHelper by inject()
private val localFoldersCreator: SpecialLocalFoldersCreator by inject()
private val preferences: Preferences by inject()
private val emailValidator: EmailAddressValidator by inject()
@ -258,7 +258,7 @@ class AccountSetupBasics : K9Activity() {
val outgoingServerSettings = connectionSettings.outgoing.newPassword(password)
account.outgoingServerSettings = outgoingServerSettings
account.deletePolicy = accountCreator.getDefaultDeletePolicy(incomingServerSettings.type)
account.deletePolicy = accountCreatorHelper.getDefaultDeletePolicy(incomingServerSettings.type)
localFoldersCreator.createSpecialLocalFolders(account)
@ -301,7 +301,7 @@ class AccountSetupBasics : K9Activity() {
private fun createAccount(): Account {
return preferences.newAccount().apply {
chipColor = accountCreator.pickColor()
chipColor = accountCreatorHelper.pickColor()
}
}

View file

@ -32,7 +32,7 @@ import com.fsck.k9.Account;
import com.fsck.k9.DI;
import com.fsck.k9.LocalKeyStoreManager;
import com.fsck.k9.Preferences;
import com.fsck.k9.account.AccountCreator;
import com.fsck.k9.account.AccountCreatorHelper;
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
import com.fsck.k9.helper.EmailHelper;
import com.fsck.k9.helper.Utility;
@ -59,7 +59,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
private static final String STATE_SECURITY_TYPE_POSITION = "stateSecurityTypePosition";
private static final String STATE_AUTH_TYPE_POSITION = "authTypePosition";
private final AccountCreator accountCreator = DI.get(AccountCreator.class);
private final AccountCreatorHelper accountCreatorHelper = DI.get(AccountCreatorHelper.class);
private final SuggestServerName serverNameSuggester = DI.get(SuggestServerName.class);
private String mStoreType;
@ -224,7 +224,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
}
if (!editSettings) {
mAccount.setDeletePolicy(accountCreator.getDefaultDeletePolicy(settings.type));
mAccount.setDeletePolicy(accountCreatorHelper.getDefaultDeletePolicy(settings.type));
}
// Note that mConnectionSecurityChoices is configured above based on server type
@ -485,7 +485,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
// Remove listener so as not to trigger validateFields() which is called
// elsewhere as a result of user interaction.
mPortView.removeTextChangedListener(validationTextWatcher);
mPortView.setText(String.valueOf(accountCreator.getDefaultPort(securityType, mStoreType)));
mPortView.setText(String.valueOf(accountCreatorHelper.getDefaultPort(securityType, mStoreType)));
mPortView.addTextChangedListener(validationTextWatcher);
}

View file

@ -30,7 +30,7 @@ import com.fsck.k9.LocalKeyStoreManager;
import com.fsck.k9.Preferences;
import app.k9mail.core.common.mail.Protocols;
import com.fsck.k9.ui.R;
import com.fsck.k9.account.AccountCreator;
import com.fsck.k9.account.AccountCreatorHelper;
import com.fsck.k9.ui.base.K9Activity;
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
import com.fsck.k9.helper.Utility;
@ -53,7 +53,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
private static final String STATE_AUTH_TYPE_POSITION = "authTypePosition";
private final AccountCreator accountCreator = DI.get(AccountCreator.class);
private final AccountCreatorHelper accountCreatorHelper = DI.get(AccountCreatorHelper.class);
private TextInputEditText mUsernameView;
private TextInputEditText mPasswordView;
@ -476,7 +476,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
// Remove listener so as not to trigger validateFields() which is called
// elsewhere as a result of user interaction.
mPortView.removeTextChangedListener(validationTextWatcher);
mPortView.setText(String.valueOf(accountCreator.getDefaultPort(securityType, Protocols.SMTP)));
mPortView.setText(String.valueOf(accountCreatorHelper.getDefaultPort(securityType, Protocols.SMTP)));
mPortView.addTextChangedListener(validationTextWatcher);
}

View file

@ -17,51 +17,51 @@ import static org.mockito.Mockito.mock;
public class AccountCreatorTest extends RobolectricTest {
private AccountCreator accountCreator;
private AccountCreatorHelper accountCreatorHelper;
@Before
public void setUp() {
Preferences preferences = mock(Preferences.class);
Resources resources = mock(Resources.class);
accountCreator = new AccountCreator(preferences, resources);
accountCreatorHelper = new AccountCreatorHelper(preferences, resources);
}
@Test
public void getDefaultDeletePolicy_withImap_shouldReturn_ON_DELETE() {
DeletePolicy result = accountCreator.getDefaultDeletePolicy(Protocols.IMAP);
DeletePolicy result = accountCreatorHelper.getDefaultDeletePolicy(Protocols.IMAP);
assertEquals(DeletePolicy.ON_DELETE, result);
}
@Test
public void getDefaultDeletePolicy_withPop3_shouldReturn_NEVER() {
DeletePolicy result = accountCreator.getDefaultDeletePolicy(Protocols.POP3);
DeletePolicy result = accountCreatorHelper.getDefaultDeletePolicy(Protocols.POP3);
assertEquals(DeletePolicy.NEVER, result);
}
@Test(expected = AssertionError.class)
public void getDefaultDeletePolicy_withSmtp_shouldFail() {
accountCreator.getDefaultDeletePolicy(Protocols.SMTP);
accountCreatorHelper.getDefaultDeletePolicy(Protocols.SMTP);
}
@Test
public void getDefaultPort_withNoConnectionSecurityAndImap_shouldReturnDefaultPort() {
int result = accountCreator.getDefaultPort(ConnectionSecurity.NONE, Protocols.IMAP);
int result = accountCreatorHelper.getDefaultPort(ConnectionSecurity.NONE, Protocols.IMAP);
assertEquals(143, result);
}
@Test
public void getDefaultPort_withStartTlsAndImap_shouldReturnDefaultPort() {
int result = accountCreator.getDefaultPort(ConnectionSecurity.STARTTLS_REQUIRED, Protocols.IMAP);
int result = accountCreatorHelper.getDefaultPort(ConnectionSecurity.STARTTLS_REQUIRED, Protocols.IMAP);
assertEquals(143, result);
}
@Test
public void getDefaultPort_withTlsAndImap_shouldReturnDefaultTlsPort() {
int result = accountCreator.getDefaultPort(ConnectionSecurity.SSL_TLS_REQUIRED, Protocols.IMAP);
int result = accountCreatorHelper.getDefaultPort(ConnectionSecurity.SSL_TLS_REQUIRED, Protocols.IMAP);
assertEquals(993, result);
}

View file

@ -156,12 +156,12 @@
<ID>MagicNumber:Account.kt$Account$6</ID>
<ID>MagicNumber:Account.kt$Account$84</ID>
<ID>MagicNumber:Account.kt$Account.DeletePolicy.MARK_AS_READ$3</ID>
<ID>MagicNumber:AccountCreator.kt$AccountCreator$110</ID>
<ID>MagicNumber:AccountCreator.kt$AccountCreator$143</ID>
<ID>MagicNumber:AccountCreator.kt$AccountCreator$465</ID>
<ID>MagicNumber:AccountCreator.kt$AccountCreator$587</ID>
<ID>MagicNumber:AccountCreator.kt$AccountCreator$993</ID>
<ID>MagicNumber:AccountCreator.kt$AccountCreator$995</ID>
<ID>MagicNumber:AccountCreatorHelper.kt$AccountCreatorHelper$110</ID>
<ID>MagicNumber:AccountCreatorHelper.kt$AccountCreatorHelper$143</ID>
<ID>MagicNumber:AccountCreatorHelper.kt$AccountCreatorHelper$465</ID>
<ID>MagicNumber:AccountCreatorHelper.kt$AccountCreatorHelper$587</ID>
<ID>MagicNumber:AccountCreatorHelper.kt$AccountCreatorHelper$993</ID>
<ID>MagicNumber:AccountCreatorHelper.kt$AccountCreatorHelper$995</ID>
<ID>MagicNumber:AccountItem.kt$AccountItem$200L</ID>
<ID>MagicNumber:AccountPreferenceSerializer.kt$AccountPreferenceSerializer$10</ID>
<ID>MagicNumber:AccountPreferenceSerializer.kt$AccountPreferenceSerializer$24</ID>
@ -590,7 +590,6 @@
<ID>SwallowedException:SettingsExporter.kt$SettingsExporter$e: InvalidSettingValueException</ID>
<ID>SwallowedException:SettingsListFragment.kt$SettingsListFragment$e: ActivityNotFoundException</ID>
<ID>SwallowedException:SmtpTransport.kt$SmtpTransport$e: NegativeSmtpReplyException</ID>
<ID>SwallowedException:SmtpTransport.kt$SmtpTransport$exception: NegativeSmtpReplyException</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:RealImapConnection.kt$RealImapConnection$Exception()</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:SmtpTransport.kt$SmtpTransport$RuntimeException()</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:TimberLogger.kt$TimberLogger$Throwable()</ID>
@ -600,7 +599,6 @@
<ID>ThrowsCount:RealImapConnection.kt$RealImapConnection$private fun authenticate(): List&lt;ImapResponse&gt;</ID>
<ID>ThrowsCount:SmtpTransport.kt$SmtpTransport$@Throws(MessagingException::class) fun sendMessage(message: Message)</ID>
<ID>ThrowsCount:SmtpTransport.kt$SmtpTransport$@VisibleForTesting @Throws(MessagingException::class) internal fun open()</ID>
<ID>ThrowsCount:SmtpTransport.kt$SmtpTransport$private fun saslAuthCramMD5()</ID>
<ID>TooGenericExceptionCaught:AccountRemover.kt$AccountRemover$e: Exception</ID>
<ID>TooGenericExceptionCaught:AccountSetupCheckSettings.kt$AccountSetupCheckSettings$e: Exception</ID>
<ID>TooGenericExceptionCaught:AccountSetupCheckSettings.kt$AccountSetupCheckSettings.CheckAccountTask$e: Exception</ID>