SshUtils implements InitializingBean { public void sendFileToHost(File localfilePath, String remoteFileName, String remotePath, String address) { Connection sshConnectionWithHost = getSshConnectionWithHost(address); try { authenticateSshSessionWithPublicKey(sshConnectionWithHost); SCPClient scp = new SCPClient(sshConnectionWithHost); scp.put(localfilePath.getAbsolutePath(), remoteFileName, remotePath, "0755"); } catch (IOException e) { logger.error(String.format("Error while sending file [%s] to host [%s]", localfilePath, address), e); } sshConnectionWithHost.close(); }  void executeCommandOnHostViaSsh(String hostIp, String command); void sendFileToHost(File localfilePath, String remoteFileName, String remotePath, String address); @Override void afterPropertiesSet();  }
@Test @PrepareForTest(SshUtils.class) public void sendFileToHostTest() throws Exception { File localfilePath = Mockito.mock(File.class); SCPClient scp = configureSendFileToHostTest(localfilePath); spy.sendFileToHost(localfilePath, "remoteFileName", "remotePath", "address"); verifySendFileToHostTest(localfilePath, scp, 1, 1); }