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

Commit 74528f04 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add BluetoothMapContentTest" am: c88124a2 am: ae26d9df

parents ff603f4b ae26d9df
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer;
import android.util.Log;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.DeviceWorkArounds;
import com.android.bluetooth.SignedLongLong;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
@@ -1215,7 +1216,8 @@ public class BluetoothMapContent {
        String uriStr = new String(Mms.CONTENT_URI + "/" + id + "/part");
        Uri uriAddress = Uri.parse(uriStr);
        // TODO: maybe use a projection with only "ct" and "text"
        Cursor c = r.query(uriAddress, null, selection, null, null);
        Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(r, uriAddress, null,
                selection, null, null);
        try {
            if (c != null && c.moveToFirst()) {
                do {
@@ -1327,7 +1329,8 @@ public class BluetoothMapContent {
        String orderBy = Contacts.DISPLAY_NAME + " ASC";
        Cursor c = null;
        try {
            c = resolver.query(uri, projection, selection, null, orderBy);
            c = BluetoothMethodProxy.getInstance().contentResolverQuery(resolver, uri, projection,
                    selection, null, orderBy);
            if (c != null) {
                int colIndex = c.getColumnIndex(Contacts.DISPLAY_NAME);
                if (c.getCount() >= 1) {
@@ -1369,7 +1372,8 @@ public class BluetoothMapContent {
            Log.v(TAG, "whereClause is " + whereClause);
        }
        try {
            cr = r.query(sAllThreadsUri, RECIPIENT_ID_PROJECTION, whereClause, null, null);
            cr = BluetoothMethodProxy.getInstance().contentResolverQuery(r, sAllThreadsUri,
                    RECIPIENT_ID_PROJECTION, whereClause, null, null);
            if (cr != null && cr.moveToFirst()) {
                recipientIds = cr.getString(0);
                if (V) {
@@ -1400,7 +1404,8 @@ public class BluetoothMapContent {
                Log.v(TAG, "whereClause is " + whereClause);
            }
            try {
                cr = r.query(sAllCanonical, null, whereClause, null, null);
                cr = BluetoothMethodProxy.getInstance().contentResolverQuery(r, sAllCanonical, null,
                        whereClause, null, null);
                if (cr != null && cr.moveToFirst()) {
                    do {
                        //TODO: Multiple Recipeints are appended with ";" for now.
@@ -1432,7 +1437,8 @@ public class BluetoothMapContent {
        String[] projection = {Mms.Addr.ADDRESS};
        Cursor c = null;
        try {
            c = r.query(uriAddress, projection, selection, null, null); // TODO: Add projection
            c = BluetoothMethodProxy.getInstance().contentResolverQuery(r, uriAddress, projection,
                    selection, null, null); // TODO: Add projection
            int colIndex = c.getColumnIndex(Mms.Addr.ADDRESS);
            if (c != null) {
                if (c.moveToFirst()) {
+123 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.map;

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

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.provider.Telephony;

import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.BluetoothMethodProxy;

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

@RunWith(AndroidJUnit4.class)
public class BluetoothMapContentTest {
    private static final String TEST_TEXT = "text";

    @Mock
    private ContentResolver mContentResolver;
    @Spy
    private BluetoothMethodProxy mMapMethodProxy = BluetoothMethodProxy.getInstance();

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
    }

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

    @Test
    public void getTextPartsMms() {
        final long id = 1111;
        Cursor cursor = mock(Cursor.class);
        when(cursor.moveToFirst()).thenReturn(true);
        when(cursor.getColumnIndex("ct")).thenReturn(1);
        when(cursor.getString(1)).thenReturn("text/plain");
        when(cursor.getColumnIndex("text")).thenReturn(2);
        when(cursor.getString(2)).thenReturn(TEST_TEXT);
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());

        assertThat(BluetoothMapContent.getTextPartsMms(mContentResolver, id)).isEqualTo(TEST_TEXT);
    }

    @Test
    public void getContactNameFromPhone() {
        String phoneName = "testPhone";
        Cursor cursor = mock(Cursor.class);
        when(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).thenReturn(1);
        when(cursor.getCount()).thenReturn(1);
        when(cursor.getString(1)).thenReturn(TEST_TEXT);
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());

        assertThat(
                BluetoothMapContent.getContactNameFromPhone(phoneName, mContentResolver)).isEqualTo(
                TEST_TEXT);
    }

    @Test
    public void getCanonicalAddressSms() {
        int threadId = 0;
        Cursor cursor = mock(Cursor.class);
        when(cursor.moveToFirst()).thenReturn(true);
        when(cursor.getString(0)).thenReturn("recipientIdOne recipientIdTwo");
        when(cursor.getColumnIndex(Telephony.CanonicalAddressesColumns.ADDRESS)).thenReturn(1);
        when(cursor.getString(1)).thenReturn("recipientAddress");
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());

        assertThat(
                BluetoothMapContent.getCanonicalAddressSms(mContentResolver, threadId)).isEqualTo(
                "recipientAddress");
    }

    @Test
    public void getAddressMms() {
        long id = 1111;
        int type = 0;
        Cursor cursor = mock(Cursor.class);
        when(cursor.moveToFirst()).thenReturn(true);
        when(cursor.getColumnIndex(Telephony.Mms.Addr.ADDRESS)).thenReturn(1);
        when(cursor.getString(1)).thenReturn(TEST_TEXT);
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());

        assertThat(BluetoothMapContent.getAddressMms(mContentResolver, id, type)).isEqualTo(
                TEST_TEXT);
    }
}
 No newline at end of file