Fix isAssertQuery in unit test on LMP
Also fixed the failures/errors related with fixing isAssertQuery
Bug 27244680
Bug 26818072
Bug 25629359
Change-Id: I0c3644c3e4b25f120a30c2227dab000c0546f697
diff --git a/src/com/android/contacts/common/compat/CompatUtils.java b/src/com/android/contacts/common/compat/CompatUtils.java
index f833bd2..e9e8300 100644
--- a/src/com/android/contacts/common/compat/CompatUtils.java
+++ b/src/com/android/contacts/common/compat/CompatUtils.java
@@ -72,6 +72,15 @@
}
return (cpoWrapper.getType() == TYPE_DELETE);
}
+ /**
+ * Returns whether the operation in CPOWrapper is of TYPE_ASSERT;
+ */
+ public static boolean isAssertQueryCompat(CPOWrapper cpoWrapper) {
+ if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M) {
+ return cpoWrapper.getOperation().isAssertQuery();
+ }
+ return (cpoWrapper.getType() == TYPE_ASSERT);
+ }
/**
* PrioritizedMimeType is added in API level 23.
diff --git a/tests/src/com/android/contacts/common/RawContactDeltaListTests.java b/tests/src/com/android/contacts/common/RawContactDeltaListTests.java
index 98f3f33..77acb98 100644
--- a/tests/src/com/android/contacts/common/RawContactDeltaListTests.java
+++ b/tests/src/com/android/contacts/common/RawContactDeltaListTests.java
@@ -178,35 +178,35 @@
return match.getEntry(dataId);
}
- static void assertDiffPattern(RawContactDelta delta, ContentProviderOperation... pattern) {
- final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
- delta.buildAssert(diff);
- delta.buildDiff(diff);
+ static void assertDiffPattern(RawContactDelta delta, CPOWrapper... pattern) {
+ final ArrayList<CPOWrapper> diff = Lists.newArrayList();
+ delta.buildAssertWrapper(diff);
+ delta.buildDiffWrapper(diff);
assertDiffPattern(diff, pattern);
}
- static void assertDiffPattern(RawContactDeltaList set, ContentProviderOperation... pattern) {
- assertDiffPattern(set.buildDiff(), pattern);
+ static void assertDiffPattern(RawContactDeltaList set, CPOWrapper... pattern) {
+ assertDiffPattern(set.buildDiffWrapper(), pattern);
}
- static void assertDiffPattern(ArrayList<ContentProviderOperation> diff,
- ContentProviderOperation... pattern) {
+ static void assertDiffPattern(ArrayList<CPOWrapper> diff, CPOWrapper... pattern) {
assertEquals("Unexpected operations", pattern.length, diff.size());
for (int i = 0; i < pattern.length; i++) {
- final ContentProviderOperation expected = pattern[i];
- final ContentProviderOperation found = diff.get(i);
+ final CPOWrapper expected = pattern[i];
+ final CPOWrapper found = diff.get(i);
- assertEquals("Unexpected uri", expected.getUri(), found.getUri());
+ assertEquals("Unexpected uri",
+ expected.getOperation().getUri(), found.getOperation().getUri());
final String expectedType = getTypeString(expected);
final String foundType = getTypeString(found);
assertEquals("Unexpected type", expectedType, foundType);
- if (expected.isDelete()) continue;
+ if (CompatUtils.isDeleteCompat(expected)) continue;
try {
- final ContentValues expectedValues = getValues(expected);
- final ContentValues foundValues = getValues(found);
+ final ContentValues expectedValues = getValues(expected.getOperation());
+ final ContentValues foundValues = getValues(found.getOperation());
expectedValues.remove(BaseColumns._ID);
foundValues.remove(BaseColumns._ID);
@@ -220,44 +220,44 @@
}
}
- static String getTypeString(ContentProviderOperation op) {
- if (op.isAssertQuery()) {
+ static String getTypeString(CPOWrapper cpoWrapper) {
+ if (CompatUtils.isAssertQueryCompat(cpoWrapper)) {
return "TYPE_ASSERT";
- } else if (op.isInsert()) {
+ } else if (CompatUtils.isInsertCompat(cpoWrapper)) {
return "TYPE_INSERT";
- } else if (op.isUpdate()) {
+ } else if (CompatUtils.isUpdateCompat(cpoWrapper)) {
return "TYPE_UPDATE";
- } else if (op.isDelete()) {
+ } else if (CompatUtils.isDeleteCompat(cpoWrapper)) {
return "TYPE_DELETE";
}
return "TYPE_UNKNOWN";
}
- static ContentProviderOperation buildAssertVersion(long version) {
+ static CPOWrapper buildAssertVersion(long version) {
final ContentValues values = new ContentValues();
values.put(RawContacts.VERSION, version);
- return buildOper(RawContacts.CONTENT_URI, TYPE_ASSERT, values);
+ return buildCPOWrapper(RawContacts.CONTENT_URI, TYPE_ASSERT, values);
}
- static ContentProviderOperation buildAggregationModeUpdate(int mode) {
+ static CPOWrapper buildAggregationModeUpdate(int mode) {
final ContentValues values = new ContentValues();
values.put(RawContacts.AGGREGATION_MODE, mode);
- return buildOper(RawContacts.CONTENT_URI, TYPE_UPDATE, values);
+ return buildCPOWrapper(RawContacts.CONTENT_URI, TYPE_UPDATE, values);
}
- static ContentProviderOperation buildUpdateAggregationSuspended() {
+ static CPOWrapper buildUpdateAggregationSuspended() {
return buildAggregationModeUpdate(RawContacts.AGGREGATION_MODE_SUSPENDED);
}
- static ContentProviderOperation buildUpdateAggregationDefault() {
+ static CPOWrapper buildUpdateAggregationDefault() {
return buildAggregationModeUpdate(RawContacts.AGGREGATION_MODE_DEFAULT);
}
- static ContentProviderOperation buildUpdateAggregationKeepTogether(long rawContactId) {
+ static CPOWrapper buildUpdateAggregationKeepTogether(long rawContactId) {
final ContentValues values = new ContentValues();
values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId);
values.put(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER);
- return buildOper(AggregationExceptions.CONTENT_URI, TYPE_UPDATE, values);
+ return buildCPOWrapper(AggregationExceptions.CONTENT_URI, TYPE_UPDATE, values);
}
static ContentValues buildDataInsert(ValuesDelta values, long rawContactId) {
@@ -266,8 +266,8 @@
return insertValues;
}
- static ContentProviderOperation buildDelete(Uri uri) {
- return buildOper(uri, TYPE_DELETE, (ContentValues)null);
+ static CPOWrapper buildDelete(Uri uri) {
+ return buildCPOWrapper(uri, TYPE_DELETE, (ContentValues) null);
}
static ContentProviderOperation buildOper(Uri uri, int type, ValuesDelta values) {
@@ -288,6 +288,14 @@
return null;
}
+ static CPOWrapper buildCPOWrapper(Uri uri, int type, ContentValues values) {
+ if (type == TYPE_ASSERT || type == TYPE_INSERT || type == TYPE_UPDATE
+ || type == TYPE_DELETE) {
+ return new CPOWrapper(buildOper(uri, type, values), type);
+ }
+ return null;
+ }
+
static Long getVersion(RawContactDeltaList set, Long rawContactId) {
return set.getByRawContactId(rawContactId).getValues().getAsLong(RawContacts.VERSION);
}
@@ -388,7 +396,7 @@
assertDiffPattern(first,
buildAssertVersion(VER_FIRST),
buildUpdateAggregationSuspended(),
- buildOper(Data.CONTENT_URI, TYPE_UPDATE, phone.getAfter()),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_UPDATE, phone.getAfter()),
buildUpdateAggregationDefault());
// Merge in the second version, verify diff matches
@@ -396,7 +404,7 @@
assertDiffPattern(merged,
buildAssertVersion(VER_SECOND),
buildUpdateAggregationSuspended(),
- buildOper(Data.CONTENT_URI, TYPE_UPDATE, phone.getAfter()),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_UPDATE, phone.getAfter()),
buildUpdateAggregationDefault());
}
@@ -413,7 +421,7 @@
assertDiffPattern(first,
buildAssertVersion(VER_FIRST),
buildUpdateAggregationSuspended(),
- buildOper(Data.CONTENT_URI, TYPE_UPDATE, phone.getAfter()),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_UPDATE, phone.getAfter()),
buildUpdateAggregationDefault());
// Merge in the second version, verify that our update changed to
@@ -422,7 +430,7 @@
assertDiffPattern(merged,
buildAssertVersion(VER_SECOND),
buildUpdateAggregationSuspended(),
- buildOper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(phone, CONTACT_BOB)),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(phone, CONTACT_BOB)),
buildUpdateAggregationDefault());
}
@@ -463,7 +471,7 @@
assertDiffPattern(first,
buildAssertVersion(VER_FIRST),
buildUpdateAggregationSuspended(),
- buildOper(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
@@ -471,7 +479,7 @@
assertDiffPattern(merged,
buildAssertVersion(VER_SECOND),
buildUpdateAggregationSuspended(),
- buildOper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)),
buildUpdateAggregationDefault());
}
@@ -490,8 +498,8 @@
first.add(joeContact);
assertDiffPattern(first,
buildAssertVersion(VER_FIRST),
- buildOper(RawContacts.CONTENT_URI, TYPE_INSERT, joeContactInsert),
- buildOper(Data.CONTENT_URI, TYPE_INSERT, joePhoneInsert),
+ buildCPOWrapper(RawContacts.CONTENT_URI, TYPE_INSERT, joeContactInsert),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, joePhoneInsert),
buildAggregationModeUpdate(RawContacts.AGGREGATION_MODE_DEFAULT),
buildUpdateAggregationKeepTogether(CONTACT_BOB));
@@ -500,8 +508,8 @@
assertDiffPattern(merged,
buildAssertVersion(VER_SECOND),
buildAssertVersion(VER_SECOND),
- buildOper(RawContacts.CONTENT_URI, TYPE_INSERT, joeContactInsert),
- buildOper(Data.CONTENT_URI, TYPE_INSERT, joePhoneInsert),
+ buildCPOWrapper(RawContacts.CONTENT_URI, TYPE_INSERT, joeContactInsert),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, joePhoneInsert),
buildAggregationModeUpdate(RawContacts.AGGREGATION_MODE_DEFAULT),
buildUpdateAggregationKeepTogether(CONTACT_BOB));
}
@@ -539,7 +547,7 @@
buildAssertVersion(VER_FIRST),
buildAssertVersion(VER_FIRST),
buildUpdateAggregationSuspended(),
- buildOper(Data.CONTENT_URI, TYPE_UPDATE, phone.getAfter()),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_UPDATE, phone.getAfter()),
buildUpdateAggregationDefault());
final ContentValues phoneInsert = phone.getCompleteValues();
@@ -551,8 +559,8 @@
final RawContactDeltaList merged = RawContactDeltaList.mergeAfter(second, first);
assertDiffPattern(merged,
buildAssertVersion(VER_SECOND),
- buildOper(RawContacts.CONTENT_URI, TYPE_INSERT, contactInsert),
- buildOper(Data.CONTENT_URI, TYPE_INSERT, phoneInsert),
+ buildCPOWrapper(RawContacts.CONTENT_URI, TYPE_INSERT, contactInsert),
+ buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, phoneInsert),
buildAggregationModeUpdate(RawContacts.AGGREGATION_MODE_DEFAULT),
buildUpdateAggregationKeepTogether(CONTACT_BOB));
}
@@ -586,7 +594,7 @@
assertDiffPattern(first,
buildAssertVersion(VER_FIRST),
buildUpdateAggregationSuspended(),
- buildOper(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
diff --git a/tests/src/com/android/contacts/common/RawContactDeltaTests.java b/tests/src/com/android/contacts/common/RawContactDeltaTests.java
index 90e663f..e4690d9 100644
--- a/tests/src/com/android/contacts/common/RawContactDeltaTests.java
+++ b/tests/src/com/android/contacts/common/RawContactDeltaTests.java
@@ -158,7 +158,7 @@
}
/**
- * Test that {@link RawContactDelta#buildDiff(ArrayList)} is correctly built for
+ * Test that {@link RawContactDelta#buildDiffWrapper(ArrayList)} is correctly built for
* insert, update, and delete cases. This only tests a subset of possible
* {@link Data} row changes.
*/
@@ -167,8 +167,8 @@
final RawContactDelta source = RawContactDelta.fromBefore(before);
// Assert that writing unchanged produces few operations
- final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
- source.buildDiff(diff);
+ final ArrayList<CPOWrapper> diff = Lists.newArrayList();
+ source.buildDiffWrapper(diff);
assertTrue("Created changes when none needed", (diff.size() == 0));
}
@@ -185,27 +185,30 @@
source.addEntry(ValuesDelta.fromAfter(phone));
// Assert two operations: insert Data row and enforce version
- final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
- source.buildAssert(diff);
- source.buildDiff(diff);
+ final ArrayList<CPOWrapper> diff = Lists.newArrayList();
+ source.buildAssertWrapper(diff);
+ source.buildDiffWrapper(diff);
assertEquals("Unexpected operations", 4, diff.size());
{
- final ContentProviderOperation oper = diff.get(0);
- assertTrue("Expected version enforcement", oper.isAssertQuery());
+ final CPOWrapper cpoWrapper = diff.get(0);
+ assertTrue("Expected version enforcement", CompatUtils.isAssertQueryCompat(cpoWrapper));
}
{
- final ContentProviderOperation oper = diff.get(1);
- assertTrue("Expected aggregation mode change", oper.isUpdate());
+ final CPOWrapper cpoWrapper = diff.get(1);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Expected aggregation mode change", CompatUtils.isUpdateCompat(cpoWrapper));
assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
}
{
- final ContentProviderOperation oper = diff.get(2);
- assertTrue("Incorrect type", oper.isInsert());
+ final CPOWrapper cpoWrapper = diff.get(2);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Incorrect type", CompatUtils.isInsertCompat(cpoWrapper));
assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
}
{
- final ContentProviderOperation oper = diff.get(3);
- assertTrue("Expected aggregation mode change", oper.isUpdate());
+ final CPOWrapper cpoWrapper = diff.get(3);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Expected aggregation mode change", CompatUtils.isUpdateCompat(cpoWrapper));
assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
}
}
@@ -225,32 +228,36 @@
source.addEntry(ValuesDelta.fromAfter(phone));
// Assert three operations: update Contact, insert Data row, enforce version
- final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
- source.buildAssert(diff);
- source.buildDiff(diff);
+ final ArrayList<CPOWrapper> diff = Lists.newArrayList();
+ source.buildAssertWrapper(diff);
+ source.buildDiffWrapper(diff);
assertEquals("Unexpected operations", 5, diff.size());
{
- final ContentProviderOperation oper = diff.get(0);
- assertTrue("Expected version enforcement", oper.isAssertQuery());
+ final CPOWrapper cpoWrapper = diff.get(0);
+ assertTrue("Expected version enforcement", CompatUtils.isAssertQueryCompat(cpoWrapper));
}
{
- final ContentProviderOperation oper = diff.get(1);
- assertTrue("Expected aggregation mode change", oper.isUpdate());
+ final CPOWrapper cpoWrapper = diff.get(1);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Expected aggregation mode change", CompatUtils.isUpdateCompat(cpoWrapper));
assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
}
{
- final ContentProviderOperation oper = diff.get(2);
- assertTrue("Incorrect type", oper.isUpdate());
+ final CPOWrapper cpoWrapper = diff.get(2);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Incorrect type", CompatUtils.isUpdateCompat(cpoWrapper));
assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
}
{
- final ContentProviderOperation oper = diff.get(3);
- assertTrue("Incorrect type", oper.isInsert());
+ final CPOWrapper cpoWrapper = diff.get(3);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Incorrect type", CompatUtils.isInsertCompat(cpoWrapper));
assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
}
{
- final ContentProviderOperation oper = diff.get(4);
- assertTrue("Expected aggregation mode change", oper.isUpdate());
+ final CPOWrapper cpoWrapper = diff.get(4);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Expected aggregation mode change", CompatUtils.isUpdateCompat(cpoWrapper));
assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
}
}
@@ -264,27 +271,30 @@
child.put(Phone.NUMBER, TEST_PHONE_NUMBER_2);
// Assert that version is enforced
- final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
- source.buildAssert(diff);
- source.buildDiff(diff);
+ final ArrayList<CPOWrapper> diff = Lists.newArrayList();
+ source.buildAssertWrapper(diff);
+ source.buildDiffWrapper(diff);
assertEquals("Unexpected operations", 4, diff.size());
{
- final ContentProviderOperation oper = diff.get(0);
- assertTrue("Expected version enforcement", oper.isAssertQuery());
+ final CPOWrapper cpoWrapper = diff.get(0);
+ assertTrue("Expected version enforcement", CompatUtils.isAssertQueryCompat(cpoWrapper));
}
{
- final ContentProviderOperation oper = diff.get(1);
- assertTrue("Expected aggregation mode change", oper.isUpdate());
+ final CPOWrapper cpoWrapper = diff.get(1);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Expected aggregation mode change", CompatUtils.isUpdateCompat(cpoWrapper));
assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
}
{
- final ContentProviderOperation oper = diff.get(2);
- assertTrue("Incorrect type", oper.isUpdate());
+ final CPOWrapper cpoWrapper = diff.get(2);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Incorrect type", CompatUtils.isUpdateCompat(cpoWrapper));
assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
}
{
- final ContentProviderOperation oper = diff.get(3);
- assertTrue("Expected aggregation mode change", oper.isUpdate());
+ final CPOWrapper cpoWrapper = diff.get(3);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Expected aggregation mode change", CompatUtils.isUpdateCompat(cpoWrapper));
assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
}
}
@@ -297,17 +307,18 @@
source.getValues().markDeleted();
// Assert two operations: delete Contact and enforce version
- final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
- source.buildAssert(diff);
- source.buildDiff(diff);
+ final ArrayList<CPOWrapper> diff = Lists.newArrayList();
+ source.buildAssertWrapper(diff);
+ source.buildDiffWrapper(diff);
assertEquals("Unexpected operations", 2, diff.size());
{
- final ContentProviderOperation oper = diff.get(0);
- assertTrue("Expected version enforcement", oper.isAssertQuery());
+ final CPOWrapper cpoWrapper = diff.get(0);
+ assertTrue("Expected version enforcement", CompatUtils.isAssertQueryCompat(cpoWrapper));
}
{
- final ContentProviderOperation oper = diff.get(1);
- assertTrue("Incorrect type", oper.isDelete());
+ final CPOWrapper cpoWrapper = diff.get(1);
+ final ContentProviderOperation oper = cpoWrapper.getOperation();
+ assertTrue("Incorrect type", CompatUtils.isDeleteCompat(cpoWrapper));
assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
}
}
diff --git a/tests/src/com/android/contacts/common/RawContactModifierTests.java b/tests/src/com/android/contacts/common/RawContactModifierTests.java
index 15670c5..755838b 100644
--- a/tests/src/com/android/contacts/common/RawContactModifierTests.java
+++ b/tests/src/com/android/contacts/common/RawContactModifierTests.java
@@ -439,7 +439,7 @@
RawContactDeltaListTests.assertDiffPattern(state,
RawContactDeltaListTests.buildAssertVersion(VER_FIRST),
RawContactDeltaListTests.buildUpdateAggregationSuspended(),
- RawContactDeltaListTests.buildOper(Data.CONTENT_URI, TYPE_INSERT,
+ RawContactDeltaListTests.buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT,
RawContactDeltaListTests.buildDataInsert(values, TEST_ID)),
RawContactDeltaListTests.buildUpdateAggregationDefault());
@@ -465,7 +465,7 @@
RawContactDeltaListTests.assertDiffPattern(state,
RawContactDeltaListTests.buildAssertVersion(VER_FIRST),
RawContactDeltaListTests.buildUpdateAggregationSuspended(),
- RawContactDeltaListTests.buildOper(Data.CONTENT_URI, TYPE_INSERT,
+ RawContactDeltaListTests.buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT,
RawContactDeltaListTests.buildDataInsert(values, TEST_ID)),
RawContactDeltaListTests.buildUpdateAggregationDefault());
@@ -474,7 +474,7 @@
RawContactDeltaListTests.assertDiffPattern(state,
RawContactDeltaListTests.buildAssertVersion(VER_FIRST),
RawContactDeltaListTests.buildUpdateAggregationSuspended(),
- RawContactDeltaListTests.buildOper(Data.CONTENT_URI, TYPE_INSERT,
+ RawContactDeltaListTests.buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT,
RawContactDeltaListTests.buildDataInsert(values, TEST_ID)),
RawContactDeltaListTests.buildUpdateAggregationDefault());
}