@Test public void testApplySettings_FailedApplyAdvertiserSettings() throws Exception { int manufacturerId = 77; int beaconAdLengthAndType = DiscoveryManagerSettings.DEFAULT_BEACON_AD_LENGTH_AND_TYPE; int beaconAdExtraInformation = PeerProperties.NO_EXTRA_INFORMATION; BlePeerDiscoverer.AdvertisementDataType advertisementDataType = BlePeerDiscoverer.AdvertisementDataType.DO_NOT_CARE; int advertiseMode = AdvertiseSettings.ADVERTISE_MODE_LOW_POWER; int advertiseTxPowerLevel = AdvertiseSettings.ADVERTISE_TX_POWER_ULTRA_LOW; int scanMode = ScanSettings.SCAN_MODE_LOW_LATENCY; long scanReportDelayInMilliseconds = 10L; when(mMockAdvertiseSettingsBuilder.setAdvertiseMode(anyInt())).thenThrow(IllegalArgumentException.class); when(mMockAdvertiseSettingsBuilder.build()).thenReturn(mMockAdvertiseSettings); when(mMockScanSettingsBuilder.build()).thenReturn(mMockScanSettings); AdvertisementData advertisementData = new AdvertisementData(manufacturerId, beaconAdLengthAndType, beaconAdExtraInformation, advertisementDataType); boolean retVal = blePeerDiscoverer.applySettings(advertisementData, advertiseMode, advertiseTxPowerLevel, scanMode, scanReportDelayInMilliseconds, mMockAdvertiseSettingsBuilder, mMockScanSettingsBuilder); verify(mMockAdvertiseSettingsBuilder, never()).setTxPowerLevel(anyInt()); verify(mMockAdvertiseSettingsBuilder, never()).setTimeout(anyInt()); verify(mMockAdvertiseSettingsBuilder, never()).setConnectable(anyBoolean()); verify(mMockBleAdvertiser, never()).setAdvertiseSettings(any(AdvertiseSettings.class)); verify(mMockScanSettingsBuilder, times(1)).setScanMode(scanMode); verify(mMockScanSettingsBuilder, times(1)).setReportDelay(scanReportDelayInMilliseconds); verify(mMockBleScanner, times(1)).setScanSettings(mMockScanSettings); assertThat("it returns false as failed to set the settings for the BLE advertiser", retVal, is(false)); }
public boolean applySettings(AdvertisementData advertisementData, int advertiseMode, int advertiseTxPowerLevel, int scanMode, long scanReportDelayInMilliseconds) { return this.applySettings(advertisementData, advertiseMode, advertiseTxPowerLevel, scanMode, scanReportDelayInMilliseconds, new AdvertiseSettings.Builder(), new ScanSettings.Builder()); }
BlePeerDiscoverer implements BleAdvertiser.Listener, BleScanner.Listener { public boolean applySettings(AdvertisementData advertisementData, int advertiseMode, int advertiseTxPowerLevel, int scanMode, long scanReportDelayInMilliseconds) { return this.applySettings(advertisementData, advertiseMode, advertiseTxPowerLevel, scanMode, scanReportDelayInMilliseconds, new AdvertiseSettings.Builder(), new ScanSettings.Builder()); } }
BlePeerDiscoverer implements BleAdvertiser.Listener, BleScanner.Listener { public boolean applySettings(AdvertisementData advertisementData, int advertiseMode, int advertiseTxPowerLevel, int scanMode, long scanReportDelayInMilliseconds) { return this.applySettings(advertisementData, advertiseMode, advertiseTxPowerLevel, scanMode, scanReportDelayInMilliseconds, new AdvertiseSettings.Builder(), new ScanSettings.Builder()); } BlePeerDiscoverer(
            BlePeerDiscoveryListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceUuid, UUID provideBluetoothMacAddressRequestUuid,
            String myBluetoothMacAddress,
            AdvertisementData advertisementData);   BlePeerDiscoverer(BlePeerDiscoveryListener listener, BluetoothAdapter bluetoothAdapter,
                      UUID serviceUuid, UUID provideBluetoothMacAddressRequestUuid,
                      String myBluetoothMacAddress, AdvertisementData advertisementData,
                      BleAdvertiser bleAdvertiser, BleScanner bleScanner); }
BlePeerDiscoverer implements BleAdvertiser.Listener, BleScanner.Listener { public boolean applySettings(AdvertisementData advertisementData, int advertiseMode, int advertiseTxPowerLevel, int scanMode, long scanReportDelayInMilliseconds) { return this.applySettings(advertisementData, advertiseMode, advertiseTxPowerLevel, scanMode, scanReportDelayInMilliseconds, new AdvertiseSettings.Builder(), new ScanSettings.Builder()); } BlePeerDiscoverer(
            BlePeerDiscoveryListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceUuid, UUID provideBluetoothMacAddressRequestUuid,
            String myBluetoothMacAddress,
            AdvertisementData advertisementData);   BlePeerDiscoverer(BlePeerDiscoveryListener listener, BluetoothAdapter bluetoothAdapter,
                      UUID serviceUuid, UUID provideBluetoothMacAddressRequestUuid,
                      String myBluetoothMacAddress, AdvertisementData advertisementData,
                      BleAdvertiser bleAdvertiser, BleScanner bleScanner); static UUID generateNewProvideBluetoothMacAddressRequestUuid(UUID serviceUuid); EnumSet<BlePeerDiscovererStateSet> getState(); String getProvideBluetoothMacAddressRequestId(); String getBluetoothMacAddress(); void setBluetoothMacAddress(String myBluetoothMacAddress); boolean applySettings(AdvertisementData advertisementData, int advertiseMode,
                                 int advertiseTxPowerLevel, int scanMode, long scanReportDelayInMilliseconds); synchronized boolean startScanner(); synchronized void stopScanner(); synchronized boolean startAdvertiser(); synchronized void stopAdvertiser(); synchronized boolean startScannerAndAdvertiser(); synchronized void stopScannerAndAdvertiser(); synchronized boolean startPeerAddressHelperAdvertiser(
            final String requestId, String bluetoothMacAddress, long durationInMilliseconds); @Override void onAdvertiserFailedToStart(int errorCode); @Override void onIsAdvertiserStartedChanged(boolean isStarted); @Override void onScannerFailed(int errorCode); @Override void onIsScannerStartedChanged(boolean isStarted); @Override void onScanResult(ScanResult result); @Override void onBatchScanResults(List<ScanResult> results); void releaseListener(); }
BlePeerDiscoverer implements BleAdvertiser.Listener, BleScanner.Listener { public boolean applySettings(AdvertisementData advertisementData, int advertiseMode, int advertiseTxPowerLevel, int scanMode, long scanReportDelayInMilliseconds) { return this.applySettings(advertisementData, advertiseMode, advertiseTxPowerLevel, scanMode, scanReportDelayInMilliseconds, new AdvertiseSettings.Builder(), new ScanSettings.Builder()); } BlePeerDiscoverer(
            BlePeerDiscoveryListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceUuid, UUID provideBluetoothMacAddressRequestUuid,
            String myBluetoothMacAddress,
            AdvertisementData advertisementData);   BlePeerDiscoverer(BlePeerDiscoveryListener listener, BluetoothAdapter bluetoothAdapter,
                      UUID serviceUuid, UUID provideBluetoothMacAddressRequestUuid,
                      String myBluetoothMacAddress, AdvertisementData advertisementData,
                      BleAdvertiser bleAdvertiser, BleScanner bleScanner); static UUID generateNewProvideBluetoothMacAddressRequestUuid(UUID serviceUuid); EnumSet<BlePeerDiscovererStateSet> getState(); String getProvideBluetoothMacAddressRequestId(); String getBluetoothMacAddress(); void setBluetoothMacAddress(String myBluetoothMacAddress); boolean applySettings(AdvertisementData advertisementData, int advertiseMode,
                                 int advertiseTxPowerLevel, int scanMode, long scanReportDelayInMilliseconds); synchronized boolean startScanner(); synchronized void stopScanner(); synchronized boolean startAdvertiser(); synchronized void stopAdvertiser(); synchronized boolean startScannerAndAdvertiser(); synchronized void stopScannerAndAdvertiser(); synchronized boolean startPeerAddressHelperAdvertiser(
            final String requestId, String bluetoothMacAddress, long durationInMilliseconds); @Override void onAdvertiserFailedToStart(int errorCode); @Override void onIsAdvertiserStartedChanged(boolean isStarted); @Override void onScannerFailed(int errorCode); @Override void onIsScannerStartedChanged(boolean isStarted); @Override void onScanResult(ScanResult result); @Override void onBatchScanResults(List<ScanResult> results); void releaseListener();  }