title: java unit test mock HttpClient and webdav
body: <p>Hello I have a class for doing webdav related operations such as creating a directory, Implementatiion can be seen below (the createDir method). The question is how to test it nicely, perhaps using EasyMock or a similar lib. Any ideas? thanks!</p>
  
  <pre><code>package foobar;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException; 
  
  import org.apache.commons.httpclient.*;
  import org.apache.commons.httpclient.HttpMethod;
  import org.apache.commons.httpclient.methods.DeleteMethod;
  import org.apache.commons.httpclient.methods.GetMethod;
  import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
  import org.apache.commons.httpclient.methods.PutMethod;
  import org.apache.commons.httpclient.methods.RequestEntity;
  
  import org.apache.jackrabbit.webdav.client.methods.DavMethod;
  import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import mypackage.httpdclient.util.URLHandler;
  
  
  public class WebDavImpl{
  
      private static final String SEPARATOR = " ----- ";
      private HttpClient httpClient;
      public StorageSpaceClientImpl() {
          httpClient = new HttpClient();
      }
  
      public String createDir(String dirName) {
  
          String response = null;
          String url = URLHandler.getInstance().getDirectoryUrl(dirName);
          DavMethod mkcol = new MkColMethod(url);
          try {
              httpClient.executeMethod(mkcol);
              response = mkcol.getStatusCode() + SEPARATOR + mkcol.getStatusText();
  
          } catch (IOException ex) {
  
          } finally {
              mkcol.releaseConnection();
          }
  
          return response;
      }
  
     }
  </code></pre>