diff options
| author | Daisuke Miyakawa <dmiyakawa@google.com> | 2010-01-05 12:38:52 +0900 |
|---|---|---|
| committer | Daisuke Miyakawa <dmiyakawa@google.com> | 2010-01-05 13:44:51 +0900 |
| commit | 1301341f13fab2ced33a6f4dc0f0e8f609217105 (patch) | |
| tree | 89c1564ed7816074f26d6d6a44ec0e2ef5de025c /core/java | |
| parent | 1dabb95d280480c4c519b52ded8990d39c8b1614 (diff) | |
| download | frameworks_base-1301341f13fab2ced33a6f4dc0f0e8f609217105.zip frameworks_base-1301341f13fab2ced33a6f4dc0f0e8f609217105.tar.gz frameworks_base-1301341f13fab2ced33a6f4dc0f0e8f609217105.tar.bz2 | |
Fix test breakage in vCard exporter.
Due to the change Iae8dbac1, all tests for vCard exporeter has failed.
This change fixes the breakage by using a kind of dirty Dependency Injection.
Current test framework for vCard exporter strongly depends on the assumption that
ContentValues objects are able to be directly passed to objects which use
ContentResolver, while the change above disabled the feature by removing
queryEntities().
This change makes VCardComposer forcibly uses queryEntities() via Reflection.
I agree that this change is not so clean, but works fine for now.
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/pim/vcard/VCardComposer.java | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/core/java/android/pim/vcard/VCardComposer.java b/core/java/android/pim/vcard/VCardComposer.java index 4eaea6a..389c9f4 100644 --- a/core/java/android/pim/vcard/VCardComposer.java +++ b/core/java/android/pim/vcard/VCardComposer.java @@ -54,6 +54,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.lang.reflect.Method; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Arrays; @@ -197,7 +198,7 @@ public class VCardComposer { if (mIsDoCoMo) { try { // Create one empty entry. - mWriter.write(createOneEntryInternal("-1")); + mWriter.write(createOneEntryInternal("-1", null)); } catch (IOException e) { Log.e(LOG_TAG, "IOException occurred during exportOneContactData: " @@ -428,6 +429,14 @@ public class VCardComposer { } public boolean createOneEntry() { + return createOneEntry(null); + } + + /** + * @param getEntityIteratorMethod For Dependency Injection. + * @hide just for testing. + */ + public boolean createOneEntry(Method getEntityIteratorMethod) { if (mCursor == null || mCursor.isAfterLast()) { mErrorReason = FAILURE_REASON_NOT_INITIALIZED; return false; @@ -439,7 +448,8 @@ public class VCardComposer { vcard = createOneCallLogEntryInternal(); } else { if (mIdColumn >= 0) { - vcard = createOneEntryInternal(mCursor.getString(mIdColumn)); + vcard = createOneEntryInternal(mCursor.getString(mIdColumn), + getEntityIteratorMethod); } else { Log.e(LOG_TAG, "Incorrect mIdColumn: " + mIdColumn); return true; @@ -475,7 +485,8 @@ public class VCardComposer { return true; } - private String createOneEntryInternal(final String contactId) { + private String createOneEntryInternal(final String contactId, + Method getEntityIteratorMethod) { final Map<String, List<ContentValues>> contentValuesListMap = new HashMap<String, List<ContentValues>>(); // The resolver may return the entity iterator with no data. It is possiible. @@ -484,13 +495,34 @@ public class VCardComposer { boolean dataExists = false; EntityIterator entityIterator = null; try { - final Uri uri = RawContacts.CONTENT_URI.buildUpon() - .appendEncodedPath(contactId) - .appendEncodedPath(RawContacts.Entity.CONTENT_DIRECTORY) - .appendQueryParameter(Data.FOR_EXPORT_ONLY, "1") - .build(); - entityIterator = RawContacts.newEntityIterator(mContentResolver.query( - uri, null, null, null, null)); + + if (getEntityIteratorMethod != null) { + try { + final Uri uri = RawContacts.CONTENT_URI.buildUpon() + .appendQueryParameter(Data.FOR_EXPORT_ONLY, "1") + .build(); + final String selection = Data.CONTACT_ID + "=?"; + final String[] selectionArgs = new String[] {contactId}; + entityIterator = (EntityIterator)getEntityIteratorMethod.invoke(null, + mContentResolver, uri, selection, selectionArgs, null); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + final Uri uri = RawContacts.CONTENT_URI.buildUpon() + .appendEncodedPath(contactId) + .appendEncodedPath(RawContacts.Entity.CONTENT_DIRECTORY) + .appendQueryParameter(Data.FOR_EXPORT_ONLY, "1") + .build(); + entityIterator = RawContacts.newEntityIterator(mContentResolver.query( + uri, null, null, null, null)); + } + + if (entityIterator == null) { + Log.e(LOG_TAG, "EntityIterator is null"); + return ""; + } + dataExists = entityIterator.hasNext(); while (entityIterator.hasNext()) { Entity entity = entityIterator.next(); |
