title: Dynamic chaining "thenReturn" in mockito
body: <p>I have a Tuple mock class, whose getString(0) and getString(1) methods are expected to be called n times. Instead of writing something like, </p>
  
  <pre><code>when(tuple.getString(0)).thenReturn(logEntries[0]).thenReturn(logEntries[1])...thenReturn(logEntries[n - 1])
  </code></pre>
  
  <p>manually, I tried the following:</p>
  
  <pre><code>OngoingStubbing stubbingGetStringZero = when(tuple.getString(0)).thenReturn(serviceRequestKey);
  OngoingStubbing stubbingGetStringOne = when(tuple.getString(1)).thenReturn(logEntries[0]);
  for (int i = 1; i &lt; n; i++) {
      stubbingGetStringZero = stubbingGetStringZero.thenReturn(serviceRequestKey);
      stubbingGetStringOne = stubbingGetStringOne.thenReturn(logEntries[i]);
  }
  </code></pre>
  
  <p>The expected result is that all calls to <code>tuple.getString(0)</code> should return the String <code>serviceRequestKey</code> and each call to <code>tuple.getString(1)</code> should return a different String <code>logEntries[i]</code> ie. ith invocation of tuple.getString(1) returns ith element of logEntries array. </p>
  
  <p>However, due to some odd reason, things are getting mixed up, and second invocation to <code>tuple.getString(1)</code> returns the String <code>serviceRequestKey</code> instead of <code>logEntries[1]</code>. What am I missing here?</p>