### Question:
InstanceURIParser { public CLIConnectionConfig parse(String uriString) { uriString = addScheme(uriString); URI uri = URI.create(uriString); NamespaceId namespace = (uri.getPath() == null || uri.getPath().isEmpty() || "/".equals(uri.getPath())) ? NamespaceId.DEFAULT : new NamespaceId(uri.getPath().substring(1)); String hostname = uri.getHost(); boolean sslEnabled = "https".equals(uri.getScheme()); int port = uri.getPort(); if (port == -1) { port = sslEnabled ? cConf.getInt(Constants.Router.ROUTER_SSL_PORT) : cConf.getInt(Constants.Router.ROUTER_PORT); } ConnectionConfig config = ConnectionConfig.builder() .setHostname(hostname) .setPort(port) .setSSLEnabled(sslEnabled) .build(); return new CLIConnectionConfig(config, namespace, null); } @Inject  InstanceURIParser(CConfiguration cConf); CLIConnectionConfig parse(String uriString); CLIConnectionConfig parseInstanceURI(String uriString, String namespaceString); static final InstanceURIParser DEFAULT; static final String DEFAULT_PROTOCOL; }### Answer:
@Test public void testParse() { CConfiguration cConf = CConfiguration.create(); int defaultSSLPort = cConf.getInt(Constants.Router.ROUTER_SSL_PORT); int defaultPort = cConf.getInt(Constants.Router.ROUTER_PORT); NamespaceId someNamespace = new NamespaceId("nsx"); InstanceURIParser parser = new InstanceURIParser(cConf); Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultPort, false), parser.parse("somehost")); Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultPort, false), parser.parse("http: Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultSSLPort, true), parser.parse("https: Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false), parser.parse("somehost:1234")); Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false), parser.parse("http: Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, true), parser.parse("https: Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, false), parser.parse("somehost:1234/nsx")); Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, false), parser.parse("http: Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, true), parser.parse("https: }
@Test public void testParseTrailingSlash() { CConfiguration cConf = CConfiguration.create(); InstanceURIParser parser = new InstanceURIParser(cConf); Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, true), parser.parse("https: }