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

Commit 12c3ea47 authored by William Escande's avatar William Escande
Browse files

Fix companionManager test

presubmit were disabled and we miss the mock of shared pref + companion

Test: atest BluetoothInstrumentationTests:
Bug: 263323082
Fix: 266002878
Change-Id: I79a0674e8a48a43d901337ec63a30089567e5cb7
parent dcf43b85
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class CompanionManager {
    private final BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
    private final Set<BluetoothDevice> mMetadataListeningDevices = new HashSet<>();

    CompanionManager(AdapterService service, ServiceFactory factory) {
    public CompanionManager(AdapterService service, ServiceFactory factory) {
        mAdapterService = service;
        mGattConnHighDefault = new int[] {
                service.getResources().getInteger(R.integer.gatt_high_priority_min_interval),
+3 −0
Original line number Diff line number Diff line
@@ -290,6 +290,9 @@ public class AdapterServiceTest {
                .thenReturn(mBluetoothManager);
        when(mMockContext.getSystemServiceName(BluetoothManager.class))
                .thenReturn(Context.BLUETOOTH_SERVICE);
        when(mMockContext.getSharedPreferences(anyString(), anyInt()))
                .thenReturn(InstrumentationRegistry.getTargetContext()
                        .getSharedPreferences("AdapterServiceTestPrefs", Context.MODE_PRIVATE));

        when(mMockContext.getAttributionSource()).thenReturn(mAttributionSource);
        doAnswer(invocation -> {
+13 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.content.AttributionSource;
import android.content.Context;
import android.content.res.Resources;
import android.os.Binder;
import android.os.ParcelUuid;
import android.os.RemoteException;
@@ -54,6 +55,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.CompanionManager;

import org.junit.After;
import org.junit.Assert;
@@ -102,10 +104,12 @@ public class GattServiceTest {
    private BluetoothAdapter mAdapter;
    private AttributionSource mAttributionSource;

    @Mock private Resources mResources;
    @Mock private AdapterService mAdapterService;
    @Mock private GattObjectsFactory mFactory;
    @Mock private GattNativeInterface mNativeInterface;
    private BluetoothDevice mCurrentDevice;
    private CompanionManager mBtCompanionManager;

    @Before
    public void setUp() throws Exception {
@@ -122,6 +126,15 @@ public class GattServiceTest {
        mAttributionSource = mAdapter.getAttributionSource();
        mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_ADDRESS);

        when(mAdapterService.getResources()).thenReturn(mResources);
        when(mResources.getInteger(anyInt())).thenReturn(0);
        when(mAdapterService.getSharedPreferences(anyString(), anyInt()))
                .thenReturn(InstrumentationRegistry.getTargetContext()
                        .getSharedPreferences("GattServiceTestPrefs", Context.MODE_PRIVATE));

        mBtCompanionManager = new CompanionManager(mAdapterService, null);
        doReturn(mBtCompanionManager).when(mAdapterService).getCompanionManager();

        TestUtils.startService(mServiceRule, GattService.class);
        mService = GattService.getGattService();
        Assert.assertNotNull(mService);