fix UnsupportedOperationException in tests

We're using the mock context to prevent modifying the real databases. However,
we need the real context to create intents. Use the real context in the few
places we must use it.

Change-Id: Icb8d289239218921c0b4b5c93ac7983830d90394
This commit is contained in:
Todd Kennedy 2011-02-23 14:51:45 -08:00
parent 8c89674b64
commit ffe6ef342a
2 changed files with 9 additions and 6 deletions

View File

@ -468,16 +468,18 @@ public class AttachmentDownloadService extends Service implements Runnable {
.toString(), req.priority != PRIORITY_FOREGROUND);
// Lazily initialize our (reusable) pending intent
if (mWatchdogPendingIntent == null) {
Intent alarmIntent = new Intent(mContext, Watchdog.class);
mWatchdogPendingIntent = PendingIntent.getBroadcast(mContext, 0, alarmIntent, 0);
mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
createWatchdogPendingIntent(mContext);
}
// Set the alarm
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + WATCHDOG_CHECK_INTERVAL, WATCHDOG_CHECK_INTERVAL,
mWatchdogPendingIntent);
}
/*package*/ void createWatchdogPendingIntent(Context context) {
Intent alarmIntent = new Intent(context, Watchdog.class);
mWatchdogPendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
mAlarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
}
private void cancelDownload(DownloadRequest req) {
mDownloadsInProgress.remove(req.attachmentId);
req.inProgress = false;

View File

@ -70,11 +70,11 @@ public class AttachmentDownloadServiceTests extends AccountTestCase {
// Use the NullEmailService so that the loadAttachment calls become no-ops
mService = new AttachmentDownloadService();
mService.mContext = mMockContext;
mService.addServiceIntentForTest(mAccountId, new Intent(mMockContext,
mService.addServiceIntentForTest(mAccountId, new Intent(mContext,
NullEmailService.class));
mAccountManagerStub = new AttachmentDownloadService.AccountManagerStub(null);
mService.mAccountManagerStub = mAccountManagerStub;
mService.mConnectivityManager = new MockConnectivityManager(getContext(), "mock");
mService.mConnectivityManager = new MockConnectivityManager(mContext, "mock");
mDownloadSet = mService.mDownloadSet;
mMockDirectory =
new MockDirectory(mService.mContext.getCacheDir().getAbsolutePath());
@ -119,6 +119,7 @@ public class AttachmentDownloadServiceTests extends AccountTestCase {
// Process the queue; attachment 1 should be marked "in progress", and should be in
// the in-progress map
mDownloadSet.createWatchdogPendingIntent(mContext);
mDownloadSet.processQueue();
DownloadRequest req = mDownloadSet.findDownloadRequest(att1.mId);
assertNotNull(req);