diff options
author | Marcus Hagerott <mhagerott@google.com> | 2021-02-09 00:07:34 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-02-09 00:07:34 +0000 |
commit | e176768ae6b7606d2ec24580e2d26b7acbcbd269 (patch) | |
tree | 5b2da0523ba433dec01f9df679f7673fe721a63e /tests | |
parent | fefa2ff7d9435fe40c73a4613dd0c8becc1e772d (diff) | |
parent | 4d36a0106c6378c1564bf3026dfd0377902a632c (diff) | |
download | Contacts-e176768ae6b7606d2ec24580e2d26b7acbcbd269.tar.gz |
Merge "Fix test failures due to bad cast"android-s-preview-1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/contacts/model/RawContactDeltaListTests.java | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/tests/src/com/android/contacts/model/RawContactDeltaListTests.java b/tests/src/com/android/contacts/model/RawContactDeltaListTests.java index 03e1d4f8f..d9ff184c0 100644 --- a/tests/src/com/android/contacts/model/RawContactDeltaListTests.java +++ b/tests/src/com/android/contacts/model/RawContactDeltaListTests.java @@ -17,6 +17,8 @@ package com.android.contacts.model; import android.content.ContentProviderOperation; +import android.content.ContentProviderResult; +import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.net.Uri; @@ -56,6 +58,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { public static final long CONTACT_BOB = 10; public static final long CONTACT_MARY = 11; + public static final long INSERTED_CONTACT_ID = 3; + public static final long PHONE_RED = 20; public static final long PHONE_GREEN = 21; public static final long PHONE_BLUE = 22; @@ -182,6 +186,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { static void assertDiffPattern(ArrayList<CPOWrapper> diff, CPOWrapper... pattern) { assertEquals("Unexpected operations", pattern.length, diff.size()); + + ContentProviderResult[] fakeBackReferences = new ContentProviderResult[diff.size()]; for (int i = 0; i < pattern.length; i++) { final CPOWrapper expected = pattern[i]; final CPOWrapper found = diff.get(i); @@ -193,21 +199,25 @@ public class RawContactDeltaListTests extends AndroidTestCase { final String foundType = getTypeString(found); assertEquals("Unexpected type", expectedType, foundType); - if (CompatUtils.isDeleteCompat(expected)) continue; + if (CompatUtils.isDeleteCompat(expected)) { + continue; + } - try { - final ContentValues expectedValues = getValues(expected.getOperation()); - final ContentValues foundValues = getValues(found.getOperation()); + if (CompatUtils.isInsertCompat(found)) { + fakeBackReferences[i] = new ContentProviderResult( + ContentUris.withAppendedId(RawContacts.CONTENT_URI, INSERTED_CONTACT_ID)); + } else if (CompatUtils.isUpdateCompat(found)) { + fakeBackReferences[i] = new ContentProviderResult(1); + } - expectedValues.remove(BaseColumns._ID); - foundValues.remove(BaseColumns._ID); - assertEquals("Unexpected values", expectedValues, foundValues); - } catch (NoSuchFieldException e) { - fail(e.toString()); - } catch (IllegalAccessException e) { - fail(e.toString()); - } + ContentValues expectedValues = expected.getOperation().resolveValueBackReferences( + new ContentProviderResult[0], 0); + ContentValues foundValues = found.getOperation().resolveValueBackReferences( + fakeBackReferences, fakeBackReferences.length); + expectedValues.remove(BaseColumns._ID); + foundValues.remove(BaseColumns._ID); + assertEquals("Unexpected values", expectedValues, foundValues); } } @@ -247,6 +257,7 @@ public class RawContactDeltaListTests extends AndroidTestCase { static CPOWrapper buildUpdateAggregationKeepTogether(long rawContactId) { final ContentValues values = new ContentValues(); values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId); + values.put(AggregationExceptions.RAW_CONTACT_ID2, INSERTED_CONTACT_ID); values.put(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER); return buildCPOWrapper(AggregationExceptions.CONTENT_URI, TYPE_UPDATE, values); } @@ -462,7 +473,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(first, buildAssertVersion(VER_FIRST), buildUpdateAggregationSuspended(), - buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), + buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, + buildDataInsert(bluePhone, CONTACT_BOB)), buildUpdateAggregationDefault()); // Merge in the second version, verify that our insert remains @@ -470,7 +482,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(merged, buildAssertVersion(VER_SECOND), buildUpdateAggregationSuspended(), - buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), + buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, + buildDataInsert(bluePhone, CONTACT_BOB)), buildUpdateAggregationDefault()); } @@ -479,10 +492,11 @@ public class RawContactDeltaListTests extends AndroidTestCase { VER_FIRST, buildPhone(PHONE_RED))); final RawContactDeltaList second = buildSet(buildBeforeEntity(mContext, CONTACT_BOB, VER_SECOND, buildPhone(PHONE_RED)), buildBeforeEntity(mContext, CONTACT_MARY, - VER_SECOND, buildPhone(PHONE_RED))); + VER_SECOND, buildPhone(PHONE_RED))); // Add new contact locally, should remain insert final ContentValues joePhoneInsert = buildPhone(PHONE_BLUE); + joePhoneInsert.put(Data.RAW_CONTACT_ID, INSERTED_CONTACT_ID); final RawContactDelta joeContact = buildAfterEntity(joePhoneInsert); final ContentValues joeContactInsert = joeContact.getValues().getCompleteValues(); joeContactInsert.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED); @@ -542,6 +556,7 @@ public class RawContactDeltaListTests extends AndroidTestCase { buildUpdateAggregationDefault()); final ContentValues phoneInsert = phone.getCompleteValues(); + phoneInsert.put(Data.RAW_CONTACT_ID, INSERTED_CONTACT_ID); final ContentValues contactInsert = first.getByRawContactId(CONTACT_MARY).getValues() .getCompleteValues(); contactInsert.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED); @@ -562,11 +577,11 @@ public class RawContactDeltaListTests extends AndroidTestCase { final RawContactDeltaList second = buildSet(buildBeforeEntity(mContext, CONTACT_BOB, VER_SECOND, buildPhone(PHONE_RED))); - assertEquals((Long)VER_FIRST, getVersion(first, CONTACT_BOB)); - assertEquals((Long)VER_SECOND, getVersion(second, CONTACT_BOB)); + assertEquals((Long) VER_FIRST, getVersion(first, CONTACT_BOB)); + assertEquals((Long) VER_SECOND, getVersion(second, CONTACT_BOB)); final RawContactDeltaList merged = RawContactDeltaList.mergeAfter(second, first); - assertEquals((Long)VER_SECOND, getVersion(merged, CONTACT_BOB)); + assertEquals((Long) VER_SECOND, getVersion(merged, CONTACT_BOB)); } public void testMergeAfterEnsureAndTrim() { @@ -585,7 +600,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(first, buildAssertVersion(VER_FIRST), buildUpdateAggregationSuspended(), - buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bobPhone, CONTACT_BOB)), + buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, + buildDataInsert(bobPhone, CONTACT_BOB)), buildUpdateAggregationDefault()); // Trim values and ensure that we don't insert things |