@@ -0,0 +1,1318 @@
+package jamex.link;%0A%0Aimport java.util.Collection;%0Aimport java.util.LinkedList;%0Aimport java.util.concurrent.LinkedBlockingQueue;%0Aimport java.util.concurrent.TimeUnit;%0Aimport javax.jms.Message;%0Aimport javax.jms.MessageListener;%0Aimport static org.junit.Assert.*;%0A%0Afinal class MessageCollector%0A  implements MessageListener%0A%7B%0A  private static final int MAX_MESSAGE_COUNT = 10;%0A%0A  private final LinkedBlockingQueue%3CMessage%3E m_messages = new LinkedBlockingQueue%3CMessage%3E( MAX_MESSAGE_COUNT );%0A%0A  @Override%0A  public void onMessage( final Message message )%0A  %7B%0A    m_messages.add( message );%0A  %7D%0A%0A  Collection%3CMessage%3E expectMessageCount( final int expectedMessageCount,%0A                                          final long maxWait )%0A    throws InterruptedException%0A  %7B%0A    final LinkedList%3CMessage%3E results = new LinkedList%3CMessage%3E();%0A    final long start = System.currentTimeMillis();%0A    long now;%0A    while( results.size() %3C expectedMessageCount &&%0A           ( ( now = System.currentTimeMillis() ) %3C start + maxWait ) )%0A    %7B%0A      final long waitTime = Math.max( 1, start + maxWait - now );%0A      final Message message = m_messages.poll( waitTime, TimeUnit.MILLISECONDS );%0A      results.add( message );%0A    %7D%0A%0A    assertEquals( %22Expected message count%22, expectedMessageCount, results.size() );%0A    return results;%0A  %7D%0A%7D%0A

Add in class that collects result messages