Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 389e64f5 authored by Kihong Seong's avatar Kihong Seong Committed by Android (Google) Code Review
Browse files

Merge "Add test for BluetoothMapContentObserver.handleContactListChanges" into tm-qpr-dev

parents e33259d8 05333df8
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -146,7 +146,8 @@ public class BluetoothMapContentObserver {
    boolean mObserverRegistered = false;
    @VisibleForTesting
    BluetoothMapAccountItem mAccount;
    private String mAuthority = null;
    @VisibleForTesting
    String mAuthority = null;

    // Default supported feature bit mask is 0x1f
    private int mMapSupportedFeatures = BluetoothMapUtils.MAP_FEATURE_DEFAULT_BITMASK;
@@ -1976,7 +1977,8 @@ public class BluetoothMapContentObserver {
        }
    }

    private void handleContactListChanges(Uri uri) {
    @VisibleForTesting
    void handleContactListChanges(Uri uri) {
        if (uri.getAuthority().equals(mAuthority)) {
            try {
                if (V) {
+142 −30
Original line number Diff line number Diff line
@@ -93,6 +93,23 @@ public class BluetoothMapContentObserverTest {
    static final int TEST_MMS_TYPE_ALL = Telephony.BaseMmsColumns.MESSAGE_BOX_ALL;
    static final int TEST_MMS_TYPE_INBOX = Telephony.BaseMmsColumns.MESSAGE_BOX_INBOX;
    static final Uri TEST_URI = Mms.CONTENT_URI;
    static final String TEST_AUTHORITY = "test_authority";

    static final long TEST_CONVO_ID = 1;
    static final String TEST_NAME = "col_name";
    static final String TEST_DISPLAY_NAME = "col_nickname";
    static final String TEST_BT_UID = "1111";
    static final int TEST_CHAT_STATE = 1;
    static final int TEST_CHAT_STATE_DIFFERENT = 2;
    static final String TEST_UCI = "col_uci";
    static final String TEST_UCI_DIFFERENT = "col_uci_different";
    static final long TEST_LAST_ACTIVITY = 1;
    static final int TEST_PRESENCE_STATE = 1;
    static final int TEST_PRESENCE_STATE_DIFFERENT = 2;
    static final String TEST_STATUS_TEXT = "col_status_text";
    static final String TEST_STATUS_TEXT_DIFFERENT = "col_status_text_different";
    static final int TEST_PRIORITY = 1;
    static final int TEST_LAST_ONLINE = 1;

    @Mock
    private BluetoothMnsObexClient mClient;
@@ -806,18 +823,6 @@ public class BluetoothMapContentObserverTest {

    @Test
    public void initContactsList() throws Exception {
        long convoId = 1;
        String name = "col_name";
        String displayName = "col_nickname";
        String btUid = "1111";
        int chatState = 1;
        String uci = "col_uci";
        long lastActivity = 1;
        int presenceState = 1;
        String statusText = "col_status_text";
        int priority = 1;
        int lastOnline = 1;

        MatrixCursor cursor = new MatrixCursor(
                new String[]{BluetoothMapContract.ConvoContactColumns.CONVO_ID,
                        BluetoothMapContract.ConvoContactColumns.NAME,
@@ -830,8 +835,9 @@ public class BluetoothMapContentObserverTest {
                        BluetoothMapContract.ConvoContactColumns.STATUS_TEXT,
                        BluetoothMapContract.ConvoContactColumns.PRIORITY,
                        BluetoothMapContract.ConvoContactColumns.LAST_ONLINE});
        cursor.addRow(new Object[] {convoId, name, displayName, btUid, chatState, uci, lastActivity,
        presenceState, statusText, priority, lastOnline});
        cursor.addRow(new Object[] {TEST_CONVO_ID, TEST_NAME, TEST_DISPLAY_NAME, TEST_BT_UID,
                TEST_CHAT_STATE, TEST_UCI, TEST_LAST_ACTIVITY, TEST_PRESENCE_STATE,
                TEST_STATUS_TEXT, TEST_PRIORITY, TEST_LAST_ONLINE});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());

@@ -841,22 +847,23 @@ public class BluetoothMapContentObserverTest {
        Map<String, BluetoothMapConvoContactElement> map = new HashMap<>();
        mObserver.setContactList(map, true);
        mObserver.initContactsList();
        BluetoothMapConvoContactElement contactElement = mObserver.getContactList().get(uci);
        BluetoothMapConvoContactElement contactElement = mObserver.getContactList().get(TEST_UCI);

        final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
        Assert.assertEquals(contactElement.getContactId(), uci);
        Assert.assertEquals(contactElement.getName(), name);
        Assert.assertEquals(contactElement.getDisplayName(), displayName);
        Assert.assertEquals(contactElement.getBtUid(), btUid);
        Assert.assertEquals(contactElement.getChatState(), chatState);
        Assert.assertEquals(contactElement.getPresenceStatus(), statusText);
        Assert.assertEquals(contactElement.getPresenceAvailability(), presenceState);
        Assert.assertEquals(contactElement.getLastActivityString(), format.format(lastActivity));
        Assert.assertEquals(contactElement.getPriority(), priority);
        Assert.assertEquals(contactElement.getContactId(), TEST_UCI);
        Assert.assertEquals(contactElement.getName(), TEST_NAME);
        Assert.assertEquals(contactElement.getDisplayName(), TEST_DISPLAY_NAME);
        Assert.assertEquals(contactElement.getBtUid(), TEST_BT_UID);
        Assert.assertEquals(contactElement.getChatState(), TEST_CHAT_STATE);
        Assert.assertEquals(contactElement.getPresenceStatus(), TEST_STATUS_TEXT);
        Assert.assertEquals(contactElement.getPresenceAvailability(), TEST_PRESENCE_STATE);
        Assert.assertEquals(contactElement.getLastActivityString(), format.format(
                TEST_LAST_ACTIVITY));
        Assert.assertEquals(contactElement.getPriority(), TEST_PRIORITY);
    }

    @Test
    public void handleMsgListChangesMsg_withNonExistingMessage_andVersionEleven() throws Exception {
    public void handleMsgListChangesMsg_withNonExistingMessage_andVersion11() throws Exception {
        MatrixCursor cursor = new MatrixCursor(new String[] {
                BluetoothMapContract.MessageColumns._ID,
                BluetoothMapContract.MessageColumns.FOLDER_ID,
@@ -892,7 +899,7 @@ public class BluetoothMapContentObserverTest {
    }

    @Test
    public void handleMsgListChangesMsg_withNonExistingMessage_andVersionTwelve() throws Exception {
    public void handleMsgListChangesMsg_withNonExistingMessage_andVersion12() throws Exception {
        MatrixCursor cursor = new MatrixCursor(new String[] {
                BluetoothMapContract.MessageColumns._ID,
                BluetoothMapContract.MessageColumns.FOLDER_ID,
@@ -928,7 +935,7 @@ public class BluetoothMapContentObserverTest {
    }

    @Test
    public void handleMsgListChangesMsg_withNonExistingMessage_andVersionTen() throws Exception {
    public void handleMsgListChangesMsg_withNonExistingMessage_andVersion10() throws Exception {
        MatrixCursor cursor = new MatrixCursor(new String[] {
                BluetoothMapContract.MessageColumns._ID,
                BluetoothMapContract.MessageColumns.FOLDER_ID,
@@ -1092,7 +1099,7 @@ public class BluetoothMapContentObserverTest {
    }

    @Test
    public void handleMsgListChangesMms_withNonExistingMessage_andVersionEleven() {
    public void handleMsgListChangesMms_withNonExistingMessage_andVersion11() {
        MatrixCursor cursor = new MatrixCursor(new String[] {Mms._ID, Mms.MESSAGE_BOX,
                Mms.MESSAGE_TYPE, Mms.THREAD_ID, Mms.READ, Mms.DATE, Mms.SUBJECT,
        Mms.PRIORITY, Mms.Addr.ADDRESS});
@@ -1122,7 +1129,7 @@ public class BluetoothMapContentObserverTest {
    }

    @Test
    public void handleMsgListChangesMms_withNonExistingMessage_andVersionTwelve() {
    public void handleMsgListChangesMms_withNonExistingMessage_andVersion12() {
        MatrixCursor cursor = new MatrixCursor(new String[] {Mms._ID, Mms.MESSAGE_BOX,
                Mms.MESSAGE_TYPE, Mms.THREAD_ID, Mms.READ, Mms.DATE, Mms.SUBJECT,
                Mms.PRIORITY, Mms.Addr.ADDRESS});
@@ -1152,7 +1159,7 @@ public class BluetoothMapContentObserverTest {
    }

    @Test
    public void handleMsgListChangesMms_withNonExistingMessage_andVersionTen() {
    public void handleMsgListChangesMms_withNonExistingMessage_andVersion10() {
        MatrixCursor cursor = new MatrixCursor(new String[] {Mms._ID, Mms.MESSAGE_BOX,
                Mms.MESSAGE_TYPE, Mms.THREAD_ID, Mms.READ});
        cursor.addRow(new Object[] {TEST_HANDLE_ONE, TEST_MMS_TYPE_ALL, TEST_MMS_MTYPE,
@@ -1488,6 +1495,111 @@ public class BluetoothMapContentObserverTest {
        verify(mContext).getContentResolver();
    }

    @Test
    public void handleContactListChanges_withNullContactForUci() throws Exception {
        Uri uri = mock(Uri.class);
        mObserver.mAuthority = TEST_AUTHORITY;
        when(uri.getAuthority()).thenReturn(TEST_AUTHORITY);

        MatrixCursor cursor = new MatrixCursor(
                new String[]{BluetoothMapContract.ConvoContactColumns.CONVO_ID,
                        BluetoothMapContract.ConvoContactColumns.NAME,
                        BluetoothMapContract.ConvoContactColumns.NICKNAME,
                        BluetoothMapContract.ConvoContactColumns.X_BT_UID,
                        BluetoothMapContract.ConvoContactColumns.CHAT_STATE,
                        BluetoothMapContract.ConvoContactColumns.UCI,
                        BluetoothMapContract.ConvoContactColumns.LAST_ACTIVE,
                        BluetoothMapContract.ConvoContactColumns.PRESENCE_STATE,
                        BluetoothMapContract.ConvoContactColumns.STATUS_TEXT,
                        BluetoothMapContract.ConvoContactColumns.PRIORITY,
                        BluetoothMapContract.ConvoContactColumns.LAST_ONLINE});
        cursor.addRow(new Object[] {TEST_CONVO_ID, TEST_NAME, TEST_DISPLAY_NAME, TEST_BT_UID,
                TEST_CHAT_STATE, TEST_UCI, TEST_LAST_ACTIVITY, TEST_PRESENCE_STATE,
                TEST_STATUS_TEXT, TEST_PRIORITY, TEST_LAST_ONLINE});
        doReturn(cursor).when(mProviderClient).query(any(), any(), any(), any(), any());

        Map<String, BluetoothMapConvoContactElement> map = new HashMap<>();
        map.put(TEST_UCI_DIFFERENT, null);
        mObserver.setContactList(map, true);
        mObserver.mMapEventReportVersion = BluetoothMapUtils.MAP_EVENT_REPORT_V12;

        mObserver.handleContactListChanges(uri);

        BluetoothMapConvoContactElement contactElement = mObserver.getContactList().get(TEST_UCI);
        final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
        Assert.assertEquals(contactElement.getContactId(), TEST_UCI);
        Assert.assertEquals(contactElement.getName(), TEST_NAME);
        Assert.assertEquals(contactElement.getDisplayName(), TEST_DISPLAY_NAME);
        Assert.assertEquals(contactElement.getBtUid(), TEST_BT_UID);
        Assert.assertEquals(contactElement.getChatState(), TEST_CHAT_STATE);
        Assert.assertEquals(contactElement.getPresenceStatus(), TEST_STATUS_TEXT);
        Assert.assertEquals(contactElement.getPresenceAvailability(), TEST_PRESENCE_STATE);
        Assert.assertEquals(contactElement.getLastActivityString(), format.format(
                TEST_LAST_ACTIVITY));
        Assert.assertEquals(contactElement.getPriority(), TEST_PRIORITY);
    }

    @Test
    public void handleContactListChanges_withNonNullContactForUci() throws Exception {
        Uri uri = mock(Uri.class);
        mObserver.mAuthority = TEST_AUTHORITY;
        when(uri.getAuthority()).thenReturn(TEST_AUTHORITY);

        MatrixCursor cursor = new MatrixCursor(
                new String[]{BluetoothMapContract.ConvoContactColumns.CONVO_ID,
                        BluetoothMapContract.ConvoContactColumns.NAME,
                        BluetoothMapContract.ConvoContactColumns.NICKNAME,
                        BluetoothMapContract.ConvoContactColumns.X_BT_UID,
                        BluetoothMapContract.ConvoContactColumns.CHAT_STATE,
                        BluetoothMapContract.ConvoContactColumns.UCI,
                        BluetoothMapContract.ConvoContactColumns.LAST_ACTIVE,
                        BluetoothMapContract.ConvoContactColumns.PRESENCE_STATE,
                        BluetoothMapContract.ConvoContactColumns.STATUS_TEXT,
                        BluetoothMapContract.ConvoContactColumns.PRIORITY,
                        BluetoothMapContract.ConvoContactColumns.LAST_ONLINE});
        cursor.addRow(new Object[] {TEST_CONVO_ID, TEST_NAME, TEST_DISPLAY_NAME, TEST_BT_UID,
                TEST_CHAT_STATE, TEST_UCI, TEST_LAST_ACTIVITY, TEST_PRESENCE_STATE,
                TEST_STATUS_TEXT, TEST_PRIORITY, TEST_LAST_ONLINE});
        doReturn(cursor).when(mProviderClient).query(any(), any(), any(), any(), any());

        Map<String, BluetoothMapConvoContactElement> map = new HashMap<>();
        map.put(TEST_UCI_DIFFERENT, null);
        BluetoothMapConvoContactElement contact = new BluetoothMapConvoContactElement(TEST_UCI,
                TEST_NAME, TEST_DISPLAY_NAME, TEST_STATUS_TEXT_DIFFERENT,
                TEST_PRESENCE_STATE_DIFFERENT, TEST_LAST_ACTIVITY, TEST_CHAT_STATE_DIFFERENT,
                TEST_PRIORITY, TEST_BT_UID);
        map.put(TEST_UCI, contact);
        mObserver.setContactList(map, true);
        mObserver.mMapEventReportVersion = BluetoothMapUtils.MAP_EVENT_REPORT_V12;

        mObserver.handleContactListChanges(uri);

        BluetoothMapConvoContactElement contactElement = mObserver.getContactList().get(TEST_UCI);
        final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
        Assert.assertEquals(contactElement.getContactId(), TEST_UCI);
        Assert.assertEquals(contactElement.getName(), TEST_NAME);
        Assert.assertEquals(contactElement.getDisplayName(), TEST_DISPLAY_NAME);
        Assert.assertEquals(contactElement.getBtUid(), TEST_BT_UID);
        Assert.assertEquals(contactElement.getChatState(), TEST_CHAT_STATE);
        Assert.assertEquals(contactElement.getPresenceStatus(), TEST_STATUS_TEXT);
        Assert.assertEquals(contactElement.getPresenceAvailability(), TEST_PRESENCE_STATE);
        Assert.assertEquals(contactElement.getLastActivityString(), format.format(
                TEST_LAST_ACTIVITY));
        Assert.assertEquals(contactElement.getPriority(), TEST_PRIORITY);
    }

    @Test
    public void handleContactListChanges_withMapEventReportVersion11() throws Exception {
        Uri uri = mock(Uri.class);
        mObserver.mAuthority = TEST_AUTHORITY;
        when(uri.getAuthority()).thenReturn(TEST_AUTHORITY);
        mObserver.mMapEventReportVersion = BluetoothMapUtils.MAP_EVENT_REPORT_V11;

        mObserver.handleContactListChanges(uri);

        verify(mProviderClient, never()).query(any(), any(), any(), any(), any(), any());
    }

    private BluetoothMapContentObserver.Msg createSimpleMsg() {
        return new BluetoothMapContentObserver.Msg(1, 1L, 1);
    }