title: How can I do unit testing for retrofit callbacks?
body: <p>I'm trying to create unitest case for  retrofit 2 callbacks  in android. I use for test mockito, MockWebServer  and  MockResponse.</p>
  
  <pre><code>public class LoginFragment extends Fragment {
  /**
       * Actualiza el numero telefonico para el usuario
       *
       * @param phoneNumber
       */
      public  void phoneNumber(String phoneNumber) {
          HttpService service = Service.createService(HttpService.class, TOKEN);
          Call&lt;Void&gt; call = service.phonumber(phoneNumber, new User("", ""));
          call.enqueue(callback());
      }
  
      /**
       * @return Callback&lt;Void&gt;
       */
      public Callback&lt;Void&gt; callback() {
          return new Callback&lt;Void&gt;() {
              @Override
              public void onResponse(Call&lt;Void&gt; call, Response&lt;Void&gt; response) {
                  if (response.isSuccessful()) {
                      dummy();
                  } else {
                      Log.e(TAG, "problema");
                  }
              }
  
              @Override
              public void onFailure(Call&lt;Void&gt; call, Throwable t) {
                  Log.e(TAG, " " + t);
              }
          };
      }
  
      public void dummy(){
          System.out.println(" called");
      }
  }
  </code></pre>
  
  <p>My unitest class:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class TestLoginFragment {
     MockWebServer mockWebServer;
  
      @Before
      public void setup() throws Exception {
          spyLoginFragment = mock(LoginFragment.class);
          mockWebServer = new MockWebServer();
      }
  
  
      @Test
      public void testDummyIsCalled() {
          spyLoginFragment.phoneNumber("3333335");
          mockWebServer.enqueue(new MockResponse().setResponseCode(201));
          verify(spyLoginFragment, times(1)).dummy();
      }
  }
  </code></pre>
  
  <p>But when you run the test I get:</p>
  
  <pre><code>TestLoginFragment &gt; testDummyIsCalled FAILED
      Wanted but not invoked:
      loginFragment.dummy();
  </code></pre>
  
  <p>I'm new making callback test, how can I verify that <code>dummy()</code> was called?</p>