Apakah ada cara agar metode stubbed mengembalikan objek yang berbeda pada pemanggilan berikutnya? Saya ingin melakukan ini untuk menguji tanggapan yang tidak ditentukan dari ExecutorCompletionService. yaitu untuk menguji bahwa terlepas dari urutan pengembalian metode, hasilnya tetap konstan.
Kode yang ingin saya uji terlihat seperti ini.
// 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 (...) { }
}