EntityModifierTests.java revision 7f86847eddbec5dff4d87ac9243d839593582e42
107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey/*
207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * Copyright (C) 2009 The Android Open Source Project
307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey *
407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License");
507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * you may not use this file except in compliance with the License.
607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * You may obtain a copy of the License at
707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey *
807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey *      http://www.apache.org/licenses/LICENSE-2.0
907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey *
1007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * Unless required by applicable law or agreed to in writing, software
1107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS,
1207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * See the License for the specific language governing permissions and
1407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * limitations under the License.
1507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey */
1607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
1707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeypackage com.android.contacts;
1807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
196f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport static android.content.ContentProviderOperation.TYPE_DELETE;
206f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport static android.content.ContentProviderOperation.TYPE_INSERT;
216f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport static android.content.ContentProviderOperation.TYPE_UPDATE;
226f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport com.android.contacts.model.ContactsSource;
246f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport com.android.contacts.model.EntityDelta;
2507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport com.android.contacts.model.EntityModifier;
267f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkeyimport com.android.contacts.model.EntitySet;
277f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkeyimport com.android.contacts.model.Sources;
2807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport com.android.contacts.model.ContactsSource.DataKind;
296f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport com.android.contacts.model.ContactsSource.EditField;
3007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport com.android.contacts.model.ContactsSource.EditType;
316f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport com.android.contacts.model.EntityDelta.ValuesDelta;
32aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport com.google.android.collect.Lists;
3307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
346f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport android.content.ContentProviderOperation;
3507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.content.ContentValues;
3607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.content.Entity;
376f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport android.provider.ContactsContract.Data;
386f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport android.provider.ContactsContract.RawContacts;
3907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.provider.ContactsContract.CommonDataKinds.Phone;
4007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.test.AndroidTestCase;
4107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.test.suitebuilder.annotation.LargeTest;
426f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport android.util.Log;
4307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
4407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport java.util.ArrayList;
4507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport java.util.List;
4607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
4707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey/**
4807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * Tests for {@link EntityModifier} to verify that {@link ContactsSource}
4907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * constraints are being enforced correctly.
5007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey */
5107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey@LargeTest
5207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeypublic class EntityModifierTests extends AndroidTestCase {
5307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public static final String TAG = "EntityModifierTests";
5407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
556f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    private static final long TEST_ID = 4;
566f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    private static final String TEST_PHONE = "218-555-1212";
576f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
587f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    private static final String TEST_ACCOUNT_NAME = "unittest@example.com";
597f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    private static final String TEST_ACCOUNT_TYPE = "com.example.unittest";
607f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
6107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public EntityModifierTests() {
6207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        super();
6307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
6407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
6507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    @Override
6607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public void setUp() {
6707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        mContext = getContext();
6807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
6907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
7007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
7107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Build a {@link ContactsSource} that has various odd constraints for
7207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * testing purposes.
7307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
7407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    protected ContactsSource getSource() {
7507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContactsSource list = new ContactsSource();
767f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        list.accountType = TEST_ACCOUNT_TYPE;
777f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        list.setInflatedLevel(ContactsSource.LEVEL_CONSTRAINTS);
7807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
7907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        {
8007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            // Phone allows maximum 2 home, 1 work, and unlimited other, with
8107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            // constraint of 5 numbers maximum.
8207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            DataKind kind = new DataKind(Phone.CONTENT_ITEM_TYPE, -1, -1, 10, true);
8307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
8407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeOverallMax = 5;
8507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeColumn = Phone.TYPE;
86aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey            kind.typeList = Lists.newArrayList();
87d4c41d5c553745fb1126e01334319f05f0808eb3Jeff Sharkey            kind.typeList.add(new EditType(Phone.TYPE_HOME, -1).setSpecificMax(2));
88d4c41d5c553745fb1126e01334319f05f0808eb3Jeff Sharkey            kind.typeList.add(new EditType(Phone.TYPE_WORK, -1).setSpecificMax(1));
89d4c41d5c553745fb1126e01334319f05f0808eb3Jeff Sharkey            kind.typeList.add(new EditType(Phone.TYPE_FAX_WORK, -1).setSecondary(true));
9007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeList.add(new EditType(Phone.TYPE_OTHER, -1));
9107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
926f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            kind.fieldList = Lists.newArrayList();
936f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            kind.fieldList.add(new EditField(Phone.NUMBER, -1, -1));
946f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            kind.fieldList.add(new EditField(Phone.LABEL, -1, -1));
956f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
9607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            list.add(kind);
9707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        }
9807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
9907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        return list;
10007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
10107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
10207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
1037f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey     * Build {@link Sources} instance.
1047f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey     */
1057f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    protected Sources getSources(ContactsSource... sources) {
1067f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        return new Sources(sources);
1077f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    }
1087f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
1097f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    /**
11007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Build an {@link Entity} with the requested set of phone numbers.
11107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
1127f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    protected EntityDelta getEntity(Long existingId, ContentValues... entries) {
11307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContentValues contact = new ContentValues();
1147f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        if (existingId != null) {
1157f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            contact.put(RawContacts._ID, existingId);
1167f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
1177f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        contact.put(RawContacts.ACCOUNT_NAME, TEST_ACCOUNT_NAME);
1187f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        contact.put(RawContacts.ACCOUNT_TYPE, TEST_ACCOUNT_TYPE);
1197f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
12007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final Entity before = new Entity(contact);
1216f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        for (ContentValues values : entries) {
1226f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            before.addSubValue(Data.CONTENT_URI, values);
1236f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
1248d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey        return EntityDelta.fromBefore(before);
12507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
12607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
12707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
12807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Assert this {@link List} contains the given {@link Object}.
12907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
13007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    protected void assertContains(List<?> list, Object object) {
13107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertTrue("Missing expected value", list.contains(object));
13207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
13307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
13407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
13507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Assert this {@link List} does not contain the given {@link Object}.
13607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
13707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    protected void assertNotContains(List<?> list, Object object) {
13807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertFalse("Contained unexpected value", list.contains(object));
13907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
14007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
14107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
14207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Insert various rows to test
1438d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey     * {@link EntityModifier#getValidTypes(EntityDelta, DataKind, EditType)}
14407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
14507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public void testValidTypes() {
14607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Build a source and pull specific types
14707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContactsSource source = getSource();
14807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
14907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
15007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeWork = EntityModifier.getType(kindPhone, Phone.TYPE_WORK);
15107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeOther = EntityModifier.getType(kindPhone, Phone.TYPE_OTHER);
15207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
15307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        List<EditType> validTypes;
15407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
15507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add first home, first work
1567f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID);
15707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
15807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeWork);
15907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
16007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Expecting home, other
16107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        validTypes = EntityModifier.getValidTypes(state, kindPhone, null);
16207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertContains(validTypes, typeHome);
16307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeWork);
16407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertContains(validTypes, typeOther);
16507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
16607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add second home
16707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
16807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
16907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Expecting other
17007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        validTypes = EntityModifier.getValidTypes(state, kindPhone, null);
17107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeHome);
17207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeWork);
17307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertContains(validTypes, typeOther);
17407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
17507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add third and fourth home (invalid, but possible)
17607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
17707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
17807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
17907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Expecting none
18007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        validTypes = EntityModifier.getValidTypes(state, kindPhone, null);
18107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeHome);
18207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeWork);
18307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeOther);
18407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
18507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
18607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
1878d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey     * Test {@link EntityModifier#canInsert(EntityDelta, DataKind)} by
18807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * inserting various rows.
18907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
19007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public void testCanInsert() {
19107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Build a source and pull specific types
19207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContactsSource source = getSource();
19307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
19407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
19507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeWork = EntityModifier.getType(kindPhone, Phone.TYPE_WORK);
19607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeOther = EntityModifier.getType(kindPhone, Phone.TYPE_OTHER);
19707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
19807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add first home, first work
1997f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID);
20007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
20107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeWork);
20207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertTrue("Unable to insert", EntityModifier.canInsert(state, kindPhone));
20307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
20407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add two other, which puts us just under "5" overall limit
20507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeOther);
20607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeOther);
20707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertTrue("Unable to insert", EntityModifier.canInsert(state, kindPhone));
20807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
20907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add second home, which should push to snug limit
21007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
21107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertFalse("Able to insert", EntityModifier.canInsert(state, kindPhone));
21207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
21307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
21407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
215d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey     * Test
216d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey     * {@link EntityModifier#getBestValidType(EntityDelta, DataKind, boolean, int)}
21707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * by asserting expected best options in various states.
21807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
21907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public void testBestValidType() {
22007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Build a source and pull specific types
22107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContactsSource source = getSource();
22207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
22307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
22407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeWork = EntityModifier.getType(kindPhone, Phone.TYPE_WORK);
22507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeFaxWork = EntityModifier.getType(kindPhone, Phone.TYPE_FAX_WORK);
22607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeOther = EntityModifier.getType(kindPhone, Phone.TYPE_OTHER);
22707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
22807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EditType suggested;
22907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
23007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Default suggestion should be home
2317f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID);
232d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
23307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeHome, suggested);
23407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
23507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add first home, should now suggest work
23607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
237d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
23807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeWork, suggested);
23907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
24007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add work fax, should still suggest work
24107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeFaxWork);
242d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
24307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeWork, suggested);
24407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
24507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add other, should still suggest work
24607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeOther);
247d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
24807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeWork, suggested);
24907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
25007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add work, now should suggest other
25107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeWork);
252d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
25307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeOther, suggested);
25407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
2556f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2566f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    public void testIsEmptyEmpty() {
2576f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ContactsSource source = getSource();
2586f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
2596f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2606f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Test entirely empty row
2616f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ContentValues after = new ContentValues();
2626f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ValuesDelta values = ValuesDelta.fromAfter(after);
2636f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2646f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertTrue("Expected empty", EntityModifier.isEmpty(values, kindPhone));
2656f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    }
2666f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2676f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    public void testIsEmptyDirectFields() {
2686f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ContactsSource source = getSource();
2696f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
2706f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
2716f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2726f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Test row that has type values, but core fields are empty
2737f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID);
2746f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ValuesDelta values = EntityModifier.insertChild(state, kindPhone, typeHome);
2756f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2766f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertTrue("Expected empty", EntityModifier.isEmpty(values, kindPhone));
2776f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2786f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Insert some data to trigger non-empty state
2796f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        values.put(Phone.NUMBER, TEST_PHONE);
2806f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2816f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertFalse("Expected non-empty", EntityModifier.isEmpty(values, kindPhone));
2826f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    }
2836f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2846f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    public void testTrimEmptySingle() {
2856f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ContactsSource source = getSource();
2866f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
2876f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
2886f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2896f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Test row that has type values, but core fields are empty
2907f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID);
2916f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ValuesDelta values = EntityModifier.insertChild(state, kindPhone, typeHome);
2926f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
2936f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Build diff, expecting insert for data row and update enforcement
2946f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
2956f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        state.buildDiff(diff);
2966f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertEquals("Unexpected operations", 3, diff.size());
2976f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
2986f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(0);
2996f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
3006f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
3016f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
3026f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
3036f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(1);
3046f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect type", TYPE_INSERT, oper.getType());
3056f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
3066f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
3076f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
3086f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(2);
3096f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
3106f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
3116f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
3126f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3137f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Trim empty rows and try again, expecting delete of overall contact
3147f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        EntityModifier.trimEmpty(state, source);
3156f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        diff.clear();
3166f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        state.buildDiff(diff);
3177f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 1, diff.size());
3187f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
3197f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(0);
3207f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect type", TYPE_DELETE, oper.getType());
3217f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
3227f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
3236f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    }
3246f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3256f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    public void testTrimEmptyUntouched() {
3266f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ContactsSource source = getSource();
3276f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
3286f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
3296f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3306f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Build "before" that has empty row
3317f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID);
3326f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ContentValues before = new ContentValues();
3336f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        before.put(Data._ID, TEST_ID);
3346f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        before.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
3356f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        state.addEntry(ValuesDelta.fromBefore(before));
3366f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3376f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Build diff, expecting no changes
3386f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
3396f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        state.buildDiff(diff);
3406f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertEquals("Unexpected operations", 0, diff.size());
3416f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3426f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Try trimming existing empty, which we shouldn't touch
3437f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        EntityModifier.trimEmpty(state, source);
3446f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        diff.clear();
3456f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        state.buildDiff(diff);
3466f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertEquals("Unexpected operations", 0, diff.size());
3476f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    }
3486f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3496f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    public void testTrimEmptyAfterUpdate() {
3506f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ContactsSource source = getSource();
3516f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
3526f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
3536f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3546f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Build "before" that has row with some phone number
3556f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ContentValues before = new ContentValues();
3566f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        before.put(Data._ID, TEST_ID);
3576f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        before.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
3586f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        before.put(kindPhone.typeColumn, typeHome.rawValue);
3596f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        before.put(Phone.NUMBER, TEST_PHONE);
3607f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID, before);
3616f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3626f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Build diff, expecting no changes
3636f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
3646f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        state.buildDiff(diff);
3656f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertEquals("Unexpected operations", 0, diff.size());
3666f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3676f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Now update row by changing number to empty string, expecting single update
3686f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        final ValuesDelta child = state.getEntry(TEST_ID);
3696f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        child.put(Phone.NUMBER, "");
3706f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        diff.clear();
3716f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        state.buildDiff(diff);
3726f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertEquals("Unexpected operations", 3, diff.size());
3736f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
3746f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(0);
3756f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
3766f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
3776f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
3786f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
3796f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(1);
3806f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect type", TYPE_UPDATE, oper.getType());
3816f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
3826f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
3836f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
3846f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(2);
3856f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
3866f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
3876f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
3886f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
3896f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Now run trim, which should turn that update into delete
3907f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        EntityModifier.trimEmpty(state, source);
3917f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        diff.clear();
3927f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
3937f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 1, diff.size());
3947f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
3957f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(0);
3967f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect type", TYPE_DELETE, oper.getType());
3977f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
3987f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
3997f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    }
4007f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4017f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    public void testTrimInsertEmpty() {
4027f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ContactsSource source = getSource();
4037f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final Sources sources = getSources(source);
4047f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
4057f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
4067f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4077f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Try creating a contact without any child entries
4087f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(null);
4097f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntitySet set = EntitySet.fromSingle(state);
4107f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4117f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Build diff, expecting single insert
4127f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
4137f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
4147f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 1, diff.size());
4157f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
4167f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(0);
4177f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect type", TYPE_INSERT, oper.getType());
4187f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
4197f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
4207f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4217f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Trim empty rows and try again, expecting no insert
4227f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        EntityModifier.trimEmpty(set, sources);
4237f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        diff.clear();
4247f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
4257f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 0, diff.size());
4267f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    }
4277f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4287f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    public void testTrimInsertInsert() {
4297f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ContactsSource source = getSource();
4307f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final Sources sources = getSources(source);
4317f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
4327f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
4337f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4347f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Try creating a contact with single empty entry
4357f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(null);
4367f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ValuesDelta values = EntityModifier.insertChild(state, kindPhone, typeHome);
4377f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntitySet set = EntitySet.fromSingle(state);
4387f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4397f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Build diff, expecting two insert operations
4407f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
4417f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
4427f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 2, diff.size());
4437f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
4447f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(0);
4457f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect type", TYPE_INSERT, oper.getType());
4467f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
4477f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
4487f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
4497f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(1);
4507f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect type", TYPE_INSERT, oper.getType());
4517f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
4527f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
4537f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4547f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Trim empty rows and try again, expecting silence
4557f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        EntityModifier.trimEmpty(set, sources);
4567f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        diff.clear();
4577f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
4587f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 0, diff.size());
4597f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    }
4607f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4617f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    public void testTrimUpdateRemain() {
4627f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ContactsSource source = getSource();
4637f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final Sources sources = getSources(source);
4647f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
4657f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
4667f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4677f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Build "before" with two phone numbers
4687f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ContentValues first = new ContentValues();
4697f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        first.put(Data._ID, TEST_ID);
4707f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        first.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
4717f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        first.put(kindPhone.typeColumn, typeHome.rawValue);
4727f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        first.put(Phone.NUMBER, TEST_PHONE);
4737f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4747f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ContentValues second = new ContentValues();
4757f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        second.put(Data._ID, TEST_ID);
4767f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        second.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
4777f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        second.put(kindPhone.typeColumn, typeHome.rawValue);
4787f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        second.put(Phone.NUMBER, TEST_PHONE);
4797f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4807f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID, first, second);
4817f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntitySet set = EntitySet.fromSingle(state);
4827f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4837f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Build diff, expecting no changes
4847f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
4857f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
4867f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 0, diff.size());
4877f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
4887f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Now update row by changing number to empty string, expecting single update
4897f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ValuesDelta child = state.getEntry(TEST_ID);
4907f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        child.put(Phone.NUMBER, "");
4917f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        diff.clear();
4927f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
4937f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 3, diff.size());
4947f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
4957f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(0);
4967f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
4977f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
4987f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
4997f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
5007f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(1);
5017f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect type", TYPE_UPDATE, oper.getType());
5027f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
5037f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
5047f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
5057f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(2);
5067f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
5077f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
5087f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
5097f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
5107f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Now run trim, which should turn that update into delete
5117f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        EntityModifier.trimEmpty(set, sources);
5126f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        diff.clear();
5136f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        state.buildDiff(diff);
5146f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        assertEquals("Unexpected operations", 3, diff.size());
5156f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
5166f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(0);
5176f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
5186f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
5196f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
5206f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
5216f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(1);
5226f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect type", TYPE_DELETE, oper.getType());
5236f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
5246f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
5256f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        {
5266f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            final ContentProviderOperation oper = diff.get(2);
5276f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
5286f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
5296f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        }
5306f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    }
5317f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
5327f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    public void testTrimUpdateUpdate() {
5337f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ContactsSource source = getSource();
5347f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final Sources sources = getSources(source);
5357f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
5367f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
5377f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
5387f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Build "before" with two phone numbers
5397f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ContentValues first = new ContentValues();
5407f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        first.put(Data._ID, TEST_ID);
5417f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        first.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
5427f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        first.put(kindPhone.typeColumn, typeHome.rawValue);
5437f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        first.put(Phone.NUMBER, TEST_PHONE);
5447f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
5457f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntityDelta state = getEntity(TEST_ID, first);
5467f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final EntitySet set = EntitySet.fromSingle(state);
5477f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
5487f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Build diff, expecting no changes
5497f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();
5507f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
5517f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 0, diff.size());
5527f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
5537f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Now update row by changing number to empty string, expecting single update
5547f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        final ValuesDelta child = state.getEntry(TEST_ID);
5557f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        child.put(Phone.NUMBER, "");
5567f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        diff.clear();
5577f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
5587f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 3, diff.size());
5597f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
5607f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(0);
5617f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
5627f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
5637f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
5647f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
5657f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(1);
5667f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect type", TYPE_UPDATE, oper.getType());
5677f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", Data.CONTENT_URI, oper.getUri());
5687f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
5697f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
5707f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(2);
5717f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Expected aggregation mode change", TYPE_UPDATE, oper.getType());
5727f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
5737f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
5747f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey
5757f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        // Now run trim, which should turn into deleting the whole contact
5767f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        EntityModifier.trimEmpty(set, sources);
5777f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        diff.clear();
5787f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        state.buildDiff(diff);
5797f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        assertEquals("Unexpected operations", 1, diff.size());
5807f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        {
5817f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            final ContentProviderOperation oper = diff.get(0);
5827f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect type", TYPE_DELETE, oper.getType());
5837f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey            assertEquals("Incorrect target", RawContacts.CONTENT_URI, oper.getUri());
5847f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey        }
5857f86847eddbec5dff4d87ac9243d839593582e42Jeff Sharkey    }
58607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey}
587