@Test
public void getConnectedPeripheralsTest() throws Exception {

    application.grantPermissions(Manifest.permission.ACCESS_COARSE_LOCATION);
    BluetoothPeripheral peripheral = mock(BluetoothPeripheral.class);
    when(peripheral.getAddress()).thenReturn("12:23:34:98:76:54");
    when(peripheral.getType()).thenReturn(BluetoothDevice.DEVICE_TYPE_LE);
    central.connectPeripheral(peripheral, peripheralCallback);
    verify(peripheral).connect();
    // Grab the scan callback that is used
    Field field = BluetoothCentral.class.getDeclaredField("internalCallback");
    field.setAccessible(true);
    BluetoothPeripheral.InternalCallback internalCallback = (BluetoothPeripheral.InternalCallback) field.get(central);
    // Give connected event and see if we get callback
    internalCallback.connected(peripheral);
    verify(callback).onConnectedPeripheral(peripheral);
    List<BluetoothPeripheral> peripherals = central.getConnectedPeripherals();
    assertNotNull(peripherals);
    assertEquals(1, peripherals.size());
    assertEquals(peripheral, peripherals.get(0));
    peripheral.cancelConnection();
    internalCallback.disconnected(peripheral, GATT_SUCCESS);
    List<BluetoothPeripheral> peripherals2 = central.getConnectedPeripherals();
    assertNotNull(peripherals2);
    assertEquals(0, peripherals2.size());
}