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

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

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

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

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2499217



Change-Id: Ica50bac50fc3f6ad4ea9d01bc28cec8596c5d350
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 2e4e3eba aa4a4f6d
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.provider.ContactsContract;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;


import com.android.bluetooth.BluetoothMethodProxy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.vcard.VCardEntry;
import com.android.vcard.VCardEntry;
import com.android.vcard.VCardEntry.PhoneData;
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()) {
        for (String key : mCallCounter.keySet()) {
            ContentValues values = new ContentValues();
            ContentValues values = new ContentValues();
            values.put(ContactsContract.RawContacts.TIMES_CONTACTED, mCallCounter.get(key));
            values.put(ContactsContract.RawContacts.TIMES_CONTACTED, mCallCounter.get(key));
            Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
            Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                    Uri.encode(key));
                    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) {
                if (c != null && c.getCount() > 0) {
                    c.moveToNext();
                    c.moveToNext();
                    String contactId = c.getString(c.getColumnIndex(
                    String contactId = c.getString(c.getColumnIndex(
+37 −0
Original line number Original line Diff line number Diff line
@@ -18,22 +18,31 @@ package com.android.bluetooth.pbapclient;


import static com.google.common.truth.Truth.assertThat;
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 static org.mockito.Mockito.mock;


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


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


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


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


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


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


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


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

    @Test
    @Test
    public void testToString() {
    public void testToString() {
        final String path = PbapClientConnectionHandler.ICH_PATH;
        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) {
    private VCardProperty createProperty(String name, String value) {
        VCardProperty property = new VCardProperty();
        VCardProperty property = new VCardProperty();
        property.setName(name);
        property.setName(name);