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:
parent
8c89674b64
commit
ffe6ef342a
@ -468,16 +468,18 @@ public class AttachmentDownloadService extends Service implements Runnable {
|
|||||||
.toString(), req.priority != PRIORITY_FOREGROUND);
|
.toString(), req.priority != PRIORITY_FOREGROUND);
|
||||||
// Lazily initialize our (reusable) pending intent
|
// Lazily initialize our (reusable) pending intent
|
||||||
if (mWatchdogPendingIntent == null) {
|
if (mWatchdogPendingIntent == null) {
|
||||||
Intent alarmIntent = new Intent(mContext, Watchdog.class);
|
createWatchdogPendingIntent(mContext);
|
||||||
mWatchdogPendingIntent = PendingIntent.getBroadcast(mContext, 0, alarmIntent, 0);
|
|
||||||
mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
|
|
||||||
}
|
}
|
||||||
// Set the alarm
|
// Set the alarm
|
||||||
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
|
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
|
||||||
System.currentTimeMillis() + WATCHDOG_CHECK_INTERVAL, WATCHDOG_CHECK_INTERVAL,
|
System.currentTimeMillis() + WATCHDOG_CHECK_INTERVAL, WATCHDOG_CHECK_INTERVAL,
|
||||||
mWatchdogPendingIntent);
|
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) {
|
private void cancelDownload(DownloadRequest req) {
|
||||||
mDownloadsInProgress.remove(req.attachmentId);
|
mDownloadsInProgress.remove(req.attachmentId);
|
||||||
req.inProgress = false;
|
req.inProgress = false;
|
||||||
|
@ -70,11 +70,11 @@ public class AttachmentDownloadServiceTests extends AccountTestCase {
|
|||||||
// Use the NullEmailService so that the loadAttachment calls become no-ops
|
// Use the NullEmailService so that the loadAttachment calls become no-ops
|
||||||
mService = new AttachmentDownloadService();
|
mService = new AttachmentDownloadService();
|
||||||
mService.mContext = mMockContext;
|
mService.mContext = mMockContext;
|
||||||
mService.addServiceIntentForTest(mAccountId, new Intent(mMockContext,
|
mService.addServiceIntentForTest(mAccountId, new Intent(mContext,
|
||||||
NullEmailService.class));
|
NullEmailService.class));
|
||||||
mAccountManagerStub = new AttachmentDownloadService.AccountManagerStub(null);
|
mAccountManagerStub = new AttachmentDownloadService.AccountManagerStub(null);
|
||||||
mService.mAccountManagerStub = mAccountManagerStub;
|
mService.mAccountManagerStub = mAccountManagerStub;
|
||||||
mService.mConnectivityManager = new MockConnectivityManager(getContext(), "mock");
|
mService.mConnectivityManager = new MockConnectivityManager(mContext, "mock");
|
||||||
mDownloadSet = mService.mDownloadSet;
|
mDownloadSet = mService.mDownloadSet;
|
||||||
mMockDirectory =
|
mMockDirectory =
|
||||||
new MockDirectory(mService.mContext.getCacheDir().getAbsolutePath());
|
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
|
// Process the queue; attachment 1 should be marked "in progress", and should be in
|
||||||
// the in-progress map
|
// the in-progress map
|
||||||
|
mDownloadSet.createWatchdogPendingIntent(mContext);
|
||||||
mDownloadSet.processQueue();
|
mDownloadSet.processQueue();
|
||||||
DownloadRequest req = mDownloadSet.findDownloadRequest(att1.mId);
|
DownloadRequest req = mDownloadSet.findDownloadRequest(att1.mId);
|
||||||
assertNotNull(req);
|
assertNotNull(req);
|
||||||
|
Loading…
Reference in New Issue
Block a user