@Override protected void handleListenerException(Throwable ex) { assertNotNull("The Throwable passed to the handleListenerException(..) method must never be null.", ex); assertTrue("The Throwable passed to the handleListenerException(..) method must be of type [ListenerExecutionFailedException].", ex instanceof ListenerExecutionFailedException); ListenerExecutionFailedException lefx = (ListenerExecutionFailedException) ex; Throwable cause = lefx.getCause(); assertNotNull("The cause of a ListenerExecutionFailedException must be preserved.", cause); assertSame(exception, cause); } };
@Test public void exceptionInListener() { javax.jms.Message message = new StubTextMessage("foo"); Session session = mock(Session.class); MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class); try { listener.onMessage(message, session); fail("Should have thrown an exception"); } catch (JMSException ex) { fail("Should not have thrown a JMS exception"); } catch (ListenerExecutionFailedException ex) { assertEquals(IllegalArgumentException.class, ex.getCause().getClass()); assertEquals("Expected test exception", ex.getCause().getMessage()); } }
@Test public void exceptionInInvocation() { javax.jms.Message message = new StubTextMessage("foo"); Session session = mock(Session.class); MessagingMessageListenerAdapter listener = getSimpleInstance("wrongParam", Integer.class); try { listener.onMessage(message, session); fail("Should have thrown an exception"); } catch (JMSException ex) { fail("Should not have thrown a JMS exception"); } catch (ListenerExecutionFailedException ex) { assertEquals(MessageConversionException.class, ex.getCause().getClass()); } }