### Question:
LollipopScanner implements Scanner { @Override @Deprecated public Observable<ScanData> scan() { if (scanDataSubject != null) { return Observable.error(new ConnectionError(SCAN_IN_PROGRESS)); } this.scanDataSubject = PublishSubject.create(); return scanDataSubject .doOnSubscribe( d -> { if (scanDataSubject != null) { startScan(scanDataSubject); } }) .doFinally(this::stopScan) .share(); } @Deprecated  LollipopScanner(); @Deprecated  LollipopScanner(ParsedAdvertisement.Factory parsedAdDataFactory); @Override @Deprecated Observable<ScanData> scan(); @Override @Deprecated Observable<ScanData> scan(int scanLatency);  }### Answer:
@Test public void scan_failed_bluetoothUnsupported() { when(BluetoothAdapter.getDefaultAdapter()).thenReturn(null); scanDataTestObserver = scanner.scan().test(); scanDataTestObserver.assertError( throwable -> { ConnectionError error = (ConnectionError) throwable; return error != null && error.getCode() == ConnectionError.Code.SCAN_FAILED; }); }
@Test public void scan_failed_bluetoothOff() { when(bluetoothAdapter.isEnabled()).thenReturn(false); when(BluetoothAdapter.getDefaultAdapter()).thenReturn(bluetoothAdapter); scanDataTestObserver = scanner.scan().test(); scanDataTestObserver.assertError( throwable -> { ConnectionError error = (ConnectionError) throwable; return error != null && error.getCode() == ConnectionError.Code.SCAN_FAILED; }); }
@Test public void scan_failed_inProgress() { when(bluetoothAdapter.isEnabled()).thenReturn(true); when(BluetoothAdapter.getDefaultAdapter()).thenReturn(bluetoothAdapter); scanner.scan().test(); scanDataTestObserver = scanner.scan().test(); scanDataTestObserver.assertError( throwable -> { ConnectionError error = (ConnectionError) throwable; return error != null && error.getCode() == ConnectionError.Code.SCAN_IN_PROGRESS; }); }