@Test
public void stopScanTest() 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);
    // Stop scan
    central.stopScan();
    // Check if scan is correctly stopped
    verify(scanner).stopScan(scanCallback);
    // Stop scan again
    central.stopScan();
    // Verify that stopScan is not called again
    verify(scanner, times(1)).stopScan(any(ScanCallback.class));
}