diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java index 4b45209ea..18d4e1060 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RelativeDateFormatterTest.java @@ -51,14 +51,22 @@ import static org.eclipse.jgit.util.RelativeDateFormatter.DAY_IN_MILLIS; import java.util.Date; +import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.util.RelativeDateFormatter; +import org.junit.Before; import org.junit.Test; public class RelativeDateFormatterTest { + @Before + public void setUp() { + SystemReader.setInstance(new MockSystemReader()); + } + private void assertFormat(long ageFromNow, long timeUnit, String expectedFormat) { - Date d = new Date(System.currentTimeMillis() - ageFromNow * timeUnit); + Date d = new Date(SystemReader.getInstance().getCurrentTime() + - ageFromNow * timeUnit); String s = RelativeDateFormatter.format(d); assertEquals(expectedFormat, s); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java index bcbcd808d..203e24799 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RelativeDateFormatter.java @@ -75,7 +75,8 @@ public class RelativeDateFormatter { @SuppressWarnings("boxing") public static String format(Date when) { - long ageMillis = (System.currentTimeMillis() - when.getTime()); + long ageMillis = SystemReader.getInstance().getCurrentTime() + - when.getTime(); // shouldn't happen in a perfect world if (ageMillis < 0)