Mockito Wanted but not Invoked
<p>I'm new to writing tests and using Mockito.
I've read the similar topics here on Stackoverflow and made the suggested changes, making sure that regarded classes / interfaces / methods are open.</p>

<blockquote>
  <p><a href="https://stackoverflow.com/questions/31411917/verify-interactions-in-rxjava-subscribers">I tried to follow this</a></p>
</blockquote>

<p>Mocking the constructor injected dependencies</p>

<p>This is the test I came up with so far</p>

<pre><code>class RegistrationPresenterTest {
@Test
fun testRegisterSuccess() {
    val mockService = mock&lt;IHerokuInteractor&gt;()
    val mockLocal = mock&lt;ILocalStorageInteractor&gt;()
    val mockView = mock&lt;RegisterView&gt;()
    val mockRegistrationResponse = HerokuRegisterResponse("hash")
    val mockPair = ImeiPair("imei","hash")
    val presenter = RegisterPresenterImpl(mockLocal,mockService)

   whenever(mockService.register(any())).thenReturn(Observable.just(mockRegistrationResponse))
    whenever(mockLocal.clearPreferences()).thenReturn(Observable.just(true))
    whenever(mockLocal.putImeiPair(any())).thenReturn(Observable.just(true))
    //whenever(presenter.writeImeiPairLocally(any())) How do I specify parameters since it uses a parameter from the register method?

    presenter.bindView(mockView)
    presenter.register("imei","male")

    verify(mockService, times(1)).register(any())
    verify(mockLocal,times(1)).clearPreferences()
    verify(mockLocal,times(1)).putImeiPair(any())
    verify(mockView,times(1)).moveToMain()
}
</code></pre>

<p>but the response I keep getting is</p>

<pre><code>Wanted but not invoked:
registerPresenterImpl.writeImeiPairLocally(
&lt;any com.company.appname.model.ImeiPair&gt;
);

Actually, there were zero interactions with this mock.
</code></pre>

<p>I got this response even when I don't mention that method in the test.
This is my presenter register method. I've changed the classes / interfaces &amp; methods involved to open (kotlin). I believe override methods are open by nature in kotlin.</p>

<pre><code> open class RegisterPresenterImpl @Inject constructor(val localStorage : ILocalStorageInteractor, var herokuService : IHerokuInteractor)

 override fun register(imei : String, gender : String){
    subscription = herokuService.register(RegisterObject(imei,gender)).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread()).subscribe(
            {
                registrationResult -&gt;
                Log.d(TAG,"${registrationResult}")
                if(registrationResult.imei_hash != null){
                    writeImeiPairLocally(ImeiPair(imei,registrationResult.imei_hash))
                }
                else{
                    Log.e(TAG,"User already exists")
                }
            },
            {
                errorResponse -&gt; Log.e(TAG,"Could not register user ${errorResponse.message}")
            }
    )
    addSubscription(subscription)
}
</code></pre>

<p>and similarly the </p>

<pre><code>open fun writeImeiPairLocally(pair : ImeiPair){
    subscription = localStorage.clearPreferences().flatMap {
        cleared -&gt; localStorage.putImeiPair(pair)}.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread()).subscribe(
            {

                booleanResult -&gt; view?.moveToMain()
            },
            {
                errorResponse -&gt; Log.e(TAG,"Could not write ImeiPair to SharedPreferences ${errorResponse.message}")
            }
    )
    addSubscription(subscription)

}
</code></pre>

<p>Here is interfaces</p>

<pre><code>open interface ILocalStorageInteractor : ILocalStorage{
   fun getImeiPair() : Observable&lt;ImeiPair&gt;
   fun putImeiPair(pair: ImeiPair) : Observable&lt;Boolean&gt;
}

open interface ILocalStorage {
   fun clearPreferences() : Observable&lt;Boolean&gt;
}
</code></pre>

<p>All help is appreciated.</p>