### Question:
BluefloodServiceStarter { public static void validateCassandraHosts() { String hosts = Configuration.getInstance().getStringProperty(CoreConfig.CASSANDRA_HOSTS); if (!(hosts.length() >= 3)) { log.error("No cassandra hosts found in configuration option 'CASSANDRA_HOSTS'"); throw new BluefloodServiceStarterException(-1, "No cassandra hosts found in configuration option 'CASSANDRA_HOSTS'"); } for (String host : hosts.split(",")) { if (!host.matches("[\\d\\w\\.\\-_]+:\\d+")) { log.error("Invalid Cassandra host found in Configuration option 'CASSANDRA_HOSTS' -- Should be of the form <hostname>:<port>"); throw new BluefloodServiceStarterException(-1, "Invalid Cassandra host found in Configuration option 'CASSANDRA_HOSTS' -- Should be of the form <hostname>:<port>"); } } }  static void validateCassandraHosts(); static void main(String args[]); static void run(); static MetricRegistry getRegistry();  }### Answer:
@Test(expected = BluefloodServiceStarterException.class) public void testNoCassandraHostsFailsValidation() { Configuration config = Configuration.getInstance(); config.setProperty(CoreConfig.CASSANDRA_HOSTS, ""); BluefloodServiceStarter.validateCassandraHosts(); }
@Test(expected = BluefloodServiceStarterException.class) public void testInvalidCassandraHostsFailsValidation() { Configuration config = Configuration.getInstance(); config.setProperty(CoreConfig.CASSANDRA_HOSTS, "something"); BluefloodServiceStarter.validateCassandraHosts(); }
@Test(expected = BluefloodServiceStarterException.class) public void testCassandraHostWithoutPortFailsValidation() { Configuration config = Configuration.getInstance(); config.setProperty(CoreConfig.CASSANDRA_HOSTS, "127.0.0.1"); BluefloodServiceStarter.validateCassandraHosts(); }
@Test public void testCassandraHostWithHyphenSucceedsValidation() { Configuration config = Configuration.getInstance(); config.setProperty(CoreConfig.CASSANDRA_HOSTS, "my-hostname:9160"); BluefloodServiceStarter.validateCassandraHosts(); }
@Test public void testCassandraHostWithUnderscoreSucceedsValidation() { Configuration config = Configuration.getInstance(); config.setProperty(CoreConfig.CASSANDRA_HOSTS, "my_hostname:9160"); BluefloodServiceStarter.validateCassandraHosts(); }