title: How to write RXjava 2 test for a behavior subject abstracted behind an interface
body: <p>I have a behavior subject that will be DI. I then have different interfaces, that subscribe to that object. Below is a super simple one I am writing so that I can mostly restrict access to the subjects onNext() function. I am not able to figure out how to write a test for this in jUnit. This is RXjava2. I see a lot of blog posts that talk about tests Observers, testScheduler and so on, but none of them seem to block till a RX observable receives the next element.. My abstraction is not helping so I cant play with test observers and test observables, but is a requirement. </p>
  
  <pre><code>fun subscribe(subscribeThread: Scheduler, observeThread: Scheduler, next: Consumer&lt;Location&gt;, throwable: Consumer&lt;Throwable&gt;): Disposable {
      return publishSubject
              .subscribeOn(subscribeThread)
              .observeOn(observeThread)
              .subscribe(next, throwable)
  }
  </code></pre>
  
  <p>I have my tests..</p>
  
  <pre><code> private var consumerResult: Consumer&lt;Val&gt; = Consumer { count++ }
  
     @Test
      fun `dispose custom and receive updates`() {
  
      var disposable = myObserver.subscribe(testScheduler, testScheduler, consumerResult, consumerThrowable)
      assertNotNull(disposable)
      assertEquals(0, count)
      subject.onNext(mockVal)
      assertEquals(1, count) // FAILS
  }
  </code></pre>
  
  <p>Which yes I expect it to fail as this is an async call. However I am not able to figure out how to write this so I can test my code.. Note this is the first step in a much larger complicated test </p>