title: Robolectric + OkHttp + retrofit + rxJava Unit Test
body: <p>I'm trying to write a unit test for a piece of code with robolectric. The problem is that I need to fake the http call but seems that robolectric's fake layer it works only with Apache's HttpClient as per this answer:</p>
  
  <p><a href="https://stackoverflow.com/questions/21735084/mock-httpresponse-with-robolectric">Link to answer</a></p>
  
  <p>In Retrofit you can't change the URL so the MockWebServer seems to be not an option.</p>
  
  <p>It seems that mockito can catch the retrofit callbacks but I'm using rxJava so I don't really know if it can helps.</p>
  
  <p>Does anyone has any suggestions about unit testing with Robolectric + Retrofit + okHttp + rxJava?</p>
  
  <p>Here is a small piece of code:</p>
  
  <pre><code>    @Test
  public void test1() throws IOException, InterruptedException {
      FragmentA frag = (FragmentA) activity
              .getFragmentManager().findFragmentById(
                      R.id.frag);
      assertThat(frag).isNotNull();
      assertThat(frag.isVisible()).isTrue();
  
      EditText input1 = (EditText) frag.getView()
              .findViewById(R.id.edit_text1);
      EditText input2 = (EditText) frag.getView()
              .findViewById(R.id.edit_text2);
      Button button = (button) frag.getView()
              .findViewById(R.id.button);
      input1.setText("999");
      input2.setText("999");
      Robolectric.addPendingHttpResponse(200, "{\"isValid\": true}");
      button.performClick();
              assertThat(
              ShadowAlertDialog.getLatestDialog() instanceof ProgressDialog)
              .isTrue();
  
    }
  </code></pre>
  
  <p>Robolectric.addPendingHttpResponse won't works anyway because of the OkHttp. The api call is started when the button is pressed so in that I moment I need to fake the response!</p>