@Test
public void scanForPeripheralsTest()  throws Exception {

    application.grantPermissions(Manifest.permission.ACCESS_COARSE_LOCATION);
    central.scanForPeripherals();
    verify(scanner).startScan(anyList(), any(ScanSettings.class), any(ScanCallback.class));
    // Grab the scan callback that is used
    Field field = BluetoothCentral.class.getDeclaredField("defaultScanCallback");
    field.setAccessible(true);
    ScanCallback scanCallback = (ScanCallback) field.get(central);
    // Fake scan result
    ScanResult scanResult = mock(ScanResult.class);
    BluetoothDevice device = mock(BluetoothDevice.class);
    when(device.getAddress()).thenReturn("12:23:34:98:76:54");
    when(scanResult.getDevice()).thenReturn(device);
    bluetoothAdapter.addDevice(device);
    scanCallback.onScanResult(CALLBACK_TYPE_ALL_MATCHES, scanResult);
    // See if we get it back
    ArgumentCaptor<BluetoothPeripheral> bluetoothPeripheralCaptor = ArgumentCaptor.forClass(BluetoothPeripheral.class);
    ArgumentCaptor<ScanResult> scanResultCaptor = ArgumentCaptor.forClass(ScanResult.class);
    verify(callback).onDiscoveredPeripheral(bluetoothPeripheralCaptor.capture(), scanResultCaptor.capture());
    assertEquals(scanResultCaptor.getValue(), scanResult);
    assertEquals(bluetoothPeripheralCaptor.getValue().getAddress(), "12:23:34:98:76:54");
}