public void destroy() { MessageBus messageBus = getMessageBus(); for (Map.Entry<String, List<MessageListener>> messageListeners : _messageListeners.entrySet()) { String destinationName = messageListeners.getKey(); for (MessageListener messageListener : messageListeners.getValue()) { messageBus.unregisterMessageListener(destinationName, messageListener); } } for (Destination destination : _destinations) { messageBus.removeDestination(destination.getName()); destination.close(); } for (Map.Entry<String, List<DestinationEventListener>> destinationEventListeners : _specificDestinationEventListeners.entrySet()) { String destinationName = destinationEventListeners.getKey(); for (DestinationEventListener destinationEventListener : destinationEventListeners.getValue()) { messageBus.removeDestinationEventListener(destinationName, destinationEventListener); } } for (DestinationEventListener destinationEventListener : _globalDestinationEventListeners) { messageBus.removeDestinationEventListener(destinationEventListener); } }
protected MessageBus setUpMessageBus() { MessageBus messageBus = Mockito.mock(MessageBus.class); _synchronousDestination = new SynchronousDestination(); _synchronousDestination.setName(_TEST_DESTINATION_NAME); messageBus.addDestination(_synchronousDestination); Mockito.when(messageBus.getDestination(Matchers.anyString())) .then( new Answer<Destination>() { @Override public Destination answer(InvocationOnMock invocationOnMock) throws Throwable { String destinationName = (String) invocationOnMock.getArguments()[0]; if (!Validator.equals(_synchronousDestination.getName(), destinationName)) { throw new IllegalArgumentException("Invalid destination: " + destinationName); } return _synchronousDestination; } }); Mockito.when( messageBus.registerMessageListener( Matchers.anyString(), Matchers.any(MessageListener.class))) .then( new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocationOnMock) throws Throwable { _synchronousDestination.register( (MessageListener) invocationOnMock.getArguments()[1]); return true; } }); Mockito.when( messageBus.unregisterMessageListener( Matchers.anyString(), Matchers.any(MessageListener.class))) .then( new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocationOnMock) throws Throwable { _synchronousDestination.unregister( (MessageListener) invocationOnMock.getArguments()[1]); return true; } }); return messageBus; }