I am writing code that calculates the date and time with the current time. During Joda, this is achieved through the constructor (Java), since it is an immutable object. I need to be able to scoff at the fact that new DateTime() returns a certain constant moment so that I can make reasonable test statements, but leave all the other DateTime methods.
This proves a nuisance. Grails mockFor(DateTime, true) won't let me scoff at a Java constructor, but there is no obvious or readable non-constructor way to get time during Joda.
The only options available seem to include low-level JVM methods, such as JMockit or the EasyMock 3 class, that cause Grails pain. Is there a simple / easy way to achieve this?
time jodatime mocking grails groovy
Stuart watt
source share