title: How to assert if a Completable has been subscribed/completed (RxJava2)
body: <p>I'm having trouble identifying if a <code>Completable</code> has been subscribed to in my tests, for example:</p>
  
  <pre><code>interface IWebApi {
      Observable&lt;Data&gt; download();
  }
  
  interface IDataRepository {
      Completable insert(Data data);
  }
  
  class SyncService {
  
      IWebApi webApi;
      IDataRepository repository;
  
      public SyncService(IWebApi webApi, IDataRepository repository) {
          this.webApi = webApi;
          this.repository = repository;
      }
  
      public Completable sync() {
          return webApi.download()
              .flatMapCompletable((Data data) -&gt; { repository.insert(data) })
      }
  }
  </code></pre>
  
  <p>And then in my tests:</p>
  
  <pre><code>@Test
  public void syncTest() {
      Data data = new Data();
      IDataRepository repository = mock (IDataRepository.class);
      IWebApi webApi = mock (IWebApi.class);
  
      given(webApi.download()).willReturn(Observable.just(data));
      given(repository.insert(data)).willReturn(Completable.complete());
  
      TestObserver&lt;Void&gt; observer = new TestObserver&lt;Void&gt;();
      SyncService service = new SyncService(webApi, repository);
      service.sync()
              .subscribe(observer);
  
      observer.assertComplete();
      verify(repository).insert(data);
  }
  </code></pre>
  
  <p>This test will pass. But I Could rewrite the sync method without using <code>flatMapCompletable</code> like this:</p>
  
  <pre><code>    public Completable sync() {
          return webApi.download()
              .doOnNext((Data data) -&gt; { repository.insert(data) })
              .ignoreElements();
      }
  </code></pre>
  
  <p>Then my tests would pass but code would not work because even thought I've called the insert method, I've not called <code>subscribe()</code> in it.</p>
  
  <p>How should I proceed about this?</p>
  
  <p>P.S I am new to RxJava so if I am not using the best practices I would love to know :)</p>
  
  <p><strong>Update</strong></p>
  
  <p>Fixed the mistake of not calling <code>.ingnoreElements()</code> pointed by Maxim Ostrovidov </p>