summaryrefslogtreecommitdiff
path: root/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java
blob: d0547bda82493f1a0327c454cc22e191a2565154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.android.dialer.list;

import android.database.Cursor;
import android.database.MatrixCursor;
import android.provider.ContactsContract.PinnedPositions;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.contacts.common.ContactTileLoaderFactory;
import com.android.contacts.common.list.ContactEntry;
import com.android.dialer.list.PhoneFavoritesTileAdapter.OnDataSetChangedForAnimationListener;

import java.util.ArrayList;

@SmallTest
public class PhoneFavoritesTileAdapterTest extends AndroidTestCase {
    private PhoneFavoritesTileAdapter mAdapter;
    private static final OnDataSetChangedForAnimationListener
            sOnDataSetChangedForAnimationListener = new OnDataSetChangedForAnimationListener() {
                @Override
                public void onDataSetChangedForAnimation(long... idsInPlace) {}

                @Override
                public void cacheOffsetsForDatasetChange() {}
            };

    /**
     * TODO: Add tests
     *
     * Test cases (various combinations of):
     * No pinned contacts
     * One pinned contact
     * Multiple pinned contacts with differing pinned positions
     * Multiple pinned contacts with conflicting pinned positions
     * Pinned contacts with pinned positions at the start, middle, end, and outside the list
     */
    public void testArrangeContactsByPinnedPosition() {

    }

    /**
     * TODO: Add tests
     *
     * This method assumes that contacts have already been reordered by
     * arrangeContactsByPinnedPosition, so we can test it with a less expansive set of test data.
     *
     * Test cases:
     * Pin a single contact at the start, middle and end of a completely unpinned list
     * Pin a single contact at the start, middle and end of a list with various numbers of
     * pinned contacts
     * Pin a single contact at the start, middle and end of a list where all contacts are pinned
     * such that contacts are forced to the left as necessary.
     */
    public void testGetReflowedPinnedPositions() {

    }

    /**
     * Returns a cursor containing starred and frequent contacts for test purposes.
     *
     * @param numStarred Number of starred contacts in the cursor. Cannot be a negative number.
     * @param numFrequents Number of frequent contacts in the cursor. Cannot be a negative number.
     * @return Cursor containing the required number of rows, each representing one ContactEntry
     */
    private Cursor getCursorForTest(int numStarred, int numFrequents) {
        assertTrue(numStarred >= 0);
        assertTrue(numFrequents >= 0);
        final MatrixCursor c = new MatrixCursor(ContactTileLoaderFactory.COLUMNS_PHONE_ONLY);
        int countId = 0;

        // Add starred contact entries. These entries have the starred field set to 1 (true).
        // The only field that really matters for testing is the contact id.
        for (int i = 0; i < numStarred; i++) {
            c.addRow(new Object[] {countId, null, 1, null, null, 0, 0, null, 0,
                    PinnedPositions.UNPINNED, countId});
            countId++;
        }

        // Add frequent contact entries. These entries have the starred field set to 0 (false).
        for (int i = 0; i < numFrequents; i++) {
            c.addRow(new Object[] {countId, null, 0, null, null, 0, 0, null, 0,
                    PinnedPositions.UNPINNED, countId});
            countId++;
        }
        return c;
    }

    /**
     * Returns a ContactEntry with test data corresponding to the provided contact Id
     *
     * @param id Non-negative id
     * @return ContactEntry item used for testing
     */
    private ContactEntry getTestContactEntry(int id, boolean isFavorite) {
        ContactEntry contactEntry = new ContactEntry();
        contactEntry.id = id;
        contactEntry.isFavorite = isFavorite;
        return contactEntry;
    }

    private void assertContactEntryRowsEqual(ArrayList<ContactEntry> expected,
            ArrayList<ContactEntry> actual) {
        assertEquals(expected.size(), actual.size());
        for (int i = 0; i < actual.size(); i++) {
            assertEquals(expected.get(i).id, actual.get(i).id);
            assertEquals(expected.get(i).isFavorite, actual.get(i).isFavorite);
        }
    }
}