title: Mockito wait for method from new thread to executes a number of times
body: <p>So I have the following things: a spring boot application that starts by listening to messages from a queue and processes them and some UTs and ITs for it. Now, from an integration test class, I want to verify that if I post a big number of messages to the input queue, my application won't crash. </p>
  
  <p>For posting, from this method test, I'm connection to queue and post some dummy messages, than I start a new thread using <code>Mockito#spy</code>. So far so good as other IT exists for just one message. Than I'm using an <code>ArgumentCaptor</code> to see that the message that I sent to queue was successfully processes by my application thread. </p>
  
  <p>What I don't know how to do is to wait for the execution of thousands of the processing method calls to see that the application won't crash. The test should end with no exception thrown after all the messages were read from queue (I'm not validating the messages as for now it's not required). The time of processing should be between 1 and 2 hours.</p>
  
  <p>I've read about <code>CountDownLatch</code> but can't figure out how to wait for the thread to execute as long as it needs to process all my messages, if that is indeed an aid to use.</p>
  
  <p>Can anyone suggest an implementation design for what I'm trying to do here? Or is there any chance that what I'm trying to do is not possible?</p>
  
  <p>Thanks in advance!</p>
  
  <p>UPDATE:
  I cannot modify the tested application method or class, so is there a way to retrieve the number of calls to my method? Thanks @Mykhailo Kovalskyi</p>