summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorErik <roboerik@android.com>2010-06-22 13:40:18 -0700
committerErik <roboerik@android.com>2010-06-23 10:33:55 -0700
commit37960c091b5912dd45beb561a85a9064ea42e616 (patch)
treef22ff7508a17e622f09d58483544c760383f35bd /tests/src
parent7e4b2c1ddb6680d5b413c5f25592b0128e5f14dc (diff)
downloadandroid_packages_apps_Calendar-37960c091b5912dd45beb561a85a9064ea42e616.tar.gz
android_packages_apps_Calendar-37960c091b5912dd45beb561a85a9064ea42e616.tar.bz2
android_packages_apps_Calendar-37960c091b5912dd45beb561a85a9064ea42e616.zip
Switches EditEventHelper to use AsyncQueryService
This change backgrounds the batch save used in EditEventHelper and the queries in the EditEventActivity. It also creates an abstract CalendarActivity with a call for lazy creation/access of an AsyncQueryService object from the activity. Also changes setting duration to prefer using the start and end to a pre-existing change to fix b/2789706. Change-Id: If7fe94086f2a5dcfa34dd208358fada370d0bfde
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/calendar/EditEventHelperTest.java168
1 files changed, 81 insertions, 87 deletions
diff --git a/tests/src/com/android/calendar/EditEventHelperTest.java b/tests/src/com/android/calendar/EditEventHelperTest.java
index f1ab78c2..0d0c2f9e 100644
--- a/tests/src/com/android/calendar/EditEventHelperTest.java
+++ b/tests/src/com/android/calendar/EditEventHelperTest.java
@@ -19,9 +19,7 @@ package com.android.calendar;
import android.content.ContentProvider;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
-import android.content.ContentResolver;
import android.content.ContentValues;
-import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.MatrixCursor;
@@ -30,8 +28,6 @@ import android.provider.Calendar.Attendees;
import android.provider.Calendar.Events;
import android.provider.Calendar.Reminders;
import android.test.AndroidTestCase;
-import android.test.mock.MockContentResolver;
-import android.test.mock.MockContext;
import android.test.mock.MockResources;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.Smoke;
@@ -104,7 +100,7 @@ public class EditEventHelperTest extends AndroidTestCase {
private ContentValues mExpectedValues;
private EditEventHelper mHelper;
- private Context mContext;
+ private AbstractCalendarActivity mActivity;
private int mCurrentSaveTest = 0;
@Override
@@ -120,50 +116,48 @@ public class EditEventHelperTest extends AndroidTestCase {
TEST_END2 = time.normalize(true);
}
- private Context buildTestContext() {
- MockContext context = new MockContext() {
- MockContentResolver mResolver;
-
- @Override
- public ContentResolver getContentResolver() {
- if (mResolver == null) {
- ContentProvider provider = new TestProvider();
- mResolver = new MockContentResolver() {
- @Override
- public ContentProviderResult[] applyBatch(String authority,
- ArrayList<ContentProviderOperation> operations) {
- return mockApplyBatch(authority, operations);
- }
- };
- mResolver.addProvider(AUTHORITY, provider);
- }
- return mResolver;
- }
-
- @Override
- public Resources getResources() {
- Resources res = new MockResources() {
+ private class MockAbsCalendarActivity extends AbstractCalendarActivity {
+ @Override
+ public AsyncQueryService getAsyncQueryService() {
+ if (mService == null) {
+ mService = new AsyncQueryService(this) {
@Override
- // The actual selects singular vs plural as well and in the given language
- public String getQuantityString(int id, int quantity) {
- if (id == R.plurals.Nmins) {
- return quantity + " mins";
- }
- if (id == R.plurals.Nminutes) {
- return quantity + " minutes";
- }
- if (id == R.plurals.Nhours) {
- return quantity + " hours";
- }
- if (id == R.plurals.Ndays) {
- return quantity + " days";
- }
- return id + " " + quantity;
+ public void startBatch(int token, Object cookie, String authority,
+ ArrayList<ContentProviderOperation> cpo, long delayMillis) {
+ mockApplyBatch(authority, cpo);
}
};
- return res;
}
- };
+ return mService;
+ }
+
+ @Override
+ public Resources getResources() {
+ Resources res = new MockResources() {
+ @Override
+ // The actual selects singular vs plural as well and in the given language
+ public String getQuantityString(int id, int quantity) {
+ if (id == R.plurals.Nmins) {
+ return quantity + " mins";
+ }
+ if (id == R.plurals.Nminutes) {
+ return quantity + " minutes";
+ }
+ if (id == R.plurals.Nhours) {
+ return quantity + " hours";
+ }
+ if (id == R.plurals.Ndays) {
+ return quantity + " days";
+ }
+ return id + " " + quantity;
+ }
+ };
+ return res;
+ }
+ }
+
+ private AbstractCalendarActivity buildTestContext() {
+ MockAbsCalendarActivity context = new MockAbsCalendarActivity();
return context;
}
@@ -329,8 +323,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@Smoke
@SmallTest
public void testSaveEventFailures() {
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -356,8 +350,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@SmallTest
public void testSaveEventNewEvent() {
// Creates a model of a new event for saving
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel1.mAttendees = TEST_ADDRESSES2;
@@ -393,8 +387,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@SmallTest
public void testSaveEventModifyRecurring() {
// Creates an original and an updated recurring event model
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -442,8 +436,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@SmallTest
public void testSaveEventRecurringToNonRecurring() {
// Creates an original and an updated recurring event model
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -498,8 +492,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@SmallTest
public void testSaveEventNonRecurringToRecurring() {
// Creates an original non-recurring and an updated recurring event model
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -532,8 +526,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@SmallTest
public void testSaveEventUpdateNonRecurring() {
// Creates an original non-recurring and an updated recurring event model
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -583,8 +577,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@SmallTest
public void testSaveEventModifySingleInstance() {
// Creates an original non-recurring and an updated recurring event model
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -645,8 +639,8 @@ public class EditEventHelperTest extends AndroidTestCase {
public void testSaveEventModifyAllFollowingWithNonRecurring() {
// Creates an original and an updated recurring event model. The update starts on the 2nd
// instance of the original.
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -702,8 +696,8 @@ public class EditEventHelperTest extends AndroidTestCase {
public void testSaveEventModifyAllFollowingFirstWithNonRecurring() {
// Creates an original recurring and an updated non-recurring event model for the first
// instance. This should replace the original event with a non-recurring event.
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -761,8 +755,8 @@ public class EditEventHelperTest extends AndroidTestCase {
public void testSaveEventModifyAllFollowingFirstWithRecurring() {
// Creates an original recurring and an updated recurring event model for the first instance
// This should replace the original event with a new recurrence
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -820,8 +814,8 @@ public class EditEventHelperTest extends AndroidTestCase {
// Creates an original recurring and an updated recurring event model
// for the second instance. This should end the original recurrence and add a new
// recurrence.
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -876,8 +870,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@Smoke
@SmallTest
public void testGetAddressesFromList() {
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
LinkedHashSet<Rfc822Token> expected = new LinkedHashSet<Rfc822Token>();
expected.add(new Rfc822Token(null, "ad1@email.com", ""));
@@ -891,8 +885,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@Smoke
@SmallTest
public void testCheckTimeDependentFieldsNoChanges() {
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -934,8 +928,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@Smoke
@SmallTest
public void testCheckTimeDependentFieldsChanges() {
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mModel1 = buildTestModel();
mModel2 = buildTestModel();
@@ -972,8 +966,8 @@ public class EditEventHelperTest extends AndroidTestCase {
mModel1 = buildTestModel();
mModel1.mUri = Uri.parse(AUTHORITY_URI + TEST_EVENT_ID);
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mValues.put(Events.RRULE, "FREQ=DAILY;UNTIL=20160903;WKST=SU"); // yyyymmddThhmmssZ
mValues.put(Events.DTSTART, TEST_START);
@@ -1001,8 +995,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@Smoke
@SmallTest
public void testConstructReminderLabel() {
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
String label = mHelper.constructReminderLabel(35, true);
assertEquals(label, "35 mins");
@@ -1049,8 +1043,8 @@ public class EditEventHelperTest extends AndroidTestCase {
ArrayList<Integer> originalMinutes = new ArrayList<Integer>();
boolean forceSave = true;
boolean result;
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
assertNotNull(mHelper);
// First test forcing a delete with no reminders.
@@ -1103,8 +1097,8 @@ public class EditEventHelperTest extends AndroidTestCase {
ArrayList<Integer> originalMinutes = new ArrayList<Integer>();
boolean forceSave = true;
boolean result;
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
assertNotNull(mHelper);
// First test forcing a delete with no reminders.
@@ -1171,8 +1165,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@Smoke
@SmallTest
public void testAddRecurrenceRule() {
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mValues = new ContentValues();
mExpectedValues = new ContentValues();
mModel1 = new CalendarEventModel();
@@ -1252,8 +1246,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@Smoke
@SmallTest
public void testSetModelFromCursor() {
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
MatrixCursor c = new MatrixCursor(EditEventHelper.EVENT_PROJECTION);
c.addRow(TEST_CURSOR_DATA);
@@ -1302,8 +1296,8 @@ public class EditEventHelperTest extends AndroidTestCase {
@Smoke
@SmallTest
public void testGetContentValuesFromModel() {
- mContext = buildTestContext();
- mHelper = new EditEventHelper(mContext, null);
+ mActivity = buildTestContext();
+ mHelper = new EditEventHelper(mActivity, null);
mExpectedValues = buildTestValues();
mModel1 = buildTestModel();