Skip to content

Instantly share code, notes, and snippets.

@kikers25
Created January 8, 2017 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikers25/2e7213ea0d42e71234cba180aea5b45e to your computer and use it in GitHub Desktop.
Save kikers25/2e7213ea0d42e71234cba180aea5b45e to your computer and use it in GitHub Desktop.
Unit tests with dates 10
public class SystemTime {
private static TimeSource defaultSource = new TimeSource() {
public long millis() {
return System.currentTimeMillis();
}
};
private static TimeSource source = defaultSource;
public static Date asDate() {
return new Date(getTimeSource().millis());
}
public static void reset() {
setTimeSource(null);
}
public static void setTimeSource(TimeSource source) {
SystemTime.source = source;
}
private static TimeSource getTimeSource() {
return (source != null ? source : defaultSource);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment