SourceCodeRepoFactory { public static Map<String, String> parseGitUrl(String url) { Pattern p1 = Pattern.compile("git\\@(\\S+):(\\S+)/(\\S+)\\.git"); Matcher m1 = p1.matcher(url); Pattern p2 = Pattern.compile("git: Matcher m2 = p2.matcher(url); Matcher matcherActual; if (m1.find()) { matcherActual = m1; } else if (m2.find()) { matcherActual = m2; } else { LOG.info("Cannot parse url using any format: " + url); return null; } final int sourceIndex = 1; final int usernameIndex = 2; final int reponameIndex = 3; String source = matcherActual.group(sourceIndex); String gitUsername = matcherActual.group(usernameIndex); String gitRepository = matcherActual.group(reponameIndex); LOG.debug("Source: " + source); LOG.debug("Username: " + gitUsername); LOG.debug("Repository: " + gitRepository); Map<String, String> map = new HashMap<>(); map.put("Source", source); map.put("Username", gitUsername); map.put("Repository", gitRepository); return map; } private  SourceCodeRepoFactory(); static SourceCodeRepoInterface createGitHubAppRepo(String token); static SourceCodeRepoInterface createSourceCodeRepo(Token token, HttpClient client); static SourceCodeRepoInterface createSourceCodeRepo(String gitUrl, HttpClient client, String bitbucketTokenContent,
            String gitlabTokenContent, String githubTokenContent); static SourceCodeRepoInterface createSourceCodeRepo(String gitUrl, String bitbucketTokenContent,
            String gitlabTokenContent, String githubTokenContent); static Map<String, String> parseGitUrl(String url);  }
@Test public void parseGitUrl() { final Map<String, String> stringStringMap1 = SourceCodeRepoFactory.parseGitUrl("git@github.com:dockstore/dockstore-ui.git"); Assert.assertNotNull(stringStringMap1); Assert.assertTrue("values not found", stringStringMap1.containsKey("Source") && stringStringMap1.containsKey("Username") && stringStringMap1 .containsKey("Repository")); final Map<String, String> stringStringMap2 = SourceCodeRepoFactory .parseGitUrl("git: Assert.assertNotNull(stringStringMap2); Assert.assertTrue("values not found", stringStringMap2.containsKey("Source") && stringStringMap2.containsKey("Username") && stringStringMap2 .containsKey("Repository")); final Map<String, String> stringStringMap3 = SourceCodeRepoFactory.parseGitUrl("mostly harmless"); Assert.assertNull("should be null", stringStringMap3); }