FileWriterQueueListener implements MessageListener { @Override public void onMessage(final Message message) { if (message instanceof ObjectMessage) { try { WilmaHttpEntity wilmaHttpEntity = getWilmaHttpEntityFromMessage(message); writeFile(message, wilmaHttpEntity); } catch (JMSException e) { throw new RuntimeException(e); } } else { throw new IllegalArgumentException("Message must be of type ObjectMessage"); } }  @Override void onMessage(final Message message);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testOnMessageShouldThrowIllegalArgumentExceptionWhenMessageNotInstanceOfObjectMessage() { underTest.onMessage(message); }
@Test(expectedExceptions = RuntimeException.class) public void testOnMessageShouldThrowRuntimeExceptionWhenObjectMessageNotInstanceOfWilmaHttpEntity() throws JMSException { given(objectMessage.getObject()).willThrow(new JMSException("Can't cast to WilmaHttpEntity!")); underTest.onMessage(objectMessage); }