From ffe6ef342a6d9ea958aaee11b57db54e52252dde Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 23 Feb 2011 14:51:45 -0800 Subject: [PATCH] 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 --- .../email/service/AttachmentDownloadService.java | 10 ++++++---- .../email/service/AttachmentDownloadServiceTests.java | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/com/android/email/service/AttachmentDownloadService.java b/src/com/android/email/service/AttachmentDownloadService.java index 38a7f224c..550931746 100644 --- a/src/com/android/email/service/AttachmentDownloadService.java +++ b/src/com/android/email/service/AttachmentDownloadService.java @@ -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; diff --git a/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java b/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java index 5ab6ca5e5..cd9766de4 100644 --- a/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java +++ b/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java @@ -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);