I want millis
to return specified value.
public long myMethod(){
DateTime nowDateTime = new DateTime(DateTimeZone.UTC);
long millis = no
Just use the org.joda.time.DateTimeUtils#setCurrentMillisFixed
method of JodaTime which was designed to fix new DateTime()
to a different time than the current time. To return to the normal time use org.joda.time.DateTimeUtils#setCurrentMillisSystem
afterwards. No mocking needed.
@Test
public void test() {
DateTimeUtils.setCurrentMillisFixed(10L);
// .. your code
}
@After
public void cleanup() {
// Make sure to cleanup afterwards
DateTimeUtils.setCurrentMillisSystem()
}