title: How to mock ResultSet.next() method using Mockito
body: <p>I am mocking <code>java.sql.ResultSet</code> like this</p>
  
  <pre><code>ResultSet rs = mock(ResultSet.class);
  when(rs.next()).thenReturn(true); // this seems wrong appraoch
  </code></pre>
  
  <p>Test code is like this</p>
  
  <pre><code>while (rs.next()) {
    // doing stuff here
  }
  </code></pre>
  
  <p>So problem is when I have mock <code>rs.next()</code> to <code>true</code> then <code>while</code> loop never terminates. I want to terminate <code>while</code> loop after 2 iteration. So how i can mock <code>rs.next()</code> method?</p>
  
  <p>I have also tried </p>
  
  <pre><code>when(rs.next()).thenReturn(true, true, false); // always return false 
  </code></pre>
  
  <p>Please help!</p>