Code example for MatrixCursor

Methods: addRow

0
import android.test.AndroidTestCase; 
 
public class RecipientAlternatesAdapterTest extends AndroidTestCase {
 
    public void testRemoveDuplicateDestinations() { 
        MatrixCursor c = new MatrixCursor(Queries.EMAIL.getProjection());
        Cursor result;
 
        // Test: Empty input 
        assertEquals(0, RecipientAlternatesAdapter.removeDuplicateDestinations(c).getCount());
 
 
        // Test: One row 
        addRow(c, "a", "1@android.com", 1, "home", 1000, 2000, "x", 0);
 
        result = RecipientAlternatesAdapter.removeDuplicateDestinations(c);
        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.removeDuplicateDestinations(c);
        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.removeDuplicateDestinations(c);
        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.removeDuplicateDestinations(c);
        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);
    } 
 
    private static MatrixCursor addRow(MatrixCursor c,
            String displayName,
            String destination,
            int destinationType,
            String destinationLabel,
            long contactId,
            long dataId,
            String photoUri,
            int displayNameSource
            ) { 
        c.addRow(new Object[] {displayName, destination, destinationType, destinationLabel,
                contactId, dataId, photoUri, displayNameSource});
        return c;
    } 
 
    private static void assertRow(Cursor c, int position,