### Question:
CorePeripheral implements Peripheral { @Override public Observable<ConnectableState> connect() { if (sharedConnectionState != null) { return sharedConnectionState; } connectionStateSubject = BehaviorSubject.create(); sharedConnectionState = connectionStateSubject .doOnNext(state -> connectedRelay.accept(state == CONNECTED)) .doOnSubscribe(disposable -> processConnect()) .doFinally(() -> disconnect()) .replay(1) .refCount(); return sharedConnectionState; } CorePeripheral(BluetoothDevice device, Context context); @Override Observable<ConnectableState> connect(); @Override Observable<Boolean> connected(); @Override Single<byte[]> read(UUID svc, UUID chr); @Override Completable write(UUID svc, UUID chr, byte[] data); @Override Completable registerNotification(UUID svc, UUID chr); @Override Completable registerNotification(UUID svc, UUID chr, @Nullable Preprocessor preprocessor); @Override Completable unregisterNotification(UUID svc, UUID chr); @Override Observable<byte[]> notification(UUID chr); @TargetApi(21) @Override Single<Integer> requestMtu(int mtu); @Override Single<Integer> readRssi(); @Override int getMaxWriteLength(); @Override void disconnect();  }### Answer:
@Test public void connect_connectGattFailed() { when(bluetoothDevice.connectGatt(any(), anyBoolean(), any())).thenReturn(null); connectTestObserver = corePeripheral.connect().test(); connectTestObserver.assertError( throwable -> { ConnectionError error = (ConnectionError) throwable; if (error != null && error.getCode() == CONNECT_FAILED && error.getCause() != null && error.getCause() instanceof PeripheralError) { PeripheralError peripheralError = (PeripheralError) error.getCause(); return peripheralError.getErrorStatus() == ERROR_STATUS_CALL_FAILED; } return false; }); }
@Test public void connect_success() { connect(); connectTestObserver.assertValues(CONNECTING, CONNECTED); }
@Test public void connect_verifyMulticasted() { connect(); corePeripheral.connect().test(); verifyNoMoreInteractions(bluetoothGatt); }