Update old tests so they compile and run
diff --git a/tests/Android.mk b/tests/Android.mk
index fe73983..c6b3875 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -9,7 +9,7 @@
LOCAL_PACKAGE_NAME := CalendarProviderTests
-LOCAL_JAVA_LIBRARIES := ext android.test.runner
+LOCAL_JAVA_LIBRARIES := ext android.test.runner googlelogin-client
LOCAL_INSTRUMENTATION_FOR := CalendarProvider
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 44114f9..22cb75b 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -26,7 +26,7 @@
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<!--
- The test delcared in this instrumentation will be run along with tests declared by
+ The test declared in this instrumentation will be run along with tests declared by
all other applications via the command: "adb shell itr".
The "itr" command will find all tests declared by all applications. If you want to run just these
tests on their own then use the command:
diff --git a/tests/src/com/android/providers/calendar/CalendarSyncTestingBase.java b/tests/src/com/android/providers/calendar/CalendarSyncTestingBase.java
index bb2473f..fb54dee 100644
--- a/tests/src/com/android/providers/calendar/CalendarSyncTestingBase.java
+++ b/tests/src/com/android/providers/calendar/CalendarSyncTestingBase.java
@@ -16,6 +16,8 @@
package com.android.providers.calendar;
+import android.accounts.Account;
+import android.accounts.AccountManager;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
@@ -23,20 +25,21 @@
import android.database.Cursor;
import android.net.Uri;
import android.os.SystemClock;
-import android.pim.DateUtils;
-import android.pim.Time;
import android.provider.Calendar;
import android.test.SyncBaseInstrumentation;
+import android.text.format.DateUtils;
+import android.text.format.Time;
import android.util.Log;
+
import com.google.android.collect.Maps;
-import com.google.android.googlelogin.GoogleLoginServiceBlockingHelper;
-import com.google.android.googlelogin.GoogleLoginServiceNotFoundException;
+import com.google.android.googlelogin.GoogleLoginServiceConstants;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class CalendarSyncTestingBase extends SyncBaseInstrumentation {
+ protected AccountManager mAccountManager;
protected Context mTargetContext;
protected String mAccount;
protected ContentResolver mResolver;
@@ -70,6 +73,8 @@
protected void setUp() throws Exception {
super.setUp();
mTargetContext = getInstrumentation().getTargetContext();
+
+ mAccountManager = AccountManager.get(mTargetContext);
mAccount = getAccount();
mResolver = mTargetContext.getContentResolver();
}
@@ -144,7 +149,7 @@
if (event.mDescription != null) {
values.put(Calendar.Events.DESCRIPTION, event.mDescription);
}
-
+
Uri uri = ContentUris.withAppendedId(Calendar.Events.CONTENT_URI, eventId);
mResolver.update(uri, values, null, null);
syncCalendar();
@@ -195,7 +200,7 @@
protected int getEventsCount() {
Cursor cursor;
cursor = mResolver.query(mEventsUri, null, null, null, null);
- return cursor.getCount();
+ return cursor.getCount();
}
/**
@@ -206,7 +211,7 @@
Cursor calendarsCursor;
calendarsCursor = mResolver.query(Calendar.Calendars.CONTENT_URI, null, null, null, null);
calendarsCursor.moveToNext();
- return calendarsCursor.getInt(calendarsCursor.getColumnIndex("_id"));
+ return calendarsCursor.getInt(calendarsCursor.getColumnIndex("_id"));
}
/**
@@ -345,12 +350,14 @@
* @return
*/
protected String getAccount() {
- try {
- return GoogleLoginServiceBlockingHelper.getAccount(mTargetContext, false);
- } catch (GoogleLoginServiceNotFoundException e) {
- Log.e("SyncCalendarTest", "Could not find Google login service", e);
- return null;
- }
+ Account[] accounts = mAccountManager.getAccountsByType(
+ GoogleLoginServiceConstants.ACCOUNT_TYPE);
+
+ assertTrue("Didn't find any Google accounts", accounts.length > 0);
+
+ Account account = accounts[accounts.length - 1];
+ Log.v(TAG, "Found " + accounts.length + " accounts; using the last one, " + account.name);
+ return account.name;
}
/**
diff --git a/tests/src/com/android/providers/calendar/SyncCalendarTest.java b/tests/src/com/android/providers/calendar/SyncCalendarTest.java
index f2c8aee..121e342 100644
--- a/tests/src/com/android/providers/calendar/SyncCalendarTest.java
+++ b/tests/src/com/android/providers/calendar/SyncCalendarTest.java
@@ -18,7 +18,7 @@
import android.database.Cursor;
import android.net.Uri;
-import android.pim.Time;
+import android.text.format.Time;
/**
* Calendar Sync instrumentation tests. Testing creation of new events, deleting events,
@@ -85,7 +85,7 @@
long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
editEvent(eventId, event);
- cursor = mResolver.query(mEventsUri, null, null, null, null);
+ cursor = mResolver.query(mEventsUri, null, null, null, null);
assertTrue("Events count should remain same.", getEventsCount() == countBeforeNewEvent);
while (cursor.moveToNext()) {
@@ -123,7 +123,7 @@
while (cursor.moveToNext()){
if (cursor.getLong(cursor.getColumnIndex("_id")) == eventId) {
assertEquals(cursor.getLong(cursor.getColumnIndex("dtstart")), newDtStart);
- assertEquals(cursor.getLong(cursor.getColumnIndex("dtend")), newDtEnd);
+ assertEquals(cursor.getLong(cursor.getColumnIndex("dtend")), newDtEnd);
break;
}
}
@@ -159,3 +159,4 @@
cursor.close();
}
}
+