public void afterPropertiesSet() {
    MessageBus messageBus = getMessageBus();

    for (DestinationEventListener destinationEventListener : _globalDestinationEventListeners) {

      messageBus.addDestinationEventListener(destinationEventListener);
    }

    for (Destination destination : _destinations) {
      messageBus.addDestination(destination);
    }

    for (Map.Entry<String, List<DestinationEventListener>> destinationEventListeners :
        _specificDestinationEventListeners.entrySet()) {

      String destinationName = destinationEventListeners.getKey();

      for (DestinationEventListener destinationEventListener :
          destinationEventListeners.getValue()) {

        messageBus.addDestinationEventListener(destinationName, destinationEventListener);
      }
    }

    for (Destination destination : _replacementDestinations) {
      messageBus.replace(destination);
    }

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    try {
      ClassLoader operatingClassLoader = getOperatingClassloader();

      currentThread.setContextClassLoader(operatingClassLoader);

      for (Map.Entry<String, List<MessageListener>> messageListeners :
          _messageListeners.entrySet()) {

        String destinationName = messageListeners.getKey();

        for (MessageListener messageListener : messageListeners.getValue()) {

          messageBus.registerMessageListener(destinationName, messageListener);
        }
      }
    } finally {
      currentThread.setContextClassLoader(contextClassLoader);
    }
  }
    public void replaceDestination(String destinationName) {
      MessageBus messageBus = MessageBusUtil.getMessageBus();

      Destination destination = messageBus.getDestination(destinationName);

      if (destination instanceof BaseAsyncDestination) {
        _asyncServiceDestinations.add(destination);

        messageBus.replace(createSynchronousDestination(destinationName));
      }

      if (destination == null) {
        _absentDestinationNames.add(destinationName);

        messageBus.addDestination(createSynchronousDestination(destinationName));
      }
    }
  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;
  }