title: Espresso / Mockito verify that method was called
body: <p>I have a simple test using an <code>activityTestRule</code> that should check whether a method of the activity under test was called:  </p>
  
  <pre><code>@Test
  public void callLiveLocation() {
      MapSettingsActivity spy = spy(activityRule.getActivity());
      doNothing().when(spy).setLiveLocation();
      onView(withId(R.id.btn_map_current_location)).perform(click());
      verify(spy).setLiveLocation();
  }
  </code></pre>
  
  <p>The method <code>setLiveLocation()</code> is being called when I check in debug mode.<br>
  However, the console tells me: </p>
  
  <blockquote>
    <p>Wanted but not invoked: mapSettingsActivity.setLiveLocation();
    -> at com.android.dx.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAdapter.java:53)
    Actually, there were zero interactions with this mock.</p>
  </blockquote>
  
  <p>How do I check if the method of the activity under test was called?<br>
  I use Android's databinding for the button click, which invokes a callback, which in turn calls a method on the activity under test. </p>
  
  <p>Note: </p>
  
  <p>The method is a simple method on the activity: </p>
  
  <pre><code>public void setLiveLocation() {
      super.startLocationListener();
  }
  </code></pre>
  
  <p>Edit: </p>
  
  <p>I noticed that creating the spy returns null for a yet unknown reason: </p>
  
  <pre><code>MapSettingsActivity spy = spy(activityRule.getActivity());
  </code></pre>