Merge "Fix unit tests"
This commit is contained in:
commit
9afd6bc59f
@ -41,6 +41,10 @@ import android.util.Log;
|
|||||||
public class MailboxFinder {
|
public class MailboxFinder {
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final Controller mController;
|
private final Controller mController;
|
||||||
|
|
||||||
|
// Actual Controller.Result that will wrapped by ControllerResultUiThreadWrapper.
|
||||||
|
// Unit tests directly use it to avoid asynchronicity caused by ControllerResultUiThreadWrapper.
|
||||||
|
private final ControllerResults mInnerControllerResults;
|
||||||
private Controller.Result mControllerResults; // Not final, we null it out when done.
|
private Controller.Result mControllerResults; // Not final, we null it out when done.
|
||||||
|
|
||||||
private final long mAccountId;
|
private final long mAccountId;
|
||||||
@ -75,8 +79,9 @@ public class MailboxFinder {
|
|||||||
mAccountId = accountId;
|
mAccountId = accountId;
|
||||||
mMailboxType = mailboxType;
|
mMailboxType = mailboxType;
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
|
mInnerControllerResults = new ControllerResults();
|
||||||
mControllerResults = new ControllerResultUiThreadWrapper<ControllerResults>(
|
mControllerResults = new ControllerResultUiThreadWrapper<ControllerResults>(
|
||||||
new Handler(), new ControllerResults());
|
new Handler(), mInnerControllerResults);
|
||||||
mController.addResultCallback(mControllerResults);
|
mController.addResultCallback(mControllerResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,6 +260,6 @@ public class MailboxFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* package */ Controller.Result getControllerResultsForTest() {
|
/* package */ Controller.Result getControllerResultsForTest() {
|
||||||
return mControllerResults;
|
return mInnerControllerResults;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.android.email;
|
package com.android.email;
|
||||||
|
|
||||||
import com.android.email.provider.AttachmentProvider;
|
import com.android.email.provider.AttachmentProvider;
|
||||||
|
import com.android.email.provider.ContentCache;
|
||||||
import com.android.email.provider.EmailContent;
|
import com.android.email.provider.EmailContent;
|
||||||
import com.android.email.provider.EmailProvider;
|
import com.android.email.provider.EmailProvider;
|
||||||
|
|
||||||
@ -202,7 +203,10 @@ public final class DBTestHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Based on ProviderTestCase2.setUp().
|
/**
|
||||||
|
* Return {@link Context} with isolated EmailProvider and AttachmentProvider. This method
|
||||||
|
* also invalidates the DB cache.
|
||||||
|
*/
|
||||||
public static Context getProviderContext(Context context) throws Exception {
|
public static Context getProviderContext(Context context) throws Exception {
|
||||||
MockContentResolver resolver = new MockContentResolver();
|
MockContentResolver resolver = new MockContentResolver();
|
||||||
final String filenamePrefix = "test.";
|
final String filenamePrefix = "test.";
|
||||||
@ -222,6 +226,9 @@ public final class DBTestHelper {
|
|||||||
final AttachmentProvider ap = new AttachmentProvider();
|
final AttachmentProvider ap = new AttachmentProvider();
|
||||||
ap.attachInfo(providerContext, null);
|
ap.attachInfo(providerContext, null);
|
||||||
resolver.addProvider(AttachmentProvider.AUTHORITY, ap);
|
resolver.addProvider(AttachmentProvider.AUTHORITY, ap);
|
||||||
|
|
||||||
|
ContentCache.invalidateAllCachesForTest();
|
||||||
|
|
||||||
return providerContext;
|
return providerContext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,6 @@ package com.android.email.activity;
|
|||||||
|
|
||||||
import com.android.email.DBTestHelper;
|
import com.android.email.DBTestHelper;
|
||||||
import com.android.email.TestUtils;
|
import com.android.email.TestUtils;
|
||||||
import com.android.email.provider.EmailContent.Account;
|
|
||||||
import com.android.email.provider.EmailContent.Mailbox;
|
|
||||||
import com.android.email.provider.EmailContent.Message;
|
|
||||||
import com.android.email.provider.ProviderTestUtils;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -80,33 +76,35 @@ public class MessageViewTest extends ActivityInstrumentationTestCase2<MessageVie
|
|||||||
}, TIMEOUT);
|
}, TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// This test doesn't work, because it sets up messages in an separated context, but
|
||||||
* Set up account/mailbox/message, and open the activity.
|
// the main activity looks at the actual context and fails to find the message.
|
||||||
*
|
// /**
|
||||||
* Expected: Message opens.
|
// * Set up account/mailbox/message, and open the activity.
|
||||||
*/
|
// *
|
||||||
public void testOpenMessage() throws Exception {
|
// * Expected: Message opens.
|
||||||
final Context c = mProviderContext;
|
// */
|
||||||
final Account acct1 = ProviderTestUtils.setupAccount("test1", true, c);
|
// public void testOpenMessage() throws Exception {
|
||||||
final Account acct2 = ProviderTestUtils.setupAccount("test2", true, c);
|
// final Context c = mProviderContext;
|
||||||
final Mailbox acct2inbox = ProviderTestUtils.setupMailbox("inbox", acct2.mId, true, c);
|
// final Account acct1 = ProviderTestUtils.setupAccount("test1", true, c);
|
||||||
final Message msg1 = ProviderTestUtils.setupMessage("message1", acct2.mId, acct2inbox.mId,
|
// final Account acct2 = ProviderTestUtils.setupAccount("test2", true, c);
|
||||||
true, true, c);
|
// final Mailbox acct2inbox = ProviderTestUtils.setupMailbox("inbox", acct2.mId, true, c);
|
||||||
final Message msg2 = ProviderTestUtils.setupMessage("message2", acct2.mId, acct2inbox.mId,
|
// final Message msg1 = ProviderTestUtils.setupMessage("message1", acct2.mId, acct2inbox.mId,
|
||||||
true, true, c);
|
// true, true, c);
|
||||||
|
// final Message msg2 = ProviderTestUtils.setupMessage("message2", acct2.mId, acct2inbox.mId,
|
||||||
setUpIntent(msg2.mId, msg2.mMailboxKey, false);
|
// true, true, c);
|
||||||
|
//
|
||||||
final MessageView activity = getActivity();
|
// setUpIntent(msg2.mId, msg2.mMailboxKey, false);
|
||||||
|
//
|
||||||
TestUtils.waitUntil(new TestUtils.Condition() {
|
// final MessageView activity = getActivity();
|
||||||
@Override
|
//
|
||||||
public boolean isMet() {
|
// TestUtils.waitUntil(new TestUtils.Condition() {
|
||||||
MessageViewFragment f = activity.getFragment();
|
// @Override
|
||||||
return f != null && f.isMessageLoadedForTest();
|
// public boolean isMet() {
|
||||||
}
|
// MessageViewFragment f = activity.getFragment();
|
||||||
}, TIMEOUT);
|
// return f != null && f.isMessageLoadedForTest();
|
||||||
|
// }
|
||||||
// TODO Check UI elements, once our UI is settled.
|
// }, TIMEOUT);
|
||||||
}
|
//
|
||||||
|
// // TODO Check UI elements, once our UI is settled.
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.android.email.data;
|
package com.android.email.data;
|
||||||
|
|
||||||
import com.android.email.DBTestHelper;
|
import com.android.email.DBTestHelper;
|
||||||
|
import com.android.email.provider.ContentCache;
|
||||||
import com.android.email.provider.EmailContent.Account;
|
import com.android.email.provider.EmailContent.Account;
|
||||||
import com.android.email.provider.EmailContent.Mailbox;
|
import com.android.email.provider.EmailContent.Mailbox;
|
||||||
import com.android.email.provider.ProviderTestUtils;
|
import com.android.email.provider.ProviderTestUtils;
|
||||||
@ -36,8 +37,9 @@ public class MailboxAccountLoaderTestCase extends LoaderTestCase {
|
|||||||
private long createAccount(boolean isEas) {
|
private long createAccount(boolean isEas) {
|
||||||
Account acct = ProviderTestUtils.setupAccount("acct1", false, mProviderContext);
|
Account acct = ProviderTestUtils.setupAccount("acct1", false, mProviderContext);
|
||||||
String proto = isEas ? "eas" : "non-eas";
|
String proto = isEas ? "eas" : "non-eas";
|
||||||
acct.mHostAuthRecv = ProviderTestUtils.setupHostAuth(proto, "hostauth", -1, false,
|
acct.mHostAuthRecv = ProviderTestUtils.setupHostAuth(proto, "hostauth", -1, true,
|
||||||
mProviderContext);
|
mProviderContext);
|
||||||
|
acct.mHostAuthKeyRecv = acct.mHostAuthRecv.mId;
|
||||||
acct.save(mProviderContext);
|
acct.save(mProviderContext);
|
||||||
return acct.mId;
|
return acct.mId;
|
||||||
}
|
}
|
||||||
@ -66,7 +68,7 @@ public class MailboxAccountLoaderTestCase extends LoaderTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load - isEas = true
|
* Load -- isEas = true
|
||||||
*/
|
*/
|
||||||
public void testLoadEas() {
|
public void testLoadEas() {
|
||||||
final long accountId = createAccount(true);
|
final long accountId = createAccount(true);
|
||||||
|
@ -16,18 +16,19 @@
|
|||||||
|
|
||||||
package com.android.email.mail.transport;
|
package com.android.email.mail.transport;
|
||||||
|
|
||||||
|
import com.android.email.DBTestHelper;
|
||||||
import com.android.email.mail.Address;
|
import com.android.email.mail.Address;
|
||||||
import com.android.email.mail.MessagingException;
|
import com.android.email.mail.MessagingException;
|
||||||
import com.android.email.mail.Transport;
|
import com.android.email.mail.Transport;
|
||||||
import com.android.email.provider.EmailProvider;
|
|
||||||
import com.android.email.provider.EmailContent.Attachment;
|
import com.android.email.provider.EmailContent.Attachment;
|
||||||
import com.android.email.provider.EmailContent.Body;
|
import com.android.email.provider.EmailContent.Body;
|
||||||
import com.android.email.provider.EmailContent.Message;
|
import com.android.email.provider.EmailContent.Message;
|
||||||
|
import com.android.email.provider.EmailProvider;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.test.ProviderTestCase2;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -48,7 +49,7 @@ import java.util.regex.Pattern;
|
|||||||
* runtest -c com.android.email.mail.transport.SmtpSenderUnitTests email
|
* runtest -c com.android.email.mail.transport.SmtpSenderUnitTests email
|
||||||
*/
|
*/
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
public class SmtpSenderUnitTests extends AndroidTestCase {
|
||||||
|
|
||||||
EmailProvider mProvider;
|
EmailProvider mProvider;
|
||||||
Context mProviderContext;
|
Context mProviderContext;
|
||||||
@ -62,19 +63,16 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
private final static String TEST_STRING = "Hello, world";
|
private final static String TEST_STRING = "Hello, world";
|
||||||
private final static String TEST_STRING_BASE64 = "SGVsbG8sIHdvcmxk";
|
private final static String TEST_STRING_BASE64 = "SGVsbG8sIHdvcmxk";
|
||||||
|
|
||||||
public SmtpSenderUnitTests() {
|
|
||||||
super(EmailProvider.class, EmailProvider.EMAIL_AUTHORITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup code. We generate a lightweight SmtpSender for testing.
|
* Setup code. We generate a lightweight SmtpSender for testing.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mProviderContext = getMockContext();
|
mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
|
||||||
|
getContext());
|
||||||
mContext = getContext();
|
mContext = getContext();
|
||||||
|
|
||||||
// These are needed so we can get at the inner classes
|
// These are needed so we can get at the inner classes
|
||||||
mSender = (SmtpSender) SmtpSender.newInstance(mProviderContext,
|
mSender = (SmtpSender) SmtpSender.newInstance(mProviderContext,
|
||||||
"smtp://user:password@server:999");
|
"smtp://user:password@server:999");
|
||||||
@ -84,14 +82,14 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
* Confirms simple non-SSL non-TLS login
|
* Confirms simple non-SSL non-TLS login
|
||||||
*/
|
*/
|
||||||
public void testSimpleLogin() throws Exception {
|
public void testSimpleLogin() throws Exception {
|
||||||
|
|
||||||
MockTransport mockTransport = openAndInjectMockTransport();
|
MockTransport mockTransport = openAndInjectMockTransport();
|
||||||
|
|
||||||
// try to open it
|
// try to open it
|
||||||
setupOpen(mockTransport, null);
|
setupOpen(mockTransport, null);
|
||||||
mSender.open();
|
mSender.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Test with SSL negotiation (faked)
|
* TODO: Test with SSL negotiation (faked)
|
||||||
* TODO: Test with SSL required but not supported
|
* TODO: Test with SSL required but not supported
|
||||||
@ -100,7 +98,7 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
* TODO: Test other capabilities.
|
* TODO: Test other capabilities.
|
||||||
* TODO: Test AUTH LOGIN
|
* TODO: Test AUTH LOGIN
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test: Open and send a single message (sunny day)
|
* Test: Open and send a single message (sunny day)
|
||||||
*/
|
*/
|
||||||
@ -285,7 +283,7 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
* Prepare to receive a simple message (see setupSimpleMessage)
|
* Prepare to receive a simple message (see setupSimpleMessage)
|
||||||
*/
|
*/
|
||||||
private void expectSimpleMessage(MockTransport mockTransport) {
|
private void expectSimpleMessage(MockTransport mockTransport) {
|
||||||
mockTransport.expect("MAIL FROM: <Jones@Registry.Org>",
|
mockTransport.expect("MAIL FROM: <Jones@Registry.Org>",
|
||||||
"250 2.1.0 <Jones@Registry.Org> sender ok");
|
"250 2.1.0 <Jones@Registry.Org> sender ok");
|
||||||
mockTransport.expect("RCPT TO: <Smith@Registry.Org>",
|
mockTransport.expect("RCPT TO: <Smith@Registry.Org>",
|
||||||
"250 2.1.5 <Smith@Registry.Org> recipient ok");
|
"250 2.1.5 <Smith@Registry.Org> recipient ok");
|
||||||
@ -347,14 +345,14 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
*/
|
*/
|
||||||
public void testEmptyLineResponse() throws Exception {
|
public void testEmptyLineResponse() throws Exception {
|
||||||
MockTransport mockTransport = openAndInjectMockTransport();
|
MockTransport mockTransport = openAndInjectMockTransport();
|
||||||
|
|
||||||
// Since SmtpSender.sendMessage() does a close then open, we need to preset for the open
|
// Since SmtpSender.sendMessage() does a close then open, we need to preset for the open
|
||||||
mockTransport.expectClose();
|
mockTransport.expectClose();
|
||||||
|
|
||||||
// Load up just the bare minimum to expose the error
|
// Load up just the bare minimum to expose the error
|
||||||
mockTransport.expect(null, "220 MockTransport 2000 Ready To Assist You Peewee");
|
mockTransport.expect(null, "220 MockTransport 2000 Ready To Assist You Peewee");
|
||||||
mockTransport.expect("EHLO " + Pattern.quote(LOCAL_ADDRESS), "");
|
mockTransport.expect("EHLO " + Pattern.quote(LOCAL_ADDRESS), "");
|
||||||
|
|
||||||
// Now trigger the transmission
|
// Now trigger the transmission
|
||||||
// Note, a null message is sufficient here, as we won't even get past open()
|
// Note, a null message is sufficient here, as we won't even get past open()
|
||||||
try {
|
try {
|
||||||
@ -365,7 +363,7 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
// TODO maybe expect a particular exception?
|
// TODO maybe expect a particular exception?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up a basic MockTransport. open it, and inject it into mStore
|
* Set up a basic MockTransport. open it, and inject it into mStore
|
||||||
*/
|
*/
|
||||||
@ -377,10 +375,10 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
mockTransport.setMockLocalAddress(InetAddress.getByName(LOCAL_ADDRESS));
|
mockTransport.setMockLocalAddress(InetAddress.getByName(LOCAL_ADDRESS));
|
||||||
return mockTransport;
|
return mockTransport;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper which stuffs the mock with enough strings to satisfy a call to SmtpSender.open()
|
* Helper which stuffs the mock with enough strings to satisfy a call to SmtpSender.open()
|
||||||
*
|
*
|
||||||
* @param mockTransport the mock transport we're using
|
* @param mockTransport the mock transport we're using
|
||||||
* @param capabilities if non-null, comma-separated list of capabilities
|
* @param capabilities if non-null, comma-separated list of capabilities
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user