title: Mockito ClassCastException
body: <p>The method I want to test has a for loop with logic for each element in bList:</p>
  
  <pre><code>class A {
      void someMethod(){
  
          for(B b: bList){
              //some logic for b
          }
      }
  }
  </code></pre>
  
  <p>I get an exception when executing following test:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  class ATest {
  
      @Mock
      private B b;
  
      @Mock
      private Map&lt;Int, List&lt;B&gt;&gt; bMap;
  
      @Mock(answer = Answers.RETURNS_DEEP_STUBS)
      private List&lt;B&gt; bList;
  
      @Spy
      @InjectMocks
      private C c;
      ....
  
      @Test
      public void test(){
  
          //this line executes fine
          when(bList.size()).thenReturn(1);
  
          //strangely this works fine
          when(bMap.get(any())).thenReturn(bList);
  
          //ClassCastException
          when(bList.get(0)).thenReturn(b); // or when(bList.get(anyInt())).thenReturn(b);
  
          c.methodIWantToTest();
      }
  }
  </code></pre>
  
  <p>The exception I get is:</p>
  
  <pre><code>java.lang.ClassCastException:
  org.mockito.internal.creation.jmock.ClassImposterizer$ClassWithSuperclassToWorkAroundCglibBug$$EnhancerByMockitoWithCGLIB$$ cannot be cast to xyz.B</code></pre>
  
  <p>Has anyone encountered this before and come up with a workaround?</p>
  
  <p>I have searched for a solution and have come across some links: 
  <a href="http://code.google.com/p/mockito/issues/detail?id=251" rel="noreferrer">http://code.google.com/p/mockito/issues/detail?id=251</a>
   and
  <a href="http://code.google.com/p/mockito/issues/detail?id=107" rel="noreferrer">http://code.google.com/p/mockito/issues/detail?id=107</a></p>