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

Commit 2adb8b89 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "Follow error prone recommendation"

parents 09dda605 a31e9787
Loading
Loading
Loading
Loading
+181 −81

File changed.

Preview size limit exceeded, changes collapsed.

+10 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.app.AlarmManager;
import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.bluetooth.IBluetoothCallback;
import android.content.AttributionSource;
import android.content.Context;
@@ -144,6 +145,7 @@ public class AdapterServiceTest {
    private final AttributionSource mAttributionSource = new AttributionSource.Builder(
            Process.myUid()).build();

    private BluetoothManager mBluetoothManager;
    private PowerManager mPowerManager;
    private PermissionCheckerManager mPermissionCheckerManager;
    private PackageManager mMockPackageManager;
@@ -233,6 +235,9 @@ public class AdapterServiceTest {
        mPermissionCheckerManager = InstrumentationRegistry.getTargetContext()
                .getSystemService(PermissionCheckerManager.class);

        mBluetoothManager = InstrumentationRegistry.getTargetContext()
                .getSystemService(BluetoothManager.class);

        when(mMockContext.getApplicationInfo()).thenReturn(mMockApplicationInfo);
        when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver);
        when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
@@ -264,6 +269,11 @@ public class AdapterServiceTest {
                .thenReturn(mBatteryStatsManager);
        when(mMockContext.getSystemServiceName(BatteryStatsManager.class))
                .thenReturn(Context.BATTERY_STATS_SERVICE);
        when(mMockContext.getSystemService(Context.BLUETOOTH_SERVICE))
                .thenReturn(mBluetoothManager);
        when(mMockContext.getSystemServiceName(BluetoothManager.class))
                .thenReturn(Context.BLUETOOTH_SERVICE);

        when(mMockContext.getAttributionSource()).thenReturn(mAttributionSource);
        doAnswer(invocation -> {
            Object[] args = invocation.getArguments();
+8 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static org.mockito.Mockito.*;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -56,6 +57,7 @@ public class BondStateMachineTest {
    private static final int BOND_BONDING = BluetoothDevice.BOND_BONDING;
    private static final int BOND_BONDED = BluetoothDevice.BOND_BONDED;

    private BluetoothManager mBluetoothManager;
    private AdapterProperties mAdapterProperties;
    private BluetoothDevice mDevice;
    private Context mTargetContext;
@@ -75,6 +77,12 @@ public class BondStateMachineTest {
        mHandlerThread = new HandlerThread("BondStateMachineTestHandlerThread");
        mHandlerThread.start();

        mBluetoothManager = mTargetContext.getSystemService(BluetoothManager.class);
        when(mAdapterService.getSystemService(Context.BLUETOOTH_SERVICE))
                .thenReturn(mBluetoothManager);
        when(mAdapterService.getSystemServiceName(BluetoothManager.class))
                .thenReturn(Context.BLUETOOTH_SERVICE);

        mRemoteDevices = new RemoteDevices(mAdapterService, mHandlerThread.getLooper());
        mRemoteDevices.reset();
        when(mAdapterService.getResources()).thenReturn(
+16 −0
Original line number Diff line number Diff line
@@ -8,7 +8,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAssignedNumbers;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.HandlerThread;
@@ -45,17 +47,31 @@ public class RemoteDevicesTest {
    private HandlerThread mHandlerThread;
    private TestLooperManager mTestLooperManager;

    private Context mTargetContext;
    private BluetoothManager mBluetoothManager;

    @Mock private AdapterService mAdapterService;

    @Before
    public void setUp() {
        mTargetContext = InstrumentationRegistry.getTargetContext();

        MockitoAnnotations.initMocks(this);
        mDevice1 = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(TEST_BT_ADDR_1);
        mHandlerThread = new HandlerThread("RemoteDevicesTestHandlerThread");
        mHandlerThread.start();
        mTestLooperManager = InstrumentationRegistry.getInstrumentation()
                .acquireLooperManager(mHandlerThread.getLooper());

        mBluetoothManager = mTargetContext.getSystemService(BluetoothManager.class);
        when(mAdapterService.getSystemService(Context.BLUETOOTH_SERVICE))
                .thenReturn(mBluetoothManager);
        when(mAdapterService.getSystemServiceName(BluetoothManager.class))
                .thenReturn(Context.BLUETOOTH_SERVICE);

        mRemoteDevices = new RemoteDevices(mAdapterService, mHandlerThread.getLooper());
        verify(mAdapterService, times(1)).getSystemService(Context.BLUETOOTH_SERVICE);
        verify(mAdapterService, times(1)).getSystemService(BluetoothManager.class);
    }

    @After