@Test public void testStartShell() throws IOException { SshConfig config = new SshConfig("localhost", "me"); Session session = mock(Session.class); when(client.startSession()).thenReturn(session); Shell shell = mock(Shell.class); when(session.startShell()).thenReturn(shell); OutputStream shellOutput = new ByteArrayOutputStream(); when(shell.getOutputStream()).thenReturn(shellOutput); InputStream shellInput = new ByteArrayInputStream(new byte[1000]); when(shell.getInputStream()).thenReturn(shellInput); InputStream shellError = new ByteArrayInputStream(new byte[1000]); when(shell.getErrorStream()).thenReturn(shellError); @SuppressWarnings("resource") InteractiveSession shellSession = new SshConnection(config, client).startShell(); verify(session).allocateDefaultPTY(); assertThat(shellSession.getInputStream(), is(shellInput)); assertThat(shellSession.getOutputStream(), is(shellOutput)); assertThat(shellSession.getErrorStream(), is(shellError)); }
public InteractiveSession startShell() throws IOException { Session session = client.startSession(); session.allocateDefaultPTY(); Shell shell = session.startShell(); return new ShellSession(shell); }
SshConnection implements AutoCloseable, CommandExecutor { public InteractiveSession startShell() throws IOException { Session session = client.startSession(); session.allocateDefaultPTY(); Shell shell = session.startShell(); return new ShellSession(shell); } }
SshConnection implements AutoCloseable, CommandExecutor { public InteractiveSession startShell() throws IOException { Session session = client.startSession(); session.allocateDefaultPTY(); Shell shell = session.startShell(); return new ShellSession(shell); } SshConnection(SshConfig config, SSHClient client); }
SshConnection implements AutoCloseable, CommandExecutor { public InteractiveSession startShell() throws IOException { Session session = client.startSession(); session.allocateDefaultPTY(); Shell shell = session.startShell(); return new ShellSession(shell); } SshConnection(SshConfig config, SSHClient client); SshConfig getConfig(); InteractiveSession startShell(); @Override void close(); @Override ExecutionResult tryExecute(Path workingDirectory, String... cmd); ExecutionResult executeIn(String workingDirectory, String... cmd); ExecutionResult tryExecuteIn(String workingDirectory, String... cmd); void uploadFile(Path localFile, String targetPath); void writeTextFile(String targetPath, String contents); String readTextFile(String remotePath); void downloadFile(String remotePath, Path localPath); }
SshConnection implements AutoCloseable, CommandExecutor { public InteractiveSession startShell() throws IOException { Session session = client.startSession(); session.allocateDefaultPTY(); Shell shell = session.startShell(); return new ShellSession(shell); } SshConnection(SshConfig config, SSHClient client); SshConfig getConfig(); InteractiveSession startShell(); @Override void close(); @Override ExecutionResult tryExecute(Path workingDirectory, String... cmd); ExecutionResult executeIn(String workingDirectory, String... cmd); ExecutionResult tryExecuteIn(String workingDirectory, String... cmd); void uploadFile(Path localFile, String targetPath); void writeTextFile(String targetPath, String contents); String readTextFile(String remotePath); void downloadFile(String remotePath, Path localPath);  }