-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from agap/fix/no-check-for-ble-adapter-on-stop
Change the BluetoothAdapter state check to be run only on Android 5.0.
- Loading branch information
Showing
2 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
luch/src/test/java/aga/android/luch/SystemBleDeviceSdk23Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package aga.android.luch; | ||
|
||
import android.bluetooth.BluetoothAdapter; | ||
import android.bluetooth.le.BluetoothLeScanner; | ||
import android.bluetooth.le.ScanCallback; | ||
import android.bluetooth.le.ScanFilter; | ||
import android.bluetooth.le.ScanResult; | ||
import android.bluetooth.le.ScanSettings; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
@Config(sdk = 23, manifest = Config.NONE) | ||
public class SystemBleDeviceSdk23Test { | ||
private final BluetoothAdapter adapter = mock(BluetoothAdapter.class); | ||
|
||
private final BluetoothLeScanner scanner = mock(BluetoothLeScanner.class); | ||
|
||
private final ScanSettings scanSettings = new ScanSettings.Builder().build(); | ||
|
||
private final List<ScanFilter> scanFilters = Collections.emptyList(); | ||
|
||
private final ScanCallback scanCallback = new ScanCallback() { | ||
@Override | ||
public void onScanResult(int callbackType, ScanResult result) { | ||
super.onScanResult(callbackType, result); | ||
} | ||
}; | ||
|
||
private final SystemBleDevice device = new SystemBleDevice( | ||
getApplicationContext(), | ||
adapter, | ||
scanSettings, | ||
scanFilters | ||
); | ||
|
||
@Test | ||
public void testAttemptToStopScansIsMadeEvenIfAdapterIsDisabled() { | ||
// given | ||
when(adapter.getBluetoothLeScanner()).thenReturn(scanner); | ||
when(adapter.isEnabled()).thenReturn(false); | ||
|
||
// when | ||
device.stopScans(scanCallback); | ||
|
||
// then | ||
verify(adapter).getBluetoothLeScanner(); | ||
verifyNoMoreInteractions(adapter); | ||
|
||
verify(scanner).stopScan(scanCallback); | ||
verifyNoMoreInteractions(scanner); | ||
} | ||
} |