title: Mocking Sftp class skip method call
body: <pre><code>public class SFTP {
  
      public Map&lt;Report, TransferStatus&gt; transfer(List&lt;Report&gt; reports) {
         //testing logic here
       }
  
      private ChannelSftp channelSftp;
      private Session session;
  
  
      private TransferStatus send(File file) {
                  connect();
  
                  send(stream, file.getName());      
      }
  
  
      private void send(FileInputStream stream, String name) throws SftpException, IOException {
  
          channelSftp.put(stream, fileNameWithId, new SftpLogMonitor(), ChannelSftp.OVERWRITE);
          stream.close();
      }
  
  
      private void connect() throws JSchException {
  
          if (session != null &amp;&amp; channelSftp != null) {
              return;
          }
  
          JSch jsch = new JSch();
  
          jsch.addIdentity(sftpConfig.getSftpPublicKey());
  
          session = jsch.getSession(sftpConfig.getSftpUser(), sftpConfig.getSftpHost(), Integer.parseInt(sftpConfig.getSftpPort()));
  
          session.setUserInfo(new JschUserInfo());
          session.setConfig("StrictHostKeyChecking", "no");
  
          session.connect();
  
          Channel channel = session.openChannel("sftp");
          channelSftp = (ChannelSftp) channel;
          channelSftp.connect();
      }
  </code></pre>
  
  <p>Given the above, how can I avoid the calls to <code>JSch</code> objects. I want to avoid sending of the file to remote server and just want to validate test cases in <code>transfer()</code> method. </p>
  
  <p>So far I have the following settings:</p>
  
  <pre><code>   private JSch jSch = mock(JSch.class);
      private Session session = mock(Session.class);
      private ChannelSftp sftp = mock(ChannelSftp.class);
  
  
      @Before
      public void setUp() throws Exception {
          when(jSch.getSession(eq(USERNAME), eq(HOSTNAME), eq(PORT))).thenReturn(session);
          when(session.openChannel("sftp")).thenReturn(sftp);
          //doNothing().when(sftp).put(Matchers.any());
  
      }
  </code></pre>
  
  <p>I don't want to exclude the call to <code>put()</code> or pass throw it to the next statement in the method. </p>