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

Commit 5455ef89 authored by Vasu Nori's avatar Vasu Nori
Browse files

Fix bugs in tests which fail when Bluettoth is turned off.

on internal gerritt, this is ag/3738365

Bug: 74609188
Test: tested manually: runtest bluetooth
Change-Id: I01af14906f44b21838a46a5a30a19b1cda5fcc03
(cherry picked from commit cc27a3dcc0f4d1bf09641c992d230b2eeeed0f21)
parent e02f912c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.telephony.SmsManager;
import android.util.Log;

import com.android.bluetooth.btservice.ProfileService;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IState;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
@@ -120,7 +121,13 @@ final class MceStateMachine extends StateMachine {
    private Bmessage.Type mDefaultMessageType = Bmessage.Type.SMS_CDMA;

    MceStateMachine(MapClientService service, BluetoothDevice device) {
        this(service, device, null);
    }

    @VisibleForTesting
    MceStateMachine(MapClientService service, BluetoothDevice device, MasClient masClient) {
        super(TAG);
        mMasClient = masClient;
        mService = service;

        mPreviousState = BluetoothProfile.STATE_DISCONNECTED;
+14 −4
Original line number Diff line number Diff line
@@ -40,13 +40,18 @@ import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

@MediumTest
@RunWith(AndroidJUnit4.class)
public class MapClientStateMachineTest {
    private static final String TAG = MapClientStateMachineTest.class.getSimpleName();
    private static final String TAG = "MapStateMachineTest";
    private static final Integer TIMEOUT = 3000;

    private BluetoothAdapter mAdapter;
    private MceStateMachine mMceStateMachine = null;
    private BluetoothDevice mTestDevice;
@@ -56,9 +61,13 @@ public class MapClientStateMachineTest {
    private CountDownLatch mLock = null;
    private Handler mHandler;

    @Mock
    private MasClient mMockMasClient;


    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mTargetContext = InstrumentationRegistry.getTargetContext();
        Assume.assumeTrue("Ignore test when MapClientService is not enabled",
                mTargetContext.getResources().getBoolean(R.bool.profile_supported_mapmce));
@@ -70,7 +79,8 @@ public class MapClientStateMachineTest {

        mLock = new CountDownLatch(1);
        mFakeMapClientService = new FakeMapClientService(mLock);
        mMceStateMachine = new MceStateMachine(mFakeMapClientService, mTestDevice);
        when(mMockMasClient.makeRequest(any(Request.class))).thenReturn(true);
        mMceStateMachine = new MceStateMachine(mFakeMapClientService, mTestDevice, mMockMasClient);
        Assert.assertNotNull(mMceStateMachine);
        if (Looper.myLooper() == null) {
            Looper.prepare();
@@ -112,11 +122,11 @@ public class MapClientStateMachineTest {
        // to MapClientService to change
        // state from STATE_CONNECTING to STATE_CONNECTED
        try {
            mLock.await();
            mLock.await(TIMEOUT, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Assert.assertNotNull(mMceStateMachine.getCurrentState());
        Assert.assertEquals(BluetoothProfile.STATE_CONNECTED, mMceStateMachine.getState());
    }