### Question:
PEUrl { public static PEUrl fromConnectString(String connectString) throws PEException { PEUrl url = new PEUrl(); String delims = "[=;]"; String[] tokens = connectString.split(delims); if (tokens.length % 2 != 0) throw new PEException("Connect String does not contain the correct number of elements"); Properties props = new Properties(); for (int i = 0; i < tokens.length; i = i + 2) { props.setProperty(tokens[i], tokens[i + 1]); } url.initializeFromProps(props, null , false ); if (!url.isInitialized()) throw new PEException("Error creating URL object from connect string: " + connectString); return url; } PEUrl();  PEUrl(Properties props, String prefix);  PEUrl(Properties props, String prefix, boolean useDefaults); static String stripUrlParameters(final String url); static PEUrl fromUrlString(String urlString); static PEUrl isValidUrlWithPort(String urlString); static PEUrl fromConnectString(String connectString); PEUrl createMysqlDefaultURL(); String getOption(String optionKey); String getURL(); String getProtocol(); PEUrl setProtocol(String protocol); String getSubProtocol(); PEUrl setSubProtocol(String subProtocol); String getAuthority(); void setAuthority(String authority); String getHost(); PEUrl setHost(String host); int getPort(); PEUrl setPort(int port); boolean hasPort(); PEUrl setPort(String port); String getPath(); PEUrl setPath(String path); String getQuery(); PEUrl setQuery(String query); PEUrl clearQuery(); Properties getQueryOptions(); PEUrl setQueryOption(String key, String value); PEUrl setQueryOptions(Properties props); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }### Answer:
@Test public void fromConnectStringTest() throws PEException { String connectString = "host=localhost;port=3306;dbname=parelastic"; PEUrl url = PEUrl.fromConnectString(connectString); assertEquals("jdbc:mysql: url.getURL()); connectString = "host=localhost"; url = PEUrl.fromConnectString(connectString); assertEquals("jdbc:mysql: connectString = "host=foo;port=7000;dbname=bar"; url = PEUrl.fromConnectString(connectString); assertEquals("jdbc:mysql: }
@Test(expected = PEException.class) public void fromConnectStringFailTest1() throws PEException { String connectString = "hostname=localhost;port=3306;dbname=parelastic"; PEUrl.fromConnectString(connectString); }
@Test(expected = PEException.class) public void fromConnectStringFailTest2() throws PEException { String connectString = "host=localhost;port"; PEUrl.fromConnectString(connectString); }
@Test(expected = PEException.class) public void fromConnectStringFailTest3() throws PEException { String connectString = "host=;port=;"; PEUrl.fromConnectString(connectString); }