title: Mocking ColumnDefinitions.Definition does return mock, but is behaves like null in the tested code
body: <p>I have following code preparing mocks to test my service using Cassandra (I need to mock <code>com.datastax.driver.core.ColumnDefinitions.Definition</code>) :</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  public class TestMyClass{
  private MyClass target;
    @Before
    public void setUp() throws Exception {
      ColumnDefinitions mockColumnDefinitions=Mockito.mock(ColumnDefinitions.class);
      Mockito.when(mockRow.getColumnDefinitions()).thenReturn(mockColumnDefinitions);
      target= new MyClass();
      Definition mockDef = Mockito.mock(Definition.class);
      List&lt;Definition&gt; defList = new ArrayList&lt;Definition&gt;();
      defList.add(mockDef);
      Iterator mockIterator = Mockito.mock(Iterator.class);
      Mockito.when(mockColumnDefinitions.iterator()).thenReturn(mockIterator);
      Mockito.when(mockIterator.hasNext()).thenReturn(true, false);
      Mockito.when(mockIterator.next()).thenReturn(mockDef);
      Mockito.when(mockDef.getName()).thenReturn(NAME);
    }
   @Test
   public void testMyMethod() throws Exception {
      target.MyMethod();
   }
  }
  </code></pre>
  
  <p>Test execution goes fine this place, and I have this type of code in different places, so it should work.
  Inside the service I am testing I have following code:</p>
  
  <pre><code>ColumnDefinitions colDef = row.getColumnDefinitions();
  Iterator&lt;Definition&gt; defIterator = colDef.iterator();
  while (defIterator.hasNext()) {
      Definition def = defIterator.next();
      String columnName = def.getName();
  }
  </code></pre>
  
  <p>When I debug this code, I see, that both <code>colDef</code> and <code>defIterator</code> are mocked successfully. I see something like that in debug variables area:</p>
  
  <pre><code>Mock for Iterator, hashCode: 430126690
  </code></pre>
  
  <p>But after <code>defIterator.next()</code> invocation I see that though <code>def</code> is an object and not null, it doesn't show hashcode like for <code>Iterator</code>, instead I see this:</p>
  
  <pre><code>com.sun.jdi.InvocationException occurred invoking method.
  </code></pre>
  
  <p>And after invoking this string:</p>
  
  <pre><code>String columnName = def.getName();
  </code></pre>
  
  <p>I immediately get <code>NullPointerException</code> like if def is null.
  What am I doing wrong?
  Thanks.</p>
  
  <p>EDIT 1 ________________________________________________________________________</p>
  
  <p>I also tried to use <code>PowerMockito</code> with the same methods instead, the result is the same. </p>
  
  <p>EDIT 2 ________________________________________________________________________</p>
  
  <p>I added the whole test method code.</p>