FileDocCategorySizeDatePackage
RecipientAlternatesAdapterTest.javaAPI DocAndroid 5.1 API7630Thu Mar 12 22:22:50 GMT 2015com.android.ex.chips

RecipientAlternatesAdapterTest

public class RecipientAlternatesAdapterTest extends android.test.AndroidTestCase

Fields Summary
Constructors Summary
Methods Summary
private static android.database.MatrixCursoraddRow(android.database.MatrixCursor c, java.lang.String displayName, java.lang.String destination, int destinationType, java.lang.String destinationLabel, long contactId, long dataId, java.lang.String photoUri, int displayNameSource)

        c.addRow(new Object[] {displayName, destination, destinationType, destinationLabel,
                contactId, dataId, photoUri, displayNameSource});
        return c;
    
private static voidassertRow(android.database.Cursor c, int position, java.lang.String displayName, java.lang.String destination, int destinationType, java.lang.String destinationLabel, long contactId, long dataId, java.lang.String photoUri, int displayNameSource)

        assertTrue(c.moveToPosition(position));
        assertEquals(displayName, c.getString(0));
        assertEquals(destination, c.getString(1));
        assertEquals(destinationType, c.getInt(2));
        assertEquals(destinationLabel, c.getString(3));
        assertEquals(contactId, c.getLong(4));
        assertEquals(dataId, c.getLong(5));
        assertEquals(photoUri, c.getString(6));
        assertEquals(displayNameSource, c.getInt(7));
    
public voidtestGetBetterRecipient()

        // Ensure that if either (but not both) parameters are null, the other is returned
        {
            final RecipientEntry entry1 =
                    RecipientEntry.constructFakeEntry("1@android.com", true);
            final RecipientEntry entry2 = null;

            assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry1, entry2), entry1);
            assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry2, entry1), entry1);
        }

        // Ensure that if only one has a display name, it is used
        {
            final RecipientEntry entry1 =
                    RecipientEntry.constructTopLevelEntry("Android", DisplayNameSources.NICKNAME,
                            "1@android.com", 0, null, 0, null /* directoryId */, 0, (Uri) null,
                            true, null /* lookupKey */);
            final RecipientEntry entry2 = RecipientEntry.constructFakeEntry("1@android.com", true);

            assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry1, entry2), entry1);
            assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry2, entry1), entry1);
        }

        // Ensure that if one has a display name different from its destination, and the other's
        // is equal to its destination, we use the unique one
        {
            final RecipientEntry entry1 =
                    RecipientEntry.constructTopLevelEntry("Android", DisplayNameSources.NICKNAME,
                            "1@android.com", 0, null, 0, null /* directoryId */, 0, (Uri) null,
                            true, null /* lookupKey */);
            final RecipientEntry entry2 =
                    RecipientEntry.constructTopLevelEntry("2@android.com", DisplayNameSources.EMAIL,
                            "2@android.com", 0, null, 0, null /* directoryId */, 0, (Uri) null,
                            true, null /* lookupKey */);

            assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry1, entry2), entry1);
            assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry2, entry1), entry1);
        }

        // Ensure that if only one has a photo, it is used
        {
            final RecipientEntry entry1 =
                    RecipientEntry.constructTopLevelEntry("Android", DisplayNameSources.NICKNAME,
                            "1@android.com", 0, null, 0, null /* directoryId */, 0,
                            Uri.parse("http://www.android.com"), true, null /* lookupKey */);
            final RecipientEntry entry2 =
                    RecipientEntry.constructTopLevelEntry("Android", DisplayNameSources.EMAIL,
                            "2@android.com", 0, null, 0, null /* directoryId */,
                            0, (Uri) null, true, null /* lookupKey */);

            assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry1, entry2), entry1);
            assertEquals(RecipientAlternatesAdapter.getBetterRecipient(entry2, entry1), entry1);
        }
    
public voidtestRemoveUndesiredDestinations()

        MatrixCursor c = new MatrixCursor(Queries.EMAIL.getProjection());
        Cursor result;

        // Test: Empty input
        assertEquals(0, RecipientAlternatesAdapter.removeUndesiredDestinations(c,
                null /* desiredMimeType */, null /* lookupKey */).getCount());


        // Test: One row
        addRow(c, "a", "1@android.com", 1, "home", 1000, 2000, "x", 0);

        result = RecipientAlternatesAdapter.removeUndesiredDestinations(c,
                null /* desiredMimeType */, null /* lookupKey */);
        assertEquals(1, result.getCount());
        assertRow(result, 0, "a", "1@android.com", 1, "home", 1000, 2000, "x", 0);

        // Test: two unique rows, different destinations
        addRow(c, "a", "2@android.com", 1, "home", 1000, 2000, "x", 0);

        result = RecipientAlternatesAdapter.removeUndesiredDestinations(c,
                null /* desiredMimeType */, null /* lookupKey */);
        assertEquals(2, result.getCount());
        assertRow(result, 0, "a", "1@android.com", 1, "home", 1000, 2000, "x", 0);
        assertRow(result, 1, "a", "2@android.com", 1, "home", 1000, 2000, "x", 0);

        // Test: add a third row with a non-unique destination.
        addRow(c, "ax", "1@android.com", 11, "homex", 10001, 2000, "xx", 1);

        // Third row should be removed.
        result = RecipientAlternatesAdapter.removeUndesiredDestinations(c,
                null /* desiredMimeType */, null /* lookupKey */);
        assertEquals(2, result.getCount());
        assertRow(result, 0, "a", "1@android.com", 1, "home", 1000, 2000, "x", 0);
        assertRow(result, 1, "a", "2@android.com", 1, "home", 1000, 2000, "x", 0);

        // Test: add a forth row with a non-unique destination again.
        addRow(c, "ax", "2@android.com", 11, "homex", 10001, 2000, "xx", 1);

        // Forth row should also be removed.
        result = RecipientAlternatesAdapter.removeUndesiredDestinations(c,
                null /* desiredMimeType */, null /* lookupKey */);
        assertEquals(2, result.getCount());
        assertRow(result, 0, "a", "1@android.com", 1, "home", 1000, 2000, "x", 0);
        assertRow(result, 1, "a", "2@android.com", 1, "home", 1000, 2000, "x", 0);