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

Commit e02f96af authored by David Duarte's avatar David Duarte
Browse files

MapClientTest: Pass mock MnsService in constructor

Bug: 319112725
Test: atest MapClientTest
Flag: Exempt, test change
Change-Id: I5270d07ba3ef89a9b87dfb2bf8d65c48e7c54fd9
parent 4f572bd6
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -74,9 +74,10 @@ public class MapClientService extends ProfileService {
    }

    @VisibleForTesting
    MapClientService(Context ctx, Looper looper) {
    MapClientService(Context ctx, Looper looper, MnsService mnsServer) {
        this(ctx);
        mSmLooper = looper;
        mMnsServer = mnsServer;
    }

    public static boolean isEnabled() {
@@ -329,12 +330,7 @@ public class MapClientService extends ProfileService {
        mHandler = new Handler(Looper.getMainLooper());

        if (mMnsServer == null) {
            mMnsServer = MapUtils.newMnsServiceInstance(this);
            if (mMnsServer == null) {
                // this can't happen
                Log.w(TAG, "MnsService is *not* created!");
                return false;
            }
            mMnsServer = new MnsService(this);
        }

        removeUncleanAccounts();
+0 −10
Original line number Diff line number Diff line
@@ -19,27 +19,17 @@ import android.os.Binder;
import android.os.SystemProperties;

import com.android.bluetooth.Utils;
import com.android.internal.annotations.VisibleForTesting;

class MapUtils {
    private static MnsService sMnsService = null;
    private static final String FETCH_MESSAGE_TYPE =
            "persist.bluetooth.pts.mapclient.fetchmessagetype";
    private static final String SEND_MESSAGE_TYPE =
            "persist.bluetooth.pts.mapclient.sendmessagetype";

    @VisibleForTesting
    static void setMnsService(MnsService service) {
        sMnsService = service;
    }

    static boolean isSystemUser() {
        return Binder.getCallingUserHandle().isSystem();
    }

    static MnsService newMnsServiceInstance(MapClientService mapClientService) {
        return (sMnsService == null) ? new MnsService(mapClientService) : sMnsService;
    }
    static byte fetchMessageType() {
        if (Utils.isPtsTestMode()) {
            return (byte) SystemProperties.getInt(FETCH_MESSAGE_TYPE,
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package com.android.bluetooth.mapclient;

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

import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
@@ -73,7 +72,8 @@ public class MapClientServiceTest {

        mTestLooper = new TestLooper();

        mService = new MapClientService(targetContext, mTestLooper.getLooper());
        MnsService mnsServer = null;
        mService = new MapClientService(targetContext, mTestLooper.getLooper(), mnsServer);
        mService.doStart();

        // Try getting the Bluetooth adapter
+3 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.os.Looper;
import android.os.UserHandle;

import androidx.test.InstrumentationRegistry;
@@ -67,9 +68,9 @@ public class MapClientTest {
        TestUtils.setAdapterService(mAdapterService);
        mIsAdapterServiceSet = true;
        when(mAdapterService.getDatabase()).thenReturn(mDatabaseManager);
        MapUtils.setMnsService(mMockMnsService);
        mIsMapClientServiceStarted = true;
        mService = new MapClientService(mTargetContext);
        Looper looper = null;
        mService = new MapClientService(mTargetContext, looper, mMockMnsService);
        mService.doStart();
        mAdapter = BluetoothAdapter.getDefaultAdapter();
    }