title: Robolectric 3.0: Mocking System.currentTimeMillis()
body: <p>I'm trying to modify the value returned by System.currentTimeMillis() so I can do operations like: write something to the database, simulate waiting 5 minutes, do a query on the database (the query is dependent on when the value is written). </p>
  
  <p>The code suggested in [this SO thread]:</p>
  
  <pre><code>ShadowSystemClock shadowClock = Robolectric.shadowOf(SystemClock.class);
  shadowClock.setCurrentTimeMillis(1424369871446);
  </code></pre>
  
  <p>Does not compile since the shadowOf method was removed. Trying alternatives like:</p>
  
  <pre><code>ShadowSystemClock shadowClock = new ShadowSystemClock();
  shadowClock.setCurrentTimeMillis(1424369871446);
  </code></pre>
  
  <p>It appears there were <a href="https://github.com/robolectric/robolectric/issues/1590" rel="noreferrer">issues with overriding currentTimeMillis()</a> but those issues should be fixed as of version 3.0. </p>
  
  <p>I could add <a href="https://github.com/jayway/powermock" rel="noreferrer">PowerMock</a> to my project and use that for this case I think, but if this is do-able with Robolectric, I'd prefer that.</p>
  
  <p><strong>Update</strong>: Getting closer, but might be missing something. This code:</p>
  
  <pre><code>ShadowSystemClock shadowClock = new ShadowSystemClock();
  
  Log("system = " + System.currentTimeMillis() + "; shadow = " + shadowClock.currentTimeMillis() + "; time from code = " + Code.getSystemTime());
  
  shadowClock.setCurrentTimeMillis(50000000L);
  
  Log("system = " + System.currentTimeMillis() + "; shadow = " + shadowClock.currentTimeMillis() + "; time from code = " + Code.getSystemTime());
  </code></pre>
  
  <p>Outputs this:</p>
  
  <pre><code>system = 1438212006879; shadow = 0; time from code = 1438212006894
  system = 1438212006898; shadow = 50000000; time from code = 1438212006898
  </code></pre>
  
  <p>Code.getSystemTime() is calling into the codebase being tested. The method simply returns System.currentTimeMillis(). </p>
  
  <p>Seems like things could work if the ShadowSystemClock intercepted the calls to currentTimeMillis(). Is there a way to do that?</p>