Existe uma maneira de um método stubbed retornar objetos diferentes nas invocações subseqüentes? Eu gostaria de fazer isso para testar respostas não determinadas de um ExecutorCompletionService. isto é, para testar se, independentemente da ordem de retorno dos métodos, o resultado permanece constante.
O código que estou procurando testar é mais ou menos assim.
// Create an completion service so we can group these tasks together
ExecutorCompletionService<T> completionService =
new ExecutorCompletionService<T>(service);
// Add all these tasks to the completion service
for (Callable<T> t : ts)
completionService.submit(request);
// As an when each call finished, add it to the response set.
for (int i = 0; i < calls.size(); i ++) {
try {
T t = completionService.take().get();
// do some stuff that I want to test
} catch (...) { }
}