title: ClassCastException with Generics and Mockito
body: <p>I have this case using JDK6, Junit3, and Mockito 1.8.5 (names have been changed to make it easily understandable):</p>
  
  <pre><code>public abstract class AbstractProcessorTest&lt;P extends AbstractProcessor&lt;T&gt;, T extends AbstractProcess&gt; {
  
  @Mock(answer = CALLS_REAL_METHODS)
  protected P processor;
  
  @Mock(answer = RETURN_DEEP_STUBS)
  protected T process;
  
  public void setUp(){
   Mockito.initMocks(this);
   // some common configurations
   processor.setProcess(process);
   ...
  }
  
  }
  
  public class ProcessorTest extends AbstractProcessorTest&lt;Processor, ProcessAlpha&gt;{    
  
  @Mock
  private Service service;
  
  @Override
  public void setUp(){
     super.setUp();
     doReturn(service).when(processor).getService();
  }
  
  public void testAMethod(){          
     processor.process();
  }
  
  }
  </code></pre>
  
  <p>When I execute the testAMethod() test case, I'm getting this exception:</p>
  
  <pre><code>java.lang.ClassCastException: org.xyz.AbstractProcessor$$EnhancerByMockitoWithCGLIB$$c948b334 cannot be cast to org.xyz.ProcessorA
  </code></pre>
  
  <p>When I inspect this method call, it says that this method cannot be found in the class. Another weird thing is I'm not getting any exception while calling methods in AbstractProcessor.setUp() (but it fails in ProcessorTest.setUp())</p>
  
  <p>This wasn't happening before I created the AbstractProcessorTest class, so I believe it's some stuff related to the generics and the way Mockito proxies these objects, that I need to change my strategy.</p>
  
  <p>Hope this was clear enough.
  Thank you in advance,</p>
  
  <p>Sebas.-</p>