From 411334d4e5c8019e646287c102faec7f18b8a13a Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Fri, 11 Sep 2009 23:00:39 -0700 Subject: [PATCH] Fix broken test cases Change-Id: Ib2d019662d358a20b4d62992529bfdf398e4661b --- .../mail/internet/EmailHtmlUtilTest.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/src/com/android/email/mail/internet/EmailHtmlUtilTest.java b/tests/src/com/android/email/mail/internet/EmailHtmlUtilTest.java index ffa6a3344..2815d82b0 100755 --- a/tests/src/com/android/email/mail/internet/EmailHtmlUtilTest.java +++ b/tests/src/com/android/email/mail/internet/EmailHtmlUtilTest.java @@ -26,6 +26,8 @@ import com.android.email.mail.store.LocalStore; import com.android.email.provider.EmailContent; import com.android.email.provider.EmailContent.Account; +import android.content.ContentUris; +import android.content.Context; import android.net.Uri; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; @@ -41,6 +43,7 @@ import java.io.IOException; @MediumTest public class EmailHtmlUtilTest extends AndroidTestCase { private EmailContent.Account mAccount; + private long mCreatedAccountId = -1; private static final String textTags = "Plain &"; private static final String textSpaces = "3 spaces end."; @@ -50,13 +53,35 @@ public class EmailHtmlUtilTest extends AndroidTestCase { protected void setUp() throws Exception { super.setUp(); // Force assignment of a default account, and retrieve it - long accountId = Account.getDefaultAccountId(getContext()); - mAccount = Account.restoreAccountWithId(getContext(), accountId); + Context context = getContext(); + + // Force assignment of a default account + long accountId = Account.getDefaultAccountId(context); + if (accountId == -1) { + Account account = new Account(); + account.mSenderName = "Bob Sender"; + account.mEmailAddress = "bob@sender.com"; + account.save(context); + accountId = account.mId; + mCreatedAccountId = accountId; + } + Account.restoreAccountWithId(context, accountId); // This is needed for mime image bodypart. BinaryTempFileBody.setTempDirectory(getContext().getCacheDir()); } + @Override + protected void tearDown() throws Exception { + super.tearDown(); + Context context = getContext(); + // If we created an account, delete it here + if (mCreatedAccountId > -1) { + context.getContentResolver().delete( + ContentUris.withAppendedId(Account.CONTENT_URI, mCreatedAccountId), null, null); + } + } + /** * Tests for resolving inline image src cid: reference to content uri. */