Cleanup broken unit tests from previous submit. This now works:

What works:
* All unit tests
* Editing existing accounts
* Create new accounts
* Checking account settings against server
* Mail sync using accounts
* Viewing mailboxes

What breaks (in approx order of planned fixes)
* Viewing messages
* Composing messages
* Some details of account editing
* Import of existing accounts
This commit is contained in:
Andrew Stadler 2009-06-09 14:46:30 -07:00
parent c0033f24a2
commit d2b0efa2f5
10 changed files with 115 additions and 53 deletions

View File

@ -421,9 +421,11 @@ public class MessagingController implements Runnable {
try {
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(mContext),
mContext);
LocalStore localStore = (LocalStore) Store.getInstance(
account.getLocalStoreUri(mContext), mContext, null);
localStore.resetVisibleLimits(info.mVisibleLimitDefault);
if (info != null) {
LocalStore localStore = (LocalStore) Store.getInstance(
account.getLocalStoreUri(mContext), mContext, null);
localStore.resetVisibleLimits(info.mVisibleLimitDefault);
}
}
catch (MessagingException e) {
Log.e(Email.LOG_TAG, "Unable to reset visible limits", e);

View File

@ -860,6 +860,7 @@ public class EmailStore {
*
* @param the new value
*/
@Deprecated
public void setStoreUri(Context context, String senderUri) {
// reconstitute or create if necessary
if (mHostAuthRecv == null) {
@ -880,6 +881,7 @@ public class EmailStore {
*
* @param the new value
*/
@Deprecated
public void setSenderUri(Context context, String senderUri) {
// reconstitute or create if necessary
if (mHostAuthSend == null) {
@ -1700,6 +1702,7 @@ public class EmailStore {
/**
* For compatibility while converting to provider model, generate a "store URI"
* TODO cache this so we don't rebuild every time
*
* @return a string in the form of a Uri, as used by the other parts of the email app
*/
@ -1712,17 +1715,21 @@ public class EmailStore {
}
String userInfo = null;
if ((mFlags & FLAG_AUTHENTICATE) != 0) {
userInfo = mLogin.trim() + ":" + mPassword.trim();
String trimUser = (mLogin != null) ? mLogin.trim() : "";
String trimPassword = (mPassword != null) ? mPassword.trim() : "";
userInfo = trimUser + ":" + trimPassword;
}
String address = (mAddress != null) ? mAddress.trim() : null;
String path = (mDomain != null) ? "/" + mDomain : null;
URI uri;
try {
uri = new URI(
mProtocol + security,
userInfo,
mAddress.trim(),
address,
mPort,
mDomain, // path
path,
null,
null);
return uri.toString();
@ -1736,6 +1743,7 @@ public class EmailStore {
*
* @param uriString a String containing a Uri
*/
@Deprecated
public void setStoreUri(String uriString) {
try {
URI uri = new URI(uriString);
@ -1745,9 +1753,9 @@ public class EmailStore {
if (uri.getUserInfo() != null) {
String[] userInfoParts = uri.getUserInfo().split(":", 2);
mLogin = userInfoParts[0];
mFlags |= FLAG_AUTHENTICATE;
if (userInfoParts.length > 1) {
mPassword = userInfoParts[1];
mFlags |= FLAG_AUTHENTICATE;
}
}

View File

@ -42,13 +42,14 @@ public class FolderMessageListUnitTests extends AndroidTestCase {
*/
@Override
protected void tearDown() throws Exception {
super.tearDown();
if (mAccount != null) {
Uri uri = ContentUris.withAppendedId(
EmailStore.Account.CONTENT_URI, mAccountId);
getContext().getContentResolver().delete(uri, null, null);
}
// must call last because it scrubs member variables
super.tearDown();
}
/**

View File

@ -64,13 +64,14 @@ public class AccountSettingsTests extends ActivityInstrumentationTestCase2<Accou
*/
@Override
protected void tearDown() throws Exception {
super.tearDown();
if (mAccount != null) {
Uri uri = ContentUris.withAppendedId(
EmailStore.Account.CONTENT_URI, mAccountId);
mContext.getContentResolver().delete(uri, null, null);
}
// must call last because it scrubs member variables
super.tearDown();
}
/**

View File

@ -16,12 +16,13 @@
package com.android.email.activity.setup;
import com.android.email.Account;
import com.android.email.Preferences;
import com.android.email.mail.Store;
import com.android.email.provider.EmailStore;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.SmallTest;
@ -36,10 +37,12 @@ import java.util.HashSet;
public class AccountSetupAccountTypeUnitTests
extends ActivityUnitTestCase<AccountSetupAccountType> {
// Borrowed from AccountSetupAccountType
private static final String EXTRA_ACCOUNT = "account";
Context mContext;
private Preferences mPreferences;
private HashSet<Account> mAccounts = new HashSet<Account>();
private HashSet<EmailStore.Account> mAccounts = new HashSet<EmailStore.Account>();
public AccountSetupAccountTypeUnitTests() {
super(AccountSetupAccountType.class);
@ -50,7 +53,6 @@ public class AccountSetupAccountTypeUnitTests
super.setUp();
mContext = this.getInstrumentation().getTargetContext();
mPreferences = Preferences.getPreferences(mContext);
}
/**
@ -58,22 +60,23 @@ public class AccountSetupAccountTypeUnitTests
*/
@Override
protected void tearDown() throws Exception {
super.tearDown();
if (mPreferences != null) {
for (Account account : mAccounts) {
account.delete(mPreferences);
}
for (EmailStore.Account account : mAccounts) {
Uri uri = ContentUris.withAppendedId(
EmailStore.Account.CONTENT_URI, account.mId);
mContext.getContentResolver().delete(uri, null, null);
}
// must call last because it scrubs member variables
super.tearDown();
}
/**
* Test store type limit enforcement
*/
public void testStoreTypeLimits() {
Account acct1 = createTestAccount("scheme1");
Account acct2 = createTestAccount("scheme1");
Account acct3 = createTestAccount("scheme2");
EmailStore.Account acct1 = createTestAccount("scheme1");
EmailStore.Account acct2 = createTestAccount("scheme1");
EmailStore.Account acct3 = createTestAccount("scheme2");
AccountSetupAccountType activity = startActivity(getTestIntent(acct1), null, null);
@ -95,10 +98,10 @@ public class AccountSetupAccountTypeUnitTests
/**
* Create a dummy account with minimal fields
*/
private Account createTestAccount(String scheme) {
Account account = new Account(mContext);
account.setStoreUri(scheme + "://user:pass@server.com:port");
account.save(mPreferences);
private EmailStore.Account createTestAccount(String scheme) {
EmailStore.Account account = new EmailStore.Account();
account.setStoreUri(mContext, scheme + "://user:pass@server.com:123");
account.saveOrUpdate(mContext);
mAccounts.add(account);
return account;
}
@ -106,9 +109,9 @@ public class AccountSetupAccountTypeUnitTests
/**
* Create an intent with the Account in it
*/
private Intent getTestIntent(Account account) {
private Intent getTestIntent(EmailStore.Account account) {
Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account"
i.putExtra(EXTRA_ACCOUNT, account);
return i;
}

View File

@ -16,8 +16,8 @@
package com.android.email.activity.setup;
import com.android.email.Account;
import com.android.email.R;
import com.android.email.provider.EmailStore;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
@ -33,6 +33,9 @@ import android.widget.EditText;
public class AccountSetupExchangeTests extends
ActivityInstrumentationTestCase2<AccountSetupExchange> {
// borrowed from AccountSetupExchange
private static final String EXTRA_ACCOUNT = "account";
private AccountSetupExchange mActivity;
private EditText mServerView;
private EditText mDomainView;
@ -171,10 +174,10 @@ public class AccountSetupExchangeTests extends
* Create an intent with the Account in it
*/
private Intent getTestIntent(String storeUriString) {
Account account = new Account(this.getInstrumentation().getTargetContext());
account.setStoreUri(storeUriString);
EmailStore.Account account = new EmailStore.Account();
account.setStoreUri(getInstrumentation().getTargetContext(), storeUriString);
Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account"
i.putExtra(EXTRA_ACCOUNT, account);
return i;
}

View File

@ -16,8 +16,8 @@
package com.android.email.activity.setup;
import com.android.email.Account;
import com.android.email.R;
import com.android.email.provider.EmailStore;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
@ -32,6 +32,9 @@ import android.widget.EditText;
@MediumTest
public class AccountSetupIncomingTests extends
ActivityInstrumentationTestCase2<AccountSetupIncoming> {
// borrowed from AccountSetupIncoming
private static final String EXTRA_ACCOUNT = "account";
private AccountSetupIncoming mActivity;
private EditText mServerView;
@ -141,10 +144,10 @@ public class AccountSetupIncomingTests extends
* Create an intent with the Account in it
*/
private Intent getTestIntent(String storeUriString) {
Account account = new Account(this.getInstrumentation().getTargetContext());
account.setStoreUri(storeUriString);
EmailStore.Account account = new EmailStore.Account();
account.setStoreUri(getInstrumentation().getTargetContext(), storeUriString);
Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account"
i.putExtra(EXTRA_ACCOUNT, account);
return i;
}

View File

@ -16,10 +16,13 @@
package com.android.email.activity.setup;
import com.android.email.Account;
import com.android.email.R;
import com.android.email.provider.EmailStore;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest;
import android.widget.Button;
@ -30,6 +33,13 @@ import android.widget.Button;
@MediumTest
public class AccountSetupNamesTests extends ActivityInstrumentationTestCase2<AccountSetupNames> {
// borrowed from AccountSetupNames
private static final String EXTRA_ACCOUNT_ID = "accountId";
private long mAccountId;
private EmailStore.Account mAccount;
private Context mContext;
private AccountSetupNames mActivity;
private Button mDoneButton;
@ -37,6 +47,31 @@ public class AccountSetupNamesTests extends ActivityInstrumentationTestCase2<Acc
super("com.android.email", AccountSetupNames.class);
}
/**
* Common setup code for all tests.
*/
@Override
protected void setUp() throws Exception {
super.setUp();
mContext = this.getInstrumentation().getTargetContext();
}
/**
* Delete any dummy accounts we set up for this test
*/
@Override
protected void tearDown() throws Exception {
if (mAccount != null) {
Uri uri = ContentUris.withAppendedId(
EmailStore.Account.CONTENT_URI, mAccountId);
mContext.getContentResolver().delete(uri, null, null);
}
// must call last because it scrubs member variables
super.tearDown();
}
/**
* Test a "good" account name (enables the button)
*/
@ -73,10 +108,13 @@ public class AccountSetupNamesTests extends ActivityInstrumentationTestCase2<Acc
* Create an intent with the Account in it
*/
private Intent getTestIntent(String name) {
Account account = new Account(this.getInstrumentation().getTargetContext());
account.setName(name);
mAccount = new EmailStore.Account();
mAccount.setName(name);
mAccount.saveOrUpdate(mContext);
mAccountId = mAccount.mId;
Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account"
i.putExtra(EXTRA_ACCOUNT_ID, mAccountId);
return i;
}

View File

@ -16,9 +16,9 @@
package com.android.email.activity.setup;
import com.android.email.Account;
import com.android.email.R;
import com.android.email.mail.Store;
import com.android.email.provider.EmailStore;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
@ -33,6 +33,9 @@ import android.widget.SpinnerAdapter;
public class AccountSetupOptionsTests
extends ActivityInstrumentationTestCase2<AccountSetupOptions> {
// borrowed from AccountSetupOptions
private static final String EXTRA_ACCOUNT = "account";
private AccountSetupOptions mActivity;
private Spinner mCheckFrequencyView;
@ -49,7 +52,7 @@ public class AccountSetupOptionsTests
getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH);
boolean hasPush = frequencySpinnerHasValue(EmailStore.Account.CHECK_INTERVAL_PUSH);
assertFalse(hasPush);
}
@ -62,7 +65,7 @@ public class AccountSetupOptionsTests
getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH);
boolean hasPush = frequencySpinnerHasValue(EmailStore.Account.CHECK_INTERVAL_PUSH);
assertFalse(hasPush);
}
@ -81,7 +84,7 @@ public class AccountSetupOptionsTests
getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH);
boolean hasPush = frequencySpinnerHasValue(EmailStore.Account.CHECK_INTERVAL_PUSH);
assertTrue(hasPush);
}
@ -112,11 +115,11 @@ public class AccountSetupOptionsTests
* Create an intent with the Account in it
*/
private Intent getTestIntent(String name, String storeUri) {
Account account = new Account(this.getInstrumentation().getTargetContext());
EmailStore.Account account = new EmailStore.Account();
account.setName(name);
account.setStoreUri(storeUri);
account.setStoreUri(getInstrumentation().getTargetContext(), storeUri);
Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account"
i.putExtra(EXTRA_ACCOUNT, account);
return i;
}

View File

@ -16,8 +16,8 @@
package com.android.email.activity.setup;
import com.android.email.Account;
import com.android.email.R;
import com.android.email.provider.EmailStore;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
@ -138,8 +138,8 @@ public class AccountSetupOutgoingTests extends
* Create an intent with the Account in it
*/
private Intent getTestIntent(String senderUriString) {
Account account = new Account(this.getInstrumentation().getTargetContext());
account.setSenderUri(senderUriString);
EmailStore.Account account = new EmailStore.Account();
account.setSenderUri(this.getInstrumentation().getTargetContext(), senderUriString);
Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account"
return i;