title: Is it safe to use DateTimeUtils.setCurrentMillisFixed in tests?
body: <p>In order to test time-dependent code it's good to use <a href="http://ducktypo.blogspot.ru/2013/12/the-virtual-clock-test-pattern.html" rel="noreferrer">Virtual Clock Pattern</a></p>
  
  <p>The idea is that we pull current time not using <code>new Date</code>, but from a clock which can be mocked with virtual clock returning predefined fixed time.</p>
  
  <p>Now in Java we have JodaTime with <code>DateTime</code> class and which allows to set sample time with </p>
  
  <pre><code>DateTimeUtils.setCurrentMillisFixed(today.getMillis());
  </code></pre>
  
  <p>And reset the fixed time to a system time with:</p>
  
  <pre><code>DateTimeUtils.setCurrentMillisSystem();
  </code></pre>
  
  <p>Here is a <a href="http://blog.zilverline.com/2011/01/14/fixing-date-in-test-using-junit-methodrule/" rel="noreferrer">good article</a> on how to use it with TestNG.</p>
  
  <p>Now the question!</p>
  
  <p>How safe it's to use this technique with setUp and tearDown methods if it globally sets fixed time in global context for the time of running test. As long as I get it - it will only work as long as we don't have two concurrent tests with this technique running in the same environment in parallel.</p>