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

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

Merge "Add tests for extract methods in BluetoothMapContent" am: 8328cb4c

parents 660cbe74 8328cb4c
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -3504,7 +3504,8 @@ public class BluetoothMapContent {
        String orderBy = Contacts._ID + " ASC";

        // Get the contact _ID and name
        p = mResolver.query(uri, projection, selection, null, orderBy);
        p = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver, uri, projection,
                selection, null, orderBy);
        try {
            if (p != null && p.moveToFirst()) {
                contactId = p.getString(p.getColumnIndex(Contacts._ID));
@@ -3518,7 +3519,8 @@ public class BluetoothMapContent {
            Cursor q = null;
            // Fetch the contact e-mail addresses
            try {
                q = mResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
                q = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                        ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
                        new String[]{contactId}, null);
                if (q != null && q.moveToFirst()) {
@@ -3627,14 +3629,16 @@ public class BluetoothMapContent {
        return message.encode();
    }

    private void extractMmsAddresses(long id, BluetoothMapbMessageMime message) {
    @VisibleForTesting
    void extractMmsAddresses(long id, BluetoothMapbMessageMime message) {
        final String[] projection = null;
        String selection = new String(Mms.Addr.MSG_ID + "=" + id);
        String uriStr = new String(Mms.CONTENT_URI + "/" + id + "/addr");
        Uri uriAddress = Uri.parse(uriStr);
        String contactName = null;

        Cursor c = mResolver.query(uriAddress, projection, selection, null, null);
        Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver, uriAddress,
                projection, selection, null, null);
        try {
            if (c.moveToFirst()) {
                do {
@@ -3709,13 +3713,15 @@ public class BluetoothMapContent {
     * @param id the content provider ID of the message
     * @param message the bMessage object to add the information to
     */
    private void extractMmsParts(long id, BluetoothMapbMessageMime message) {
    @VisibleForTesting
    void extractMmsParts(long id, BluetoothMapbMessageMime message) {
        final String[] projection = null;
        String selection = new String(Mms.Part.MSG_ID + "=" + id);
        String uriStr = new String(Mms.CONTENT_URI + "/" + id + "/part");
        Uri uriAddress = Uri.parse(uriStr);
        BluetoothMapbMessageMime.MimePart part;
        Cursor c = mResolver.query(uriAddress, projection, selection, null, null);
        Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver, uriAddress,
                projection, selection, null, null);
        try {
            if (c.moveToFirst()) {
                do {
+148 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
@@ -38,6 +39,7 @@ import android.provider.Telephony;
import android.provider.Telephony.Threads;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer;

import androidx.test.runner.AndroidJUnit4;
@@ -81,6 +83,7 @@ public class BluetoothMapContentTest {
    private static final String TEST_PHONE = "test_phone";
    private static final String TEST_PHONE_NAME = "test_phone_name";
    private static final long TEST_ID = 1;
    private static final String TEST_ID_STRING = "1";
    private static final long TEST_INBOX_FOLDER_ID = BluetoothMapContract.FOLDER_ID_INBOX;
    private static final long TEST_SENT_FOLDER_ID = BluetoothMapContract.FOLDER_ID_SENT;
    private static final String TEST_SUBJECT = "subject";
@@ -106,6 +109,7 @@ public class BluetoothMapContentTest {
    private static final String TEST_YES = "yes";
    private static final String TEST_NO = "no";
    private static final String TEST_RECEPTION_STATUS = "complete";
    private static final String TEST_EMAIL = "test@google.com";

    @Mock
    private BluetoothMapAccountItem mAccountItem;
@@ -1481,4 +1485,148 @@ public class BluetoothMapContentTest {

        assertThat(mContent.msgListingHasUnread(mCurrentFolder, mParams)).isTrue();
    }

    @Test
    public void extractMmsAddresses_withTypeMmsFrom() {
        MatrixCursor addressCursor = new MatrixCursor(new String[] {Telephony.Mms.Addr.ADDRESS,
                Telephony.Mms.Addr.TYPE});
        addressCursor.addRow(new Object[] {TEST_ADDRESS, BluetoothMapContent.MMS_FROM});
        doReturn(addressCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(Telephony.Mms.Addr.MSG_ID + "=" + TEST_ID), any(), any());

        MatrixCursor contactCursor = new MatrixCursor(new String[] {ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME});
        contactCursor.addRow(new Object[] {TEST_ID_STRING, TEST_NAME});
        doReturn(contactCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1"), any(), any());

        MatrixCursor emailCursor = new MatrixCursor(
                new String[]{ContactsContract.CommonDataKinds.Email.ADDRESS});
        emailCursor.addRow(new Object[] {TEST_EMAIL});
        doReturn(emailCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?"), any(), any());

        BluetoothMapbMessageMime mime = new BluetoothMapbMessageMime();
        mContent.extractMmsAddresses(TEST_ID, mime);

        Rfc822Token fromToken = mime.getFrom().get(0);
        assertThat(fromToken.getName()).isEqualTo(TEST_NAME);
        assertThat(fromToken.getAddress()).isEqualTo(TEST_ADDRESS);
    }

    @Test
    public void extractMmsAddresses_withTypeMmsTo() {
        MatrixCursor addressCursor = new MatrixCursor(new String[] {Telephony.Mms.Addr.ADDRESS,
                Telephony.Mms.Addr.TYPE});
        addressCursor.addRow(new Object[] {TEST_ADDRESS, BluetoothMapContent.MMS_TO});
        doReturn(addressCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(Telephony.Mms.Addr.MSG_ID + "=" + TEST_ID), any(), any());

        MatrixCursor contactCursor = new MatrixCursor(new String[] {ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME});
        contactCursor.addRow(new Object[] {TEST_ID_STRING, TEST_NAME});
        doReturn(contactCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1"), any(), any());

        MatrixCursor emailCursor = new MatrixCursor(
                new String[]{ContactsContract.CommonDataKinds.Email.ADDRESS});
        emailCursor.addRow(new Object[] {TEST_EMAIL});
        doReturn(emailCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?"), any(), any());

        BluetoothMapbMessageMime mime = new BluetoothMapbMessageMime();
        mContent.extractMmsAddresses(TEST_ID, mime);

        Rfc822Token toToken = mime.getTo().get(0);
        assertThat(toToken.getName()).isEqualTo(TEST_NAME);
        assertThat(toToken.getAddress()).isEqualTo(TEST_ADDRESS);
    }

    @Test
    public void extractMmsAddresses_withTypeMmsCc() {
        MatrixCursor addressCursor = new MatrixCursor(new String[] {Telephony.Mms.Addr.ADDRESS,
                Telephony.Mms.Addr.TYPE});
        addressCursor.addRow(new Object[] {TEST_ADDRESS, BluetoothMapContent.MMS_CC});
        doReturn(addressCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(Telephony.Mms.Addr.MSG_ID + "=" + TEST_ID), any(), any());

        MatrixCursor contactCursor = new MatrixCursor(new String[] {ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME});
        contactCursor.addRow(new Object[] {TEST_ID_STRING, TEST_NAME});
        doReturn(contactCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1"), any(), any());

        MatrixCursor emailCursor = new MatrixCursor(
                new String[]{ContactsContract.CommonDataKinds.Email.ADDRESS});
        emailCursor.addRow(new Object[] {TEST_EMAIL});
        doReturn(emailCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?"), any(), any());

        BluetoothMapbMessageMime mime = new BluetoothMapbMessageMime();
        mContent.extractMmsAddresses(TEST_ID, mime);

        Rfc822Token ccToken = mime.getCc().get(0);
        assertThat(ccToken.getName()).isEqualTo(TEST_NAME);
        assertThat(ccToken.getAddress()).isEqualTo(TEST_ADDRESS);
    }

    @Test
    public void extractMmsAddresses_withTypeMmsBcc() {
        MatrixCursor addressCursor = new MatrixCursor(new String[] {Telephony.Mms.Addr.ADDRESS,
                Telephony.Mms.Addr.TYPE});
        addressCursor.addRow(new Object[] {TEST_ADDRESS, BluetoothMapContent.MMS_BCC});
        doReturn(addressCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(Telephony.Mms.Addr.MSG_ID + "=" + TEST_ID), any(), any());

        MatrixCursor contactCursor = new MatrixCursor(new String[] {ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME});
        contactCursor.addRow(new Object[] {TEST_ID_STRING, TEST_NAME});
        doReturn(contactCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1"), any(), any());

        MatrixCursor emailCursor = new MatrixCursor(
                new String[]{ContactsContract.CommonDataKinds.Email.ADDRESS});
        emailCursor.addRow(new Object[] {TEST_EMAIL});
        doReturn(emailCursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(),
                eq(ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?"), any(), any());

        BluetoothMapbMessageMime mime = new BluetoothMapbMessageMime();
        mContent.extractMmsAddresses(TEST_ID, mime);

        Rfc822Token bccToken = mime.getBcc().get(0);
        assertThat(bccToken.getName()).isEqualTo(TEST_NAME);
        assertThat(bccToken.getAddress()).isEqualTo(TEST_ADDRESS);
    }

    @Test
    public void extractMmsParts() {
        MatrixCursor cursor = new MatrixCursor(
                new String[] {BaseColumns._ID, Telephony.Mms.Part.CONTENT_TYPE,
                        Telephony.Mms.Part.NAME, Telephony.Mms.Part.CHARSET,
                        Telephony.Mms.Part.FILENAME, Telephony.Mms.Part.TEXT,
                        Telephony.Mms.Part._DATA, Telephony.Mms.Part.CONTENT_ID,
                        Telephony.Mms.Part.CONTENT_LOCATION,
                        Telephony.Mms.Part.CONTENT_DISPOSITION});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(),
                eq(Uri.parse(Telephony.Mms.CONTENT_URI + "/" + TEST_ID + "/part")), any(),
                eq(Telephony.Mms.Part.MSG_ID + "=" + TEST_ID), any(), any());
        String filename = "test_filename";
        String location = "test_content_location";
        String disposition = "test_content_disposition";
        cursor.addRow(new Object[] {TEST_ID, TEST_ATTACHMENT_MIME_TYPE, TEST_NAME, "test_charset",
                filename, TEST_TEXT, 1, TEST_ID_STRING, location, disposition});

        BluetoothMapbMessageMime mime = new BluetoothMapbMessageMime();
        mime.setIncludeAttachments(false);
        mContent.extractMmsParts(TEST_ID, mime);

        BluetoothMapbMessageMime.MimePart part = mime.getMimeParts().get(0);
        assertThat(part.mContentType).isEqualTo("text");
        assertThat(part.mPartName).isEqualTo(TEST_NAME);
        assertThat(part.mContentId).isEqualTo(TEST_ID_STRING);
        assertThat(part.mContentLocation).isEqualTo(location);
        assertThat(part.mContentDisposition).isEqualTo(disposition);
        assertThat(part.mCharsetName).isEqualTo("utf-8");
        assertThat(part.mFileName).isEqualTo(filename);
    }
}
 No newline at end of file