-
-
Save kikers25/2e7213ea0d42e71234cba180aea5b45e to your computer and use it in GitHub Desktop.
Unit tests with dates 10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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