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

Commit febf6e54 authored by Kihong Seong's avatar Kihong Seong Committed by Automerger Merge Worker
Browse files

Merge "Add test for CallLogPullRequest#updateTimesContacted" am: 3963c5bd am: 08822006

parents 3963d90e 08822006
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.provider.ContactsContract;
import android.util.Log;
import android.util.Pair;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.vcard.VCardEntry;
import com.android.vcard.VCardEntry.PhoneData;
@@ -141,13 +142,15 @@ public class CallLogPullRequest extends PullRequest {
        }
    }

    private void updateTimesContacted() {
    @VisibleForTesting
    void updateTimesContacted() {
        for (String key : mCallCounter.keySet()) {
            ContentValues values = new ContentValues();
            values.put(ContactsContract.RawContacts.TIMES_CONTACTED, mCallCounter.get(key));
            Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                    Uri.encode(key));
            try (Cursor c = mContext.getContentResolver().query(uri, null, null, null)) {
            try (Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(
                    mContext.getContentResolver(), uri, null, null, null)) {
                if (c != null && c.getCount() > 0) {
                    c.moveToNext();
                    String contactId = c.getString(c.getColumnIndex(
+37 −0
Original line number Diff line number Diff line
@@ -18,22 +18,31 @@ package com.android.bluetooth.pbapclient;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import android.accounts.Account;
import android.content.Context;
import android.database.MatrixCursor;
import android.provider.ContactsContract;

import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.vcard.VCardConstants;
import com.android.vcard.VCardEntry;
import com.android.vcard.VCardProperty;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;

import java.util.ArrayList;
import java.util.HashMap;
@@ -47,12 +56,21 @@ public class CallLogPullRequestTest {
    private final HashMap<String, Integer> mCallCounter = new HashMap<>();

    private Context mTargetContext;
    @Spy
    private BluetoothMethodProxy mMapMethodProxy = BluetoothMethodProxy.getInstance();

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
        mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    }

    @After
    public void tearDown() throws Exception {
        BluetoothMethodProxy.setInstanceForTesting(null);
    }

    @Test
    public void testToString() {
        final String path = PbapClientConnectionHandler.ICH_PATH;
@@ -156,6 +174,25 @@ public class CallLogPullRequestTest {
        }
    }

    @Test
    public void updateTimesContacted_cursorIsClosed() {
        final String path = PbapClientConnectionHandler.OCH_PATH;
        final CallLogPullRequest request = new CallLogPullRequest(
                mTargetContext, path, mCallCounter, mAccount);
        mCallCounter.put("key", 1);

        MatrixCursor cursor = new MatrixCursor(
                new String[] {ContactsContract.PhoneLookup.CONTACT_ID});
        cursor.addRow(new Object[] {"contact_id"});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), eq(null),
                eq(null), eq(null));
        assertThat(cursor.isClosed()).isFalse();

        request.updateTimesContacted();

        assertThat(cursor.isClosed()).isTrue();
    }

    private VCardProperty createProperty(String name, String value) {
        VCardProperty property = new VCardProperty();
        property.setName(name);