title: Testing RxJava2 doOnComplete()
body: <p>As you can see from the code below, I am attempting to test the behavior of the <code>doOnComplete()</code> call occurring within my repository. However, when I mock the injected dependency of my client where I return items using <code>Observable.just()</code>, the <code>doOnComplete()</code> is no longer invoked. I believe this is intentional as per RxJava2. I'm unsure as to how to work around this.</p>
  
  <pre><code>@Singleton
  public class Repository {
      private SomeNetworkClient client;
      private SomeCache cache;
  
      @Inject
      public Repository(SomeNetworkClient client, SomeCache cache) {
          this.client = client;
          this.cache = cache;
      }
  
      public Observable&lt;SomeItem&gt; getSomeItem() {
          return client.getSomeItem()
                  .doOnComplete(() -&gt; cache.doThisOnComplete())
                  .doOnError(throwable -&gt; someError);
      }
  }
  
  public class RepositoryTest {
      private Repository testedRepository;
      @Mock
      SomeNetworkClient client;
      @Mock
      SomeCache cache;
      @Mock
      SomeItem someItem;
  
      @Before
      public void setup() {
          MockitoAnnotations.initMocks(this);
          testedRepository = new Repository(client, cache);
          when(client.getSomeItem())
              .thenReturn(Observable.just(someItem));
      }
  
      @Test
      public void thisTestFails() {
          testedRepository.getSomeItem().blockingFirst();
          // This fails because it appears that mocking with
          // Observable.just() makes doOnComplete() not be invoked.
          verify(cache.doThisOnComplete());
      }
  }
  </code></pre>