I want to test some methods of the class that contain logic depending on the current time of its launch. I would like to set the / jvm / system stream time to a specific future date in JUnit setup and run my tests. Also I would like it to be temporary. Has anyone done this before?
I was thinking of something like TimeZone.setDefault (timezone)
You can use AspectJ and roundabout methods java.lang.System.currentTimeMillis(), java.util.Date.new()and java.util.Calendar.getInstance(), which adjust the time to suit your needs.
java.lang.System.currentTimeMillis()
java.util.Date.new()
java.util.Calendar.getInstance()
, java.util.Date.
joda-time, . . this
. , , TimeHelper, : Date factory, DateFormatters .., .
Easymock , , .
. long, - , TimeZone. , "" TimeZone, , , ; long, , TimeZone, - , .
long
TimeZone
, "" , . , TimeZone , , , .
, - . , !
.