Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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