SshUtils implements InitializingBean { protected void waitUntilCommandFinishes(String hostIp, String command, Session sshSession) { Integer exitStatus = sshSession.getExitStatus(); while (exitStatus == null) { exitStatus = sshSession.getExitStatus(); threadUtils.sleepThread(5); } logger.info(String.format("Command [%s] executed on [%s] has the following exitStatus [%d]", command, hostIp, exitStatus)); }  void executeCommandOnHostViaSsh(String hostIp, String command); void sendFileToHost(File localfilePath, String remoteFileName, String remotePath, String address); @Override void afterPropertiesSet();  }
@Test public void waitUntilCommandFinishesTest() { Mockito.when(sshSession.getExitStatus()).thenReturn(null, null, new Integer(1)); Mockito.doNothing().when(threadUtils).sleepThread(Mockito.anyInt()); spy.waitUntilCommandFinishes("hostIp", "command", sshSession); Mockito.verify(sshSession, Mockito.times(3)).getExitStatus(); Mockito.verify(threadUtils, Mockito.times(2)).sleepThread(Mockito.eq(5)); }