title: Java Unit Testing method that uses new Date() for current date
body: <p>So I have a class that has a method "getDaysUntil(Date date)" which returns the number of days until the date given as parameter. I mention that I cannot change the class below:</p>
  
  <pre><code>public class A {
  
  public int getDaysUntil(Date givenDate) {
  
      ... // code
  
      Date currentDate = new Date() //it creates a date object holding the current day
  
      ...// code that calculates the nr of days between currentDate and givenDate.
  
  }
  </code></pre>
  
  <p>I have to do some unit testing and you might see the problem, it creates currentDate inside the method and the returned value will be different from day to day. I have tried to mock a Date object or "override" System.currentTimeMillis() with PowerMock but to no avail.</p>
  
  <p>Is there any way to properly test these kind of methods?</p>