package me.alb_i986.testing.assertions.retry.internal;

import java.util.concurrent.TimeUnit;

public class Timeout {

    private final long timeout;
    private final TimeUnit timeoutUnit;

    private long startTimeMillis;

    public Timeout(long timeout, TimeUnit timeoutUnit) {
        this.timeout = timeout;
        this.timeoutUnit = timeoutUnit;
        restart();
    }

    //TODO allow unit tests to inject a mocked Clock (with Joda time or jdk8)

    /**
     * Reset the timeout so that it starts over.
     */
    public void restart() {
        this.startTimeMillis = System.currentTimeMillis();
    }

    /**
     * @return true if the timeout has expired since the last invocation to {@link #restart()}
     */
    public boolean isExpired() {
        return getElapsedTimeMillis() > timeoutUnit.toMillis(timeout);
    }

    public long getElapsedTimeMillis() {
        return System.currentTimeMillis() - startTimeMillis;
    }
}

@@ -211,21 +211,20 @@
 tartTime
-Milli
+Nano
 s;%0A%0A    
@@ -568,21 +568,20 @@
 tartTime
-Milli
+Nano
 s = Syst
@@ -583,33 +583,24 @@
  System.
-currentTimeMillis
+nanoTime
 ();%0A    
@@ -884,32 +884,53 @@
 urn 
-System.currentTimeMillis
+TimeUnit.NANOSECONDS.toMillis(System.nanoTime
 () -
@@ -939,22 +939,22 @@
 tartTime
-Millis
+Nanos)
 ;%0A    %7D%0A

Fix Timeout: System.currentTimeMillis is not precise