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

Commit 256ed77b authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

Add assumption to test

SmsMessage.calculateLength() requires
the FEATURE_TELEPHONY_MESSAGING feature.

This commit adds an assumption to disable
the test on environments lacking this feature.

Flag: EXEMPT, test only change
Test: atest BluetoothMapsmsPduTest
Bug: 367385963
Change-Id: Id84442abb6ea5006a897779f17e32b50a0c93740
parent 45ce68d3
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -16,22 +16,26 @@

package com.android.bluetooth.map;

import static android.content.pm.PackageManager.FEATURE_TELEPHONY_MESSAGING;

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

import static org.junit.Assert.assertThrows;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.pm.PackageManager;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;

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

import com.android.bluetooth.map.BluetoothMapSmsPdu.SmsPdu;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -66,6 +70,9 @@ public class BluetoothMapSmsPduTest {

    @Before
    public void setUp() throws Exception {
        PackageManager packageManager =
                InstrumentationRegistry.getTargetContext().getPackageManager();
        assumeTrue(packageManager.isPackageAvailable(FEATURE_TELEPHONY_MESSAGING));
        when(mTargetContext.getSystemServiceName(TelephonyManager.class))
                .thenReturn("TELEPHONY_SERVICE");
        when(mTargetContext.getSystemService("TELEPHONY_SERVICE")).thenReturn(mTelephonyManager);
@@ -104,7 +111,7 @@ public class BluetoothMapSmsPduTest {
    @Test
    public void getSubmitPdus_withTypeGSM_whenMsgCountIsMoreThanOne() throws Exception {
        // Do not run test if sms is not supported
        Assume.assumeTrue(mSmsManager.isImsSmsSupported());
        assumeTrue(mSmsManager.isImsSmsSupported());
        when(mTelephonyManager.getCurrentPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM);

        List<SmsPdu> pdus =
@@ -133,7 +140,7 @@ public class BluetoothMapSmsPduTest {
    @Test
    public void getSubmitPdus_withTypeCDMA() throws Exception {
        // Do not run test if sms is not supported
        Assume.assumeTrue(mSmsManager.isImsSmsSupported());
        assumeTrue(mSmsManager.isImsSmsSupported());
        when(mTelephonyManager.getCurrentPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);

        List<SmsPdu> pdus = BluetoothMapSmsPdu.getSubmitPdus(mTargetContext, TEST_TEXT, null);
@@ -158,7 +165,7 @@ public class BluetoothMapSmsPduTest {
    @Test
    public void getDeliverPdus_withTypeGSM() throws Exception {
        // Do not run test if sms is not supported
        Assume.assumeTrue(mSmsManager.isImsSmsSupported());
        assumeTrue(mSmsManager.isImsSmsSupported());
        when(mTelephonyManager.getCurrentPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM);

        List<SmsPdu> pdus =
@@ -187,7 +194,7 @@ public class BluetoothMapSmsPduTest {
    @Test
    public void getDeliverPdus_withTypeCDMA() throws Exception {
        // Do not run test if sms is not supported
        Assume.assumeTrue(mSmsManager.isImsSmsSupported());
        assumeTrue(mSmsManager.isImsSmsSupported());
        when(mTelephonyManager.getCurrentPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);

        List<SmsPdu> pdus =