### Question:
ZooKeeperMainServer { public String parse(final Configuration c) { Properties zkProps = ZKConfig.makeZKProps(c); String clientPort = null; List<String> hosts = new ArrayList<String>(); for (Entry<Object, Object> entry: zkProps.entrySet()) { String key = entry.getKey().toString().trim(); String value = entry.getValue().toString().trim(); if (key.startsWith("server.")) { String[] parts = value.split(":"); hosts.add(parts[0]); } else if (key.endsWith("clientPort")) { clientPort = value; } } if (hosts.isEmpty() || clientPort == null) return null; StringBuilder host = new StringBuilder(); for (int i = 0; i < hosts.size(); i++) { if (i > 0) host.append("," + hosts.get(i)); else host.append(hosts.get(i)); host.append(":"); host.append(clientPort); } return host.toString(); }  String parse(final Configuration c); static void main(String args[]);  }### Answer:
@Test public void test() { Configuration c = HBaseConfiguration.create(); assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c)); final String port = "1234"; c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port); c.set("hbase.zookeeper.quorum", "example.com"); assertEquals("example.com:" + port, parser.parse(c)); c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com"); String ensemble = parser.parse(c); assertTrue(port, ensemble.matches("(example[1-3]\\.com:1234,){2}example[1-3]\\.com:" + port)); }
@Test public void testHostPortParse() { ZooKeeperMainServer parser = new ZooKeeperMainServer(); Configuration c = HBaseConfiguration.create(); assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c)); final String port = "1234"; c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port); c.set("hbase.zookeeper.quorum", "example.com"); assertEquals("example.com:" + port, parser.parse(c)); c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com"); String ensemble = parser.parse(c); assertTrue(port, ensemble.matches("(example[1-3]\\.com:1234,){2}example[1-3]\\.com:" + port)); }