EntityModifierTests.java revision d046a039e41deab0635c3327cd40c3896e39acad
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
198d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkeyimport com.android.contacts.model.EntityDelta;
2007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport com.android.contacts.model.ContactsSource;
2107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport com.android.contacts.model.EntityModifier;
2207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport com.android.contacts.model.ContactsSource.DataKind;
2307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport com.android.contacts.model.ContactsSource.EditType;
2407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
2507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.content.ContentValues;
2607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.content.Entity;
2707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.provider.ContactsContract.CommonDataKinds.Phone;
2807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.test.AndroidTestCase;
2907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport android.test.suitebuilder.annotation.LargeTest;
3007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
3107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport java.util.ArrayList;
3207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeyimport java.util.List;
3307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
3407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey/**
3507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * Tests for {@link EntityModifier} to verify that {@link ContactsSource}
3607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey * constraints are being enforced correctly.
3707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey */
3807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey@LargeTest
3907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkeypublic class EntityModifierTests extends AndroidTestCase {
4007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public static final String TAG = "EntityModifierTests";
4107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
4207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public EntityModifierTests() {
4307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        super();
4407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
4507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
4607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    @Override
4707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public void setUp() {
4807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        mContext = getContext();
4907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
5007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
5107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
5207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Build a {@link ContactsSource} that has various odd constraints for
5307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * testing purposes.
5407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
5507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    protected ContactsSource getSource() {
5607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContactsSource list = new ContactsSource();
5707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
5807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        {
5907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            // Phone allows maximum 2 home, 1 work, and unlimited other, with
6007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            // constraint of 5 numbers maximum.
6107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            DataKind kind = new DataKind(Phone.CONTENT_ITEM_TYPE, -1, -1, 10, true);
6207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
6307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeOverallMax = 5;
6407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeColumn = Phone.TYPE;
6507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeList = new ArrayList<EditType>();
6607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeList.add(new EditType(Phone.TYPE_HOME, -1, false, 2));
6707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeList.add(new EditType(Phone.TYPE_WORK, -1, false, 1));
6807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeList.add(new EditType(Phone.TYPE_FAX_WORK, -1, true, -1));
6907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            kind.typeList.add(new EditType(Phone.TYPE_OTHER, -1));
7007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
7107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey            list.add(kind);
7207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        }
7307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
7407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        return list;
7507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
7607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
7707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
7807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Build an {@link Entity} with the requested set of phone numbers.
7907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
808d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey    protected EntityDelta getEntity() {
8107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContentValues contact = new ContentValues();
8207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final Entity before = new Entity(contact);
838d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey        return EntityDelta.fromBefore(before);
8407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
8507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
8607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
8707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Assert this {@link List} contains the given {@link Object}.
8807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
8907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    protected void assertContains(List<?> list, Object object) {
9007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertTrue("Missing expected value", list.contains(object));
9107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
9207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
9307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
9407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Assert this {@link List} does not contain the given {@link Object}.
9507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
9607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    protected void assertNotContains(List<?> list, Object object) {
9707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertFalse("Contained unexpected value", list.contains(object));
9807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
9907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
10007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
10107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * Insert various rows to test
1028d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey     * {@link EntityModifier#getValidTypes(EntityDelta, DataKind, EditType)}
10307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
10407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public void testValidTypes() {
10507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Build a source and pull specific types
10607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContactsSource source = getSource();
10707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
10807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
10907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeWork = EntityModifier.getType(kindPhone, Phone.TYPE_WORK);
11007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeOther = EntityModifier.getType(kindPhone, Phone.TYPE_OTHER);
11107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
11207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        List<EditType> validTypes;
11307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
11407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add first home, first work
1158d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey        final EntityDelta state = getEntity();
11607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
11707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeWork);
11807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
11907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Expecting home, other
12007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        validTypes = EntityModifier.getValidTypes(state, kindPhone, null);
12107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertContains(validTypes, typeHome);
12207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeWork);
12307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertContains(validTypes, typeOther);
12407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
12507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add second home
12607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
12707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
12807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Expecting other
12907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        validTypes = EntityModifier.getValidTypes(state, kindPhone, null);
13007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeHome);
13107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeWork);
13207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertContains(validTypes, typeOther);
13307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
13407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add third and fourth home (invalid, but possible)
13507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
13607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
13707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
13807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Expecting none
13907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        validTypes = EntityModifier.getValidTypes(state, kindPhone, null);
14007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeHome);
14107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeWork);
14207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertNotContains(validTypes, typeOther);
14307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
14407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
14507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
1468d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey     * Test {@link EntityModifier#canInsert(EntityDelta, DataKind)} by
14707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * inserting various rows.
14807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
14907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public void testCanInsert() {
15007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Build a source and pull specific types
15107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContactsSource source = getSource();
15207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
15307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
15407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeWork = EntityModifier.getType(kindPhone, Phone.TYPE_WORK);
15507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeOther = EntityModifier.getType(kindPhone, Phone.TYPE_OTHER);
15607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
15707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add first home, first work
1588d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey        final EntityDelta state = getEntity();
15907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
16007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeWork);
16107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertTrue("Unable to insert", EntityModifier.canInsert(state, kindPhone));
16207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
16307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add two other, which puts us just under "5" overall limit
16407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeOther);
16507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeOther);
16607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertTrue("Unable to insert", EntityModifier.canInsert(state, kindPhone));
16707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
16807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add second home, which should push to snug limit
16907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
17007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertFalse("Able to insert", EntityModifier.canInsert(state, kindPhone));
17107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
17207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
17307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    /**
174d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey     * Test
175d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey     * {@link EntityModifier#getBestValidType(EntityDelta, DataKind, boolean, int)}
17607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     * by asserting expected best options in various states.
17707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey     */
17807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    public void testBestValidType() {
17907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Build a source and pull specific types
18007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final ContactsSource source = getSource();
18107c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final DataKind kindPhone = source.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
18207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeHome = EntityModifier.getType(kindPhone, Phone.TYPE_HOME);
18307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeWork = EntityModifier.getType(kindPhone, Phone.TYPE_WORK);
18407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeFaxWork = EntityModifier.getType(kindPhone, Phone.TYPE_FAX_WORK);
18507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        final EditType typeOther = EntityModifier.getType(kindPhone, Phone.TYPE_OTHER);
18607c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
18707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EditType suggested;
18807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
18907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Default suggestion should be home
1908d9767d79f9fe2a09ee6e981b1fede7e9863d62aJeff Sharkey        final EntityDelta state = getEntity();
191d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
19207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeHome, suggested);
19307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
19407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add first home, should now suggest work
19507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeHome);
196d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
19707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeWork, suggested);
19807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
19907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add work fax, should still suggest work
20007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeFaxWork);
201d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
20207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeWork, suggested);
20307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
20407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add other, should still suggest work
20507c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeOther);
206d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
20707c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeWork, suggested);
20807c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey
20907c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        // Add work, now should suggest other
21007c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        EntityModifier.insertChild(state, kindPhone, typeWork);
211d046a039e41deab0635c3327cd40c3896e39acadJeff Sharkey        suggested = EntityModifier.getBestValidType(state, kindPhone, false, Integer.MIN_VALUE);
21207c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey        assertEquals("Unexpected suggestion", typeOther, suggested);
21307c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey    }
21407c2e41b5ce7abeb9dd14e5d700a8fb928723330Jeff Sharkey}
215