### Question:
MongoUriParser { public static String[] getHosts(String mongoUri) { Matcher m = MONGO_URI_PATTERN.matcher(mongoUri); if (m.find()) { return Optional.ofNullable(m.group(2)) .map(hosts -> hosts.split(",")) .orElseThrow(() -> new RuntimeException("unsupported mongo uri")); } else { throw new RuntimeException("unsupported mongo uri"); } }  static String[] getHosts(String mongoUri);  }### Answer:
@Test @DisplayName("getHosts from username, pass, multiple host + port, dbname, options") public void getHostsTest8() { String[] mongoHosts = MongoUriParser.getHosts( "mongodb: assertEquals(2, mongoHosts.length); assertEquals("mongo0.exmpl.com:27017", mongoHosts[0]); assertEquals("mongo1.exmpl.com:27017", mongoHosts[1]); }
@Test public void getHostsUnsupportedUri() { assertThrows( RuntimeException.class, () -> MongoUriParser.getHosts("mongodb: ); }
@Test @DisplayName("getHosts from host only") public void getHostsTest() { String[] mongoHosts = MongoUriParser.getHosts("mongodb: assertEquals(1, mongoHosts.length); assertEquals("mongo0.exmpl.com", mongoHosts[0]); }
@Test @DisplayName("getHosts from multiple host only") public void getHostsTest2() { String[] mongoHosts = MongoUriParser.getHosts("mongodb: assertEquals(2, mongoHosts.length); assertEquals("mongo0.exmpl.com", mongoHosts[0]); assertEquals("mongo1.exmpl.com", mongoHosts[1]); }
@Test @DisplayName("getHosts from host and port") public void getHostsTest3() { String[] mongoHosts = MongoUriParser.getHosts("mongodb: assertEquals(1, mongoHosts.length); assertEquals("mongo0.exmpl.com:27017", mongoHosts[0]); }
@Test @DisplayName("getHosts from multiple host and port") public void getHostsTest4() { String[] mongoHosts = MongoUriParser.getHosts("mongodb: assertEquals(2, mongoHosts.length); assertEquals("mongo0.exmpl.com:27017", mongoHosts[0]); assertEquals("mongo1.exmpl.com:27017", mongoHosts[1]); }
@Test @DisplayName("getHosts from username, pass, host, port") public void getHostsTest5() { String[] mongoHosts = MongoUriParser.getHosts("mongodb: assertEquals(1, mongoHosts.length); assertEquals("mongo0.exmpl.com:27017", mongoHosts[0]); }
@Test @DisplayName("getHosts from username, pass, host, port, dbname") public void getHostsTest6() { String[] mongoHosts = MongoUriParser.getHosts("mongodb: assertEquals(1, mongoHosts.length); assertEquals("mongo0.exmpl.com:27017", mongoHosts[0]); }
@Test @DisplayName("getHosts from username, pass, host, port, dbname, options") public void getHostsTest7() { String[] mongoHosts = MongoUriParser.getHosts("mongodb: assertEquals(1, mongoHosts.length); assertEquals("mongo0.exmpl.com:27017", mongoHosts[0]); }