title: How to return different results when calling the same mocked method?
body: <p>I have a method that I call that connects to another server and each time I call it, and it returns different data.<br>
  I am writing a unit test for the class calling the method. I have mocked that class and I expect it to return the stubbed result. It actually works using <code>doReturn</code>, but it returns the same data every time. I want it to return different data and I want to be able to specify what it should be.</p>
  
  <p>I tried using 'doReturn - when' and it works, but I can't make it return a different result. I don't know how to do this.</p>
  
  <p>I also tried using 'when - thenReturn' which was the solution I found here on StackOverflow. With that, I could specify o get different responses every time I called the same method.</p>
  
  <p>Problem is that I get a compilation error</p>
  
  <blockquote>
    <p>The method XXX is undefined for the type <code>OngoingStubbing&lt;MyClass&gt;</code></p>
  </blockquote>
  
  <pre><code>JSONArray jsonArray1 = { json array1 here };
  JSONArray jsonArray2 = { json array2 here };
  
  // Works but return the same jsonArray1 every time:
  MyClass MyClassMock = mock(MyClass.class);
  Mockito.doReturn(jsonArray1)
          .when(MyClassMock).getMyValues(any(List.class), any   (String.class), any(String.class),
                  any(String.class),
                  any(String.class));
  
  // Does not work:
  when(MyClassMock).getMyValues(any(List.class),
         any(String.class), any(String.class),
         any(String.class),
         any(String.class)).thenReturn(jsonArray1, jsonArray2);
  
  
  // Compile error:
  // The method getMyValues(any(List.class), any(String.class), any (String.class), any(String.class), any(String.class)) is undefined for the type OngoingStubbing&lt;MyClass&gt;
  </code></pre>
  
  <p>I get compile error:</p>
  
  <blockquote>
    <p>The method getMyValues(any(List.class), any(String.class),
    any(String.class), any(String.class), any(String.class)) is undefined
    for the type OngoingStubbing</p>
  </blockquote>