I have the following method which take a UNIX time stamp and returns the age in terms of days, hours, or minutes. I want to unit test it with JUnit but I'm unsure how I would start doing that as the current time is constantly changing. Any advice? Thanks!
Here is the method:
public static String getAge(long unixTime) throws Exception {
long diff = (System.currentTimeMillis() / 1000) - unixTime;
diff = diff / 60;
if (diff < 60) {
return Math.round(diff) + " m";
}
else
diff /= 60;
if (diff < 24) {
return Math.round(diff) + " h";
}
else {
diff /= 24;
return Math.round(diff) + " d";
}
}