ArtemisMessageSource implements MessageSource { @Override public void shutDown() { closeEventReceivers(); } @Inject  ArtemisMessageSource(ActiveMQSessionFactory sessionFactory, ObjectMapper mapper,
        MessageSourceReceiverFactory receiverFactory); @Override void shutDown(); @Override void onStatusUpdate(QpidStatus oldStatus, QpidStatus newStatus); @Override void onStatusUpdate(ActiveMQStatus oldStatus, ActiveMQStatus newStatus); static String getQueueName(EventListener listener);  }
@Test public void shouldStopAndCloseSessionsOnShutdown() throws Exception { ClientSession session1 = mock(ClientSession.class); ClientSession session2 = mock(ClientSession.class); when(clientSessionFactory.createSession()) .thenReturn(session1).thenReturn(session2); when(session1.createConsumer(any(String.class))).thenReturn(mock(ClientConsumer.class)); when(session2.createConsumer(any(String.class))).thenReturn(mock(ClientConsumer.class)); DefaultEventMessageReceiver receiver1 = new DefaultEventMessageReceiver(mock(EventListener.class), sessionFactory, mock(ObjectMapper.class)); DefaultEventMessageReceiver receiver2 = new DefaultEventMessageReceiver(mock(EventListener.class), sessionFactory, mock(ObjectMapper.class)); ArtemisMessageSource messageSource = createEventSourceStubbedWithFactoryCreation(receiver1, receiver2); messageSource.shutDown(); verify(session1).close(); verify(session2).close(); }
@Test public void shouldStopAndCloseSessionOnShutdownWhenExceptionThrownOnStop() throws Exception { ClientSession session = mock(ClientSession.class); when(clientSessionFactory.createSession()).thenReturn(session); when(session.createConsumer(any(String.class))).thenReturn(mock(ClientConsumer.class)); doThrow(new ActiveMQException("Forced")).when(session).stop(); DefaultEventMessageReceiver receiver = new DefaultEventMessageReceiver(mock(EventListener.class), sessionFactory, mock(ObjectMapper.class)); ArtemisMessageSource messageSource = createEventSourceStubbedWithFactoryCreation(receiver); messageSource.shutDown(); verify(session).close(); }
@Test public void shouldStopAndCloseSessionOnShutdownWhenExceptionThrownOnClose() throws Exception { ClientSession session = mock(ClientSession.class); when(clientSessionFactory.createSession()).thenReturn(session); when(session.createConsumer(any(String.class))).thenReturn(mock(ClientConsumer.class)); doThrow(new ActiveMQException("Forced")).when(session).close(); DefaultEventMessageReceiver receiver = new DefaultEventMessageReceiver(mock(EventListener.class), sessionFactory, mock(ObjectMapper.class)); ArtemisMessageSource messageSource = createEventSourceStubbedWithFactoryCreation(receiver); messageSource.shutDown(); verify(session).close(); }