ClusterJMSService implements ClusterService { @Override public void connect() { try { final String jmsUserName = clusterParameters.getJmsUserName(); final String jmsPassword = clusterParameters.getJmsPassword(); final ConnectionFactory factory; switch (clusterParameters.getConnectionMode()) { case REMOTE: final String jmsURL = clusterParameters.getProviderUrl(); factory = createRemoteConnectionFactory(jmsURL, jmsUserName, jmsPassword); break; case JNDI: final InitialContext context = new InitialContext(clusterParameters.getInitialContextFactory()); factory = createJNDIConnectionFactory(context); break; default: throw new RuntimeException("Error setting the cluster mode (should be defined as REMOTE or JNDI"); } if (thereIsNoCredentials(jmsUserName, jmsPassword)) { connection = factory.createConnection(); } else { connection = factory.createConnection(jmsUserName, jmsPassword); } connection.setExceptionListener(new JMSExceptionListener()); connection.start(); } catch (Exception e) { LOGGER.error("Error connecting on JMS " + e.getMessage()); throw new RuntimeException(e); } } ClusterJMSService(); @Override void connect(); @Override void createConsumer(DestinationType type,
                                   String channel,
                                   Class<T> objectMessageClass,
                                   Consumer<T> listener); @Override synchronized void broadcast(DestinationType type,
                                       String channel,
                                       Serializable object); @Override boolean isAppFormerClustered(); @Override void close();  }
@Test(expected = RuntimeException.class) public void noConnectionModeShouldThrowException() { clusterService.connect(); }