### Question:
JellyBeanScanner implements Scanner { @Override public Observable<ScanData> scan() { return Observable.merge(sharedScanData, getErrorSubject().toObservable()); } JellyBeanScanner();  JellyBeanScanner(ParsedAdvertisement.Factory parsedAdDataFactory); @Override Observable<ScanData> scan(); @Override 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_share_inProgress() { when(bluetoothAdapter.isEnabled()).thenReturn(true); when(BluetoothAdapter.getDefaultAdapter()).thenReturn(bluetoothAdapter); scanner.scan().test(); scanDataTestObserver = scanner.scan().test(); scanDataTestObserver.assertNoErrors(); scanDataTestObserver.hasSubscription(); }
@Test public void scan_withMatches() { when(bluetoothAdapter.isEnabled()).thenReturn(true); when(BluetoothAdapter.getDefaultAdapter()).thenReturn(bluetoothAdapter); scanDataTestObserver = scanner.scan().test(); ArgumentCaptor<BluetoothAdapter.LeScanCallback> argument = ArgumentCaptor.forClass(BluetoothAdapter.LeScanCallback.class); verify(bluetoothAdapter).startLeScan(argument.capture()); argument.getValue().onLeScan(bluetoothDevice, 0, new byte[] {0x00}); scanDataTestObserver.assertValueCount(1); }