### Question:
CorePeripheral implements Peripheral { @Override public Completable write(UUID svc, UUID chr, byte[] data) { final SingleSubject<UUID> scopedSubject = SingleSubject.create(); return scopedSubject .filter(writeChr -> writeChr.equals(chr)) .ignoreElement() .doOnSubscribe(disposable -> processWrite(scopedSubject, svc, chr, data)) .doFinally(() -> clearWriteSubject(scopedSubject)); } 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 write_disconnected() { byte[] writeBytes = new byte[] {0x00}; writeTestObserver = corePeripheral.write(svcUuid, chrUuid, writeBytes).test(); writeTestObserver.assertError( throwable -> { PeripheralError error = (PeripheralError) throwable; return error != null && error.getCode() == DISCONNECTED; }); }