title: PowerMockito: NotAMockException on a mock
body: <p>Bit of a complicated setup.  Robolectric, PowerMockito rule-based config.  </p>
  
  <pre><code>@RunWith(RobolectricGradleTestRunner.class)
  @Config(constants = BuildConfig.class, sdk = 21)
  @PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"})
  // Using "PrepareOnlyThis" prevents powermock from trying to instrument the whole hierarchy,
  // part of which we've ignored (android.os.* in this case)
  @PrepareOnlyThisForTest({ServiceCallbackBase.class}) // this class extends Handler, 
  // so we need PrepareOnlyThis.  It also has some final methods we need to verify()
  public class ServiceBaseTests {
  
    private class Foo {
      // nothing
    }
  
    @Rule
    public PowerMockRule rule = new PowerMockRule();
  
    private ServiceCallbackBase&lt;Object, Foo&gt; setupCallback( boolean hasValidContext, boolean allContextsCanceled ) {
      ServiceCallbackBase&lt;Object, Foo&gt; callback = PowerMockito.mock( ServiceCallbackBase.class );
      // EDIT:  I have converted these to PowerMockito.doReturn()s to no avail.
      PowerMockito.when( callback.hasValidContext() ).thenReturn( hasValidContext );
      PowerMockito.when( callback.allContextsAreCanceled( any( Message.class ) ) ).thenReturn( allContextsCanceled );
      PowerMockito.doNothing().when( callback ).preSendMessage( any( Message.class ) );
      return callback;
    }
  </code></pre>
  
  <p>Should be pretty routine.  But whenever I try to call <code>verify</code> on one of these "callback" mock instances, for instance:</p>
  
  <pre><code>  private void test_notifyCallback( boolean isFromCache ) {
      ServiceCallbackBase&lt;Object, Foo&gt; callback = setupCallback( true, false );
  
      uut.addHandler( TestEnum.FOO, callback );
      uut.addHandler( TestEnum.BAR, PowerMockito.mock( ServiceCallbackBase.class ) );
      uut.addHandler( TestEnum.BAZ, PowerMockito.mock( ServiceCallbackBase.class ) );
  
      Response&lt;Foo&gt; foo = new Response&lt;&gt;( new Foo(), new ResponseStatus( 0, "Error" ) );
      uut.handleCallBack( TestEnum.FOO, foo, isFromCache );
  
      ArgumentCaptor&lt;Message&gt; captor = ArgumentCaptor.forClass( Message.class );
  
      // this line throws the error.  
      verify( callback ).preSendMessage( captor.capture() );
  
      assertThat( captor.getValue().what ).isEqualTo( TestEnum.FOO.ordinal() );
      assertThat( captor.getValue().obj ).isEqualTo( foo );
      assertThat( captor.getValue().arg1 ).isEqualTo( isFromCache ? 1 : 0 );
    }
  </code></pre>
  
  <p>I get an error like so:</p>
  
  <pre><code>org.mockito.exceptions.misusing.NotAMockException: 
  Argument passed to verify() is of type ServiceCallbackBase$$EnhancerByMockitoWithCGLIB$$9acf906b and is not a mock!
  Make sure you place the parenthesis correctly!
  See the examples of correct verifications:
      verify(mock).someMethod();
      verify(mock, times(10)).someMethod();
      verify(mock, atLeastOnce()).someMethod();
  </code></pre>
  
  <p>It's clearly and obviously been "enhanced" by mockito, and PowerMock doesn't have a verify()  method to use instead of <code>Mockito.verify()</code>...  what gives?</p>
  
  <p><em>EDIT</em>:  this is in some ways more and in some ways less confusing.  </p>
  
  <p>I'm in the process of building another test class to test ServiceCallbackBase itself.  If I remove the tests from that class, these tests pass.  The following snippet in a different class causes the tests above to fail.</p>
  
  <pre><code>@RunWith(RobolectricGradleTestRunner.class)
  @Config(constants = BuildConfig.class, sdk = 21)
  public class ServiceCallbackBaseTests {
  
    @Test
    public void test_nothing(){
  
    }
  
    private ServiceCallbackBase&lt;Object, String&gt; uutSpy;
  
  
    @Before
    public void setup(){
      uutSpy = mock( ServiceCallbackBase.class );
    }
  }
  </code></pre>