title: Mock File class and NullPointerException
body: <p>I'm creating a File mock object with Mockito that will be used as the directory to store a new  File. </p>
  
  <pre><code>Folder folder = Mockito.mock(File.class);
  File file = new Agent().createNewFile(folder, "fileName");
  </code></pre>
  
  <p>and inside my Agent class:</p>
  
  <pre><code>public File createNewFile(File folder, String filename){
      return new File(folder, "testfile");
  }
  </code></pre>
  
  <p>But I'm getting a NullPointerException at the initialization block of File when creating the new file inside <code>createNewFile</code> method:</p>
  
  <pre><code>java.lang.NullPointerException at java.io.File.&lt;init&gt;(File.java:308)
  </code></pre>
  
  <p>I think it happens because File doesn't have any empty constructor, so when mocking the object some internal state remains null.</p>
  
  <p>Am I taking the wrong approach mocking the <code>File folder</code> object? My goal is to check some constraints before creating the new file, but I don't want to depend on an existing real folder on the file system.</p>
  
  <p>Thank you.</p>