### Question:
MongoDataSource { static List<ServerAddress> parseServerString(String servers) { CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(servers)); ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>(); String[] serverList = servers.split(","); for (String server : serverList) { String[] pair = server.split(":"); try { if(pair.length == 1) { addrs.add(new ServerAddress(pair[0].trim())); } else if (pair.length == 2) { addrs.add(new ServerAddress(pair[0].trim(), Integer.valueOf(pair[1].trim()))); } else { throw new RuntimeException("Bad server string: " + servers); } } catch (UnknownHostException e) { throw new RuntimeException("parse server string error", e); } } return addrs; } MongoDataSource(String servers);  MongoDataSource(String servers, int connectionsPerHost);  MongoDataSource(String servers, CMSDBConfig dbConfig);  MongoDataSource(String servers, int connectionsPerHost, ReadPreference readPreference, CMSDBConfig config); MongoClient getMongoInstance(); @Override int hashCode(); @Override boolean equals(Object o);  }### Answer:
@Test(expected=Exception.class) public void testNullServerString() { MongoDataSource.parseServerString(null); }
@Test(expected=Exception.class) public void testEmptyServerString() { MongoDataSource.parseServerString(""); }
@Test(expected=RuntimeException.class) public void testBadServerString1() { MongoDataSource.parseServerString("localhost:3:2,"); }
@Test(expected=RuntimeException.class) public void testBadServerString2() { MongoDataSource.parseServerString("@@@:12345"); }
@Test public void testServerString() { List<ServerAddress> addrs1 = MongoDataSource.parseServerString("localhost:12345, www.ebay.com:2897"); Assert.assertEquals(2, addrs1.size()); Assert.assertEquals("localhost", addrs1.get(0).getHost()); Assert.assertEquals("www.ebay.com", addrs1.get(1).getHost()); List<ServerAddress> addrs2 = MongoDataSource.parseServerString("localhost, www.ebay.com:2897"); Assert.assertEquals(2, addrs2.size()); Assert.assertEquals("localhost", addrs2.get(0).getHost()); Assert.assertEquals("www.ebay.com", addrs2.get(1).getHost()); }