### Question:
LogFeederSolrClientFactory { @VisibleForTesting ZkConnection createZKConnection(String zkConnectionString) { String split[] = zkConnectionString.split("/", 2); String zkChroot = null; final List<String> zkHosts; if (split.length == 1) { zkHosts = Arrays.asList(split[0].split(",")); } else { zkHosts = Arrays.asList(split[0].split(",")); zkChroot = ("/" + split[1]).replaceAll("/+", "/"); if (zkChroot.endsWith("/")) { zkChroot = zkChroot.substring(0, zkChroot.lastIndexOf("/")); } } return new ZkConnection(zkHosts, zkChroot); }  SolrClient createSolrClient(String zkConnectionString, String[] solrUrls, String collection, boolean discover);  }### Answer:
@Test public void testCreateZKConnection() { String input = "localhost:2181/solr"; LogFeederSolrClientFactory.ZkConnection result = underTest.createZKConnection(input); assertEquals("/solr", Optional.ofNullable(result.getZkChroot()).get()); assertEquals("localhost:2181", result.getZkHosts().get(0)); }
@Test public void testCreateZKConnectionWithoutChroot() { String input = "localhost:2181"; LogFeederSolrClientFactory.ZkConnection result = underTest.createZKConnection(input); assertFalse(Optional.ofNullable(result.getZkChroot()).isPresent()); assertEquals(input, result.getZkHosts().get(0)); }
@Test public void testCreateZKConnectionWithMultipleHosts() { String input = "localhost1:2181,localhost2:2181"; LogFeederSolrClientFactory.ZkConnection result = underTest.createZKConnection(input); assertFalse(Optional.ofNullable(result.getZkChroot()).isPresent()); assertEquals(2, result.getZkHosts().size()); assertTrue(result.getZkHosts().contains("localhost1:2181")); assertTrue(result.getZkHosts().contains("localhost2:2181")); }
@Test public void testCreateZKConnectionWithMultipleHostsAndChroot() { String input = "localhost1:2181,localhost2:2181/solr"; LogFeederSolrClientFactory.ZkConnection result = underTest.createZKConnection(input); assertEquals("/solr", result.getZkChroot()); assertEquals(2, result.getZkHosts().size()); assertTrue(result.getZkHosts().contains("localhost1:2181")); assertTrue(result.getZkHosts().contains("localhost2:2181")); }
@Test public void testCreateZKConnectionInvalidSlashes() { String input = "localhost:2181 LogFeederSolrClientFactory.ZkConnection result = underTest.createZKConnection(input); assertEquals("/solr", Optional.ofNullable(result.getZkChroot()).get()); assertEquals("localhost:2181", result.getZkHosts().get(0)); }
@Test public void testCreateZKConnectionInvalidSlashesMultipleTimes() { String input = "localhost:2181 LogFeederSolrClientFactory.ZkConnection result = underTest.createZKConnection(input); assertEquals("/solr/my/root", Optional.ofNullable(result.getZkChroot()).get()); assertEquals("localhost:2181", result.getZkHosts().get(0)); }