@Test public void testInstallGitSkipsIfAlreadyInstalled() throws IOException { when(connection.tryExecute("which", "git")).thenReturn( new ExecutionResult(0, "", "")); remoteGitHelper.installGit(connection, SystemSpecification.UBUNTU_1404); verify(connection, never()).execute("sudo", "apt-get", "-y", "install", "git"); }
public void installGit(SshConnection connection, SystemSpecification os) throws IOException { if (isGitInstalled(connection)) { return; } if (!SystemSpecification.UBUNTU.equals(os.getDistributionName())) { throw new UnsupportedOperationException( "Only ubuntu is supported for git installation at the moment"); } connection.execute("sudo", "apt-get", "-y", "update"); connection.execute("sudo", "apt-get", "-y", "install", "git"); if (!isGitInstalled(connection)) { throw new IOException("Installed git, but it is not callable afterwards"); } }
RemoteGitHelper { public void installGit(SshConnection connection, SystemSpecification os) throws IOException { if (isGitInstalled(connection)) { return; } if (!SystemSpecification.UBUNTU.equals(os.getDistributionName())) { throw new UnsupportedOperationException( "Only ubuntu is supported for git installation at the moment"); } connection.execute("sudo", "apt-get", "-y", "update"); connection.execute("sudo", "apt-get", "-y", "install", "git"); if (!isGitInstalled(connection)) { throw new IOException("Installed git, but it is not callable afterwards"); } } }
RemoteGitHelper { public void installGit(SshConnection connection, SystemSpecification os) throws IOException { if (isGitInstalled(connection)) { return; } if (!SystemSpecification.UBUNTU.equals(os.getDistributionName())) { throw new UnsupportedOperationException( "Only ubuntu is supported for git installation at the moment"); } connection.execute("sudo", "apt-get", "-y", "update"); connection.execute("sudo", "apt-get", "-y", "install", "git"); if (!isGitInstalled(connection)) { throw new IOException("Installed git, but it is not callable afterwards"); } } protected  RemoteGitHelper(); }
RemoteGitHelper { public void installGit(SshConnection connection, SystemSpecification os) throws IOException { if (isGitInstalled(connection)) { return; } if (!SystemSpecification.UBUNTU.equals(os.getDistributionName())) { throw new UnsupportedOperationException( "Only ubuntu is supported for git installation at the moment"); } connection.execute("sudo", "apt-get", "-y", "update"); connection.execute("sudo", "apt-get", "-y", "install", "git"); if (!isGitInstalled(connection)) { throw new IOException("Installed git, but it is not callable afterwards"); } } protected  RemoteGitHelper(); void installGit(SshConnection connection, SystemSpecification os); boolean isGitInstalled(SshConnection connection); void checkoutHard(SshConnection connection, String remotePath, String revision); void initEmptyRepository(SshConnection connection, String remotePath); }
RemoteGitHelper { public void installGit(SshConnection connection, SystemSpecification os) throws IOException { if (isGitInstalled(connection)) { return; } if (!SystemSpecification.UBUNTU.equals(os.getDistributionName())) { throw new UnsupportedOperationException( "Only ubuntu is supported for git installation at the moment"); } connection.execute("sudo", "apt-get", "-y", "update"); connection.execute("sudo", "apt-get", "-y", "install", "git"); if (!isGitInstalled(connection)) { throw new IOException("Installed git, but it is not callable afterwards"); } } protected  RemoteGitHelper(); void installGit(SshConnection connection, SystemSpecification os); boolean isGitInstalled(SshConnection connection); void checkoutHard(SshConnection connection, String remotePath, String revision); void initEmptyRepository(SshConnection connection, String remotePath);  }