@Test
public void testWaitResponse() throws Exception
{

    listener.waitResponse( messageRequest, REQUEST_TIMEOUT, RESPONSE_TIMEOUT );
    verify( responses ).remove( any( UUID.class ) );
    when( messenger.getMessageStatus( any( UUID.class ) ) ).thenReturn( MessageStatus.EXPIRED );
    try
    {
        listener.waitResponse( messageRequest, REQUEST_TIMEOUT, RESPONSE_TIMEOUT );
        fail( "Expected PeerException" );
    }
    catch ( PeerException e )
    {
    }
    when( messenger.getMessageStatus( any( UUID.class ) ) ).thenReturn( MessageStatus.SENT );
    doThrow( new MessageException( "" ) ).when( messenger ).getMessageStatus( any( UUID.class ) );
    try
    {
        listener.waitResponse( messageRequest, REQUEST_TIMEOUT, RESPONSE_TIMEOUT );
        fail( "Expected PeerException" );
    }
    catch ( PeerException e )
    {
    }
    reset( messenger );
    when( messenger.getMessageStatus( any( UUID.class ) ) ).thenReturn( MessageStatus.SENT );
    doThrow( interruptedException ).when( semaphore ).tryAcquire( anyLong(), any( TimeUnit.class ) );
    listener.waitResponse( messageRequest, REQUEST_TIMEOUT, RESPONSE_TIMEOUT );
    assertTrue( Thread.interrupted() );
}