{
public void testExceptionReceived()
{
String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'";
AMQInvalidArgumentException expectedException = new AMQInvalidArgumentException("Test", null);
final AtomicReference<JMSException> receivedException = new AtomicReference<JMSException>();
try
{
MockAMQConnection connection = new MockAMQConnection(url);
connection.setExceptionListener(new ExceptionListener()
{
@Override
public void onException(JMSException jmsException)
{
receivedException.set(jmsException);
}
});
connection.exceptionReceived(expectedException);
}
catch (Exception e)
{
fail("Failure to test exceptionRecived:" + e.getMessage());
}
JMSException exception = receivedException.get();
assertNotNull("Expected JMSException but got null", exception);
assertEquals("JMSException error code is incorrect", Integer.toString(expectedException.getErrorCode().getCode()), exception.getErrorCode());
assertNotNull("Expected not null message for JMSException", exception.getMessage());
assertTrue("JMSException error message is incorrect", exception.getMessage().contains(expectedException.getMessage()));
assertEquals("JMSException linked exception is incorrect", expectedException, exception.getLinkedException());
}