java - How to override the current system date within junits -
i want curent system date overriden junits.please help.
one technique use not call usual date/calendar factory methods/constructors, nor system.getcurrenttimemillis. instead inject date/time "factory," namely interface methods whatever need in way of getting system time.
then during test inject instance control directly (hard-coding time, or storing in file, depending on i'm testing). otherwise inject implementation makes appropriate real calls system.
it's not work sounds, , makes testing time/date-sensitive code straightforward.
Comments
Post a Comment