title: Mock direct instantiation of classes
body: <p>I'm often confronted with the problem of mocking direct instantiations of classes:</p>
  
  <pre><code>final File configFile = new File(pathFile);
  </code></pre>
  
  <p>I'd like to mock <code>new File(pathFile)</code> in order to make a <code>doReturn(otherFile)</code>.</p>
  
  <p>I found that I could mock the direct instantiation by wrapping it in another method. Thing is I don't want to amend all my code by creating methods for instantiations just for unit testing, that would be ugly.</p>
  
  <p>Is there any other way?</p>