title: mock retrofit service observable not calling onError method Android Mockito
body: <p>I am testing this code and I got success in the success response code but I am not able to reach the onError code</p>
  <pre><code>    internal class MaintenanceStatusResponseHandler {
  
   fun getMaintenanceResponse (voiceAiServices: VoiceAiServices, header: String): MaintenanceStatus {
  
       val maintenanceStatus = MaintenanceStatus()
      voiceAiServices.getMaintenanceStatus(header)
          .subscribe { response: MaintenanceStatus.Content, error: Throwable? -&gt;
              error.let {
                  if (error != null) {
                      maintenanceStatus.error = error
                  }
              }
              response.let {
                 maintenanceStatus.content = response
              }
          }
     return maintenanceStatus
  }
  </code></pre>
  <p>}</p>
  <p>repository class</p>
  <pre><code> class RetrofitRepository() {
      val TAG = RetrofitRepository::class.java.canonicalName
  
      fun getRetrofit(baseUrl: String?): VoiceAiServices {
        val voiceAiServices: VoiceAiServices =  Retrofit.Builder()
              .baseUrl(baseUrl!!)
              .addConverterFactory(GsonConverterFactory.create())
              .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
              .build().create(VoiceAiServices::class.java)
  
          return voiceAiServices
      }
  }
  </code></pre>
  <p>interface</p>
  <pre><code>interface VoiceAiServices {
  @GET(&quot;/v1/api/status&quot;)
  fun getMaintenanceStatus(@Header(&quot;Authorization&quot;)header: String): Single&lt;MaintenanceStatus.Content&gt;
  </code></pre>
  <p>}</p>
  <p>Pojo class</p>
  <pre><code> data class MaintenanceStatus(
      var error: Throwable? = null,
      var content: Content? = null
  ) {
      data class Content(
          val enabled: Boolean,
          val maintenanceMsg: String
      )
  }
  </code></pre>
  <p>Below test code for Success response which is working fine</p>
  <pre><code> fun mockedObservableErrorSuccess(): Single&lt;MaintenanceStatus.Content&gt; {
      return Single.create { e -&gt;
          e.onSuccess(MaintenanceStatus.Content(true, &quot;Under error maintenance&quot;))
          e.onError(Throwable(&quot;Error message&quot;))
      }
  }
  
  
      @Test
      fun testMaintenanceSuccessResponse() {
          val voiceAiService: VoiceAiServices = mock(VoiceAiServices::class.java)
          val maintenanceStatusHandler = MaintenanceStatusResponseHandler()
  
          val content =  MaintenanceStatus.Content(true, &quot;Under maintenance&quot;)
          `when`(voiceAiService.getMaintenanceStatus(Utilities.getHeader(voiceAIConfig))).thenReturn(just(content))
          
          val testObserver: TestObserver&lt;MaintenanceStatus.Content&gt; = TestObserver.create()
  
          val observer = mockedObservableErrorSuccess()
  
          observer.subscribe(testObserver)
          
          maintenanceStatusHandler.getMaintenanceResponse(voiceAiService, &quot;header&quot;)
  
          testObserver.awaitTerminalEvent()
          
          testObserver.onComplete()
  
      }
  </code></pre>
  <p>Below is code that is not able to reach to Error method and for this code I need help</p>
  <p>I really appreciate any help you can provide.</p>
  <pre><code>@Test(expected = java.lang.Exception::class)
  fun testMaintenanceErrorResponse()  {
      val voiceAiService: VoiceAiServices = mock(VoiceAiServices::class.java)
      val maintenanceStatusHandler = MaintenanceStatusResponseHandler()
      `when`(voiceAiService.getMaintenanceStatus(Utilities.getHeader(voiceAIConfig))).thenReturn(error(Throwable(&quot;Error message&quot;)))
      val testObserver: TestObserver&lt;MaintenanceStatus.Content&gt; = TestObserver.create()
      val observer = mockedObservableErrorSuccess()
      observer.subscribe(testObserver)
      maintenanceStatusHandler.getMaintenanceResponse(voiceAiService, Utilities.getHeader(voiceAIConfig))
      testObserver.awaitTerminalEvent()
      testObserver.assertError(Throwable::class.java)
     // testObserver.onError(Throwable()) //Also tried this method
  }
  
  Caused by: java.lang.AssertionError: No errors (latch = 0, values = 1, errors = 0, completions = 1)
  </code></pre>