package me.alb_i986.testing.hamcrest.assertion.retry;

import java.util.concurrent.TimeUnit;

/**
 * Factory methods of wait strategies to feed into {@link RetryConfig.Builder#withWaitStrategy(Runnable)}.
 *
 * <p>Please note: when defining custom strategies, please override {@code toString()} to return
 * a meaningful description of the strategy, e.g. "waiting for a message to be published to the queue myQueue".
 *
 * @author Alberto Scotto
 */
public class WaitStrategies {

    protected WaitStrategies() {
        // static class
    }

    /**
     * @see Thread#sleep(long)
     */
    public static Runnable sleep(long time, TimeUnit timeUnit) {
        return sleep(timeUnit.toMillis(time));
    }

    private static Runnable sleep(final long millis) {
        return new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(millis);
                } catch (InterruptedException e) {
                    // swallow!
                }
            }

            @Override
            public String toString() {
                //TODO improve display of time: if t>1000ms, we should talk about seconds; if t>60s => minutes, etc.
                return "sleep for " + millis + "ms";
            }
        };
    }
}

@@ -546,16 +546,90 @@
     /**%0A
+     * @throws IllegalArgumentException if the integer is negative%0A     *%0A
      * @
@@ -720,24 +720,127 @@
 timeUnit) %7B%0A
+        if (time %3C= 0) %7B%0A            throw new IllegalArgumentException(%22negative timeout%22);%0A        %7D%0A
         retu

Improve WaitStrategie#sleep: fail fast