@Test public void testNoExceptionIsThrownWhileTryingToStopScansWhenThereIsNoBleScanner() { when(adapter.getBluetoothLeScanner()).thenReturn(null); when(adapter.isEnabled()).thenReturn(true); device.stopScans(scanCallback); verify(adapter).isEnabled(); verify(adapter).getBluetoothLeScanner(); verifyNoMoreInteractions(adapter); }
@Override public void stopScans(@NonNull ScanCallback scanCallback) { try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "Can't stop the BLE scans since BluetoothAdapter is not enabled, most likely " + "the scans weren't started either (check if Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "Can't stop the BLE scans since there is no BluetoothLeScanner available, " + "most likely the scans weren't started either (check if Bluetooth is " + "turned on)" ); return; } bleScanner.stopScan(scanCallback); } catch (SecurityException e) { BeaconLogger.e( "Can't stop the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } }
SystemBleDevice implements IBleDevice { @Override public void stopScans(@NonNull ScanCallback scanCallback) { try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "Can't stop the BLE scans since BluetoothAdapter is not enabled, most likely " + "the scans weren't started either (check if Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "Can't stop the BLE scans since there is no BluetoothLeScanner available, " + "most likely the scans weren't started either (check if Bluetooth is " + "turned on)" ); return; } bleScanner.stopScan(scanCallback); } catch (SecurityException e) { BeaconLogger.e( "Can't stop the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } } }
SystemBleDevice implements IBleDevice { @Override public void stopScans(@NonNull ScanCallback scanCallback) { try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "Can't stop the BLE scans since BluetoothAdapter is not enabled, most likely " + "the scans weren't started either (check if Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "Can't stop the BLE scans since there is no BluetoothLeScanner available, " + "most likely the scans weren't started either (check if Bluetooth is " + "turned on)" ); return; } bleScanner.stopScan(scanCallback); } catch (SecurityException e) { BeaconLogger.e( "Can't stop the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } } SystemBleDevice(Context context,
                    BluetoothAdapter bluetoothAdapter,
                    ScanSettings scanSettings,
                    List<ScanFilter> scanFilters); }
SystemBleDevice implements IBleDevice { @Override public void stopScans(@NonNull ScanCallback scanCallback) { try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "Can't stop the BLE scans since BluetoothAdapter is not enabled, most likely " + "the scans weren't started either (check if Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "Can't stop the BLE scans since there is no BluetoothLeScanner available, " + "most likely the scans weren't started either (check if Bluetooth is " + "turned on)" ); return; } bleScanner.stopScan(scanCallback); } catch (SecurityException e) { BeaconLogger.e( "Can't stop the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } } SystemBleDevice(Context context,
                    BluetoothAdapter bluetoothAdapter,
                    ScanSettings scanSettings,
                    List<ScanFilter> scanFilters); @Override void startScans(@NonNull ScanCallback scanCallback); @Override void stopScans(@NonNull ScanCallback scanCallback); }
SystemBleDevice implements IBleDevice { @Override public void stopScans(@NonNull ScanCallback scanCallback) { try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "Can't stop the BLE scans since BluetoothAdapter is not enabled, most likely " + "the scans weren't started either (check if Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "Can't stop the BLE scans since there is no BluetoothLeScanner available, " + "most likely the scans weren't started either (check if Bluetooth is " + "turned on)" ); return; } bleScanner.stopScan(scanCallback); } catch (SecurityException e) { BeaconLogger.e( "Can't stop the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } } SystemBleDevice(Context context,
                    BluetoothAdapter bluetoothAdapter,
                    ScanSettings scanSettings,
                    List<ScanFilter> scanFilters); @Override void startScans(@NonNull ScanCallback scanCallback); @Override void stopScans(@NonNull ScanCallback scanCallback);  }