title: Using Apache Mina as a Mock/In Memory SFTP Server for Unit Testing
body: <p>I am having a bit of trouble working out how to use Apache Mina. Their documentation is a bit scant for my talentless brain to work out. I have seen the helpful starting code at
  <a href="https://stackoverflow.com/questions/3076443/java-sftp-server-library">Java SFTP server library?</a></p>
  
  <p>What I can't figure out is how to use it. I want to setup a unit test that checks my sftp code, using Mina as a kind of mock server, i.e., be able to write a unit test like:</p>
  
  <pre><code>@Before 
  public void beforeTestSetup() {
      sshd = SshServer.setUpDefaultServer();
      sshd.setPort(22);
      sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
  
      List&lt;NamedFactory&lt;UserAuth&gt;&gt; userAuthFactories = new ArrayList&lt;NamedFactory&lt;UserAuth&gt;&gt;();
      userAuthFactories.add(new UserAuthNone.Factory());
      sshd.setUserAuthFactories(userAuthFactories);
      sshd.setPublickeyAuthenticator(new PublickeyAuthenticator());
  
  
      sshd.setCommandFactory(new ScpCommandFactory());
  
      List&lt;NamedFactory&lt;Command&gt;&gt; namedFactoryList = new ArrayList&lt;NamedFactory&lt;Command&gt;&gt;();
      namedFactoryList.add(new SftpSubsystem.Factory());
      sshd.setSubsystemFactories(namedFactoryList);
  
      try {
          sshd.start();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  @Test
  public void testGetFile() {
  
  }
  </code></pre>
  
  <p>The question is what to put in <code>testGetFile()</code>.</p>
  
  <p>I've been trawling through the test code wondering whether more configuration is needed in the above to specify a root directory, a user name and an authentication key file name. Then I'll need to get and pull files from it using a client, or my own SFTP api code?</p>
  
  <p>I'm sure this is an excellent API, there's just not a lot of instruction for it, can anyone help?</p>