### Question:
CoreConnectionManager implements ConnectionManager { @Override public Observable<Peripheral> connect( ScanMatcher scanMatcher, int scanTimeoutMs, int connectionTimeoutMs) { if (this.scanMatcher != null && !this.scanMatcher.equals(scanMatcher)) { return Observable.error(new ConnectionError(CONNECTION_IN_PROGRESS)); } else if (sharedPeripheralObservable != null) { return sharedPeripheralObservable; } this.scanTimeoutMs = scanTimeoutMs; this.connectionTimeoutMs = connectionTimeoutMs; this.scanMatcher = scanMatcher; this.sharedPeripheralObservable = bluetoothDetector .enabled() .distinctUntilChanged() .filter(enabled -> enabled) .compose(scan(scanner, scanMatcher)) .switchMap(scanData -> connect(scanData.getBluetoothDevice())) .compose(shareConnection()); return sharedPeripheralObservable; } CoreConnectionManager(Context context);  CoreConnectionManager(Context context, BluetoothDetector bluetoothDetector);  CoreConnectionManager(Context context,
                               BluetoothDetector bluetoothDetector,
                               Peripheral.Factory peripheralFactory);  CoreConnectionManager(
          Context context,
          BluetoothDetector bluetoothDetector,
          Peripheral.Factory peripheralFactory,
          Scanner.Factory scannerFactory);  CoreConnectionManager(
          Context context,
          BluetoothDetector bluetoothDetector,
          Scanner scanner,
          Peripheral.Factory peripheralFactory); @Override Observable<Peripheral> connect(
          ScanMatcher scanMatcher, int scanTimeoutMs, int connectionTimeoutMs); @Override Observable<Peripheral> connect(BluetoothDevice bluetoothDevice, int connectionTimeoutMs); @Override Observable<State> state();  }### Answer:
@Test public void connect_failed_connectionInProgress() { prepareConnect(false); TestObserver<Peripheral> secondConnect = coreConnectionManager .connect( scanMatcher2, DEFAULT_SCAN_TIMEOUT, ConnectionManager.DEFAULT_CONNECTION_TIMEOUT) .test(); secondConnect.assertError( throwable -> { ConnectionError error = (ConnectionError) throwable; return error != null && error.getCode() == ConnectionError.Code.CONNECTION_IN_PROGRESS; }); }
@Test public void connect_multicasted_for_equalScanMatcher() { prepareConnect(true); TestObserver<Peripheral> secondConnect = coreConnectionManager .connect( scanMatcher2, DEFAULT_SCAN_TIMEOUT, ConnectionManager.DEFAULT_CONNECTION_TIMEOUT) .test(); secondConnect.assertNoErrors(); }