### Question:
ContinuumScmUtils { public static ContinuumScmConfiguration setSCMCredentialsforSSH( ContinuumScmConfiguration config, String scmUrl, String scmUsername, String scmPassword ) { String sshScmUsername = ""; String sshScmPassword = ""; String providerType = ScmUrlUtils.getProvider( scmUrl ); String scmSpecificUrl = scmUrl.substring( providerType.length() + 5 ); if ( providerType.contains( GIT_SCM_PROVIDERTYPE ) && scmSpecificUrl.startsWith( GitScmProviderRepository.PROTOCOL_SSH ) ) { scmSpecificUrl = scmSpecificUrl.substring( GitScmProviderRepository.PROTOCOL_SSH.length() + 3 ); int indexAt = scmSpecificUrl.indexOf( "@" ); if ( indexAt >= 0 ) { String userInfo = scmSpecificUrl.substring( 0, indexAt ); sshScmUsername = userInfo; int indexPwdSep = userInfo.indexOf( ":" ); if ( indexPwdSep < 0 ) { sshScmUsername = userInfo.substring( indexPwdSep + 1 ); } else { sshScmUsername = userInfo.substring( 0, indexPwdSep ); sshScmPassword = userInfo.substring( indexPwdSep + 1 ); } } } if ( StringUtils.isBlank( sshScmUsername ) ) { config.setUsername( scmUsername ); config.setPassword( scmPassword ); } else { config.setUsername( sshScmUsername ); if ( !StringUtils.isBlank( sshScmPassword ) ) { config.setPassword( sshScmPassword ); } } return config; }  static ContinuumScmConfiguration setSCMCredentialsforSSH( ContinuumScmConfiguration config, String scmUrl,
                                                                     String scmUsername, String scmPassword ); static final String GIT_SCM_PROVIDERTYPE; }### Answer:
@Test public void testGitProviderWithSSHProtocolUsernameInUrl() throws Exception { ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration(); scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration, "scm:git:ssh: "dummyuser", "dummypassword" ); assertEquals( "sshUser", scmConfiguration.getUsername() ); assertTrue( StringUtils.isBlank( scmConfiguration.getPassword() ) ); }
@Test public void testGitProviderWithSSHProtocolUsernameAndPasswordInUrl() throws Exception { ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration(); scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration, "scm:git:ssh: "dummyuser", "dummypassword" ); assertEquals( "sshUser", scmConfiguration.getUsername() ); assertEquals( "sshPassword", scmConfiguration.getPassword() ); }
@Test public void testGitProviderWithSSHProtocolNoCredentialsInUrl() throws Exception { ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration(); scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration, "scm:git:ssh: "dummyuser", "dummypassword" ); assertEquals( "dummyuser", scmConfiguration.getUsername() ); assertEquals( "dummypassword", scmConfiguration.getPassword() ); }
@Test public void testNotGitProvider() throws Exception { ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration(); scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration, "scm:svn:ssh: "dummyuser", "dummypassword" ); assertEquals( "dummyuser", scmConfiguration.getUsername() ); assertEquals( "dummypassword", scmConfiguration.getPassword() ); }
@Test public void testNotSSHProtocol() throws Exception { ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration(); scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration, "scm:git:https: "dummyuser", "dummypassword" ); assertEquals( "dummyuser", scmConfiguration.getUsername() ); assertEquals( "dummypassword", scmConfiguration.getPassword() ); }