diff --git a/src/main/java/com/github/rholder/retry/StopStrategies.java b/src/main/java/com/github/rholder/retry/StopStrategies.java index e8a0969..3790176 100644 --- a/src/main/java/com/github/rholder/retry/StopStrategies.java +++ b/src/main/java/com/github/rholder/retry/StopStrategies.java @@ -100,7 +100,7 @@ private static final class StopAfterAttemptStrategy implements StopStrategy { private final int maxAttemptNumber; public StopAfterAttemptStrategy(int maxAttemptNumber) { - Preconditions.checkArgument(maxAttemptNumber >= 1, "maxAttemptNumber must be >= 1 but is %d", maxAttemptNumber); + Preconditions.checkArgument(maxAttemptNumber >= 1, "maxAttemptNumber must be >= 1 but is %s", maxAttemptNumber); this.maxAttemptNumber = maxAttemptNumber; } @@ -115,7 +115,7 @@ private static final class StopAfterDelayStrategy implements StopStrategy { private final long maxDelay; public StopAfterDelayStrategy(long maxDelay) { - Preconditions.checkArgument(maxDelay >= 0L, "maxDelay must be >= 0 but is %d", maxDelay); + Preconditions.checkArgument(maxDelay >= 0L, "maxDelay must be >= 0 but is %s", maxDelay); this.maxDelay = maxDelay; } diff --git a/src/main/java/com/github/rholder/retry/WaitStrategies.java b/src/main/java/com/github/rholder/retry/WaitStrategies.java index fb2c5da..9338495 100644 --- a/src/main/java/com/github/rholder/retry/WaitStrategies.java +++ b/src/main/java/com/github/rholder/retry/WaitStrategies.java @@ -234,7 +234,7 @@ private static final class FixedWaitStrategy implements WaitStrategy { private final long sleepTime; public FixedWaitStrategy(long sleepTime) { - Preconditions.checkArgument(sleepTime >= 0L, "sleepTime must be >= 0 but is %d", sleepTime); + Preconditions.checkArgument(sleepTime >= 0L, "sleepTime must be >= 0 but is %s", sleepTime); this.sleepTime = sleepTime; } @@ -251,8 +251,8 @@ private static final class RandomWaitStrategy implements WaitStrategy { private final long maximum; public RandomWaitStrategy(long minimum, long maximum) { - Preconditions.checkArgument(minimum >= 0, "minimum must be >= 0 but is %d", minimum); - Preconditions.checkArgument(maximum > minimum, "maximum must be > minimum but maximum is %d and minimum is", maximum, minimum); + Preconditions.checkArgument(minimum >= 0, "minimum must be >= 0 but is %s", minimum); + Preconditions.checkArgument(maximum > minimum, "maximum must be > minimum but maximum is %s and minimum is", maximum, minimum); this.minimum = minimum; this.maximum = maximum; @@ -272,7 +272,7 @@ private static final class IncrementingWaitStrategy implements WaitStrategy { public IncrementingWaitStrategy(long initialSleepTime, long increment) { - Preconditions.checkArgument(initialSleepTime >= 0L, "initialSleepTime must be >= 0 but is %d", initialSleepTime); + Preconditions.checkArgument(initialSleepTime >= 0L, "initialSleepTime must be >= 0 but is %s", initialSleepTime); this.initialSleepTime = initialSleepTime; this.increment = increment; } @@ -291,9 +291,9 @@ private static final class ExponentialWaitStrategy implements WaitStrategy { public ExponentialWaitStrategy(long multiplier, long maximumWait) { - Preconditions.checkArgument(multiplier > 0L, "multiplier must be > 0 but is %d", multiplier); - Preconditions.checkArgument(maximumWait >= 0L, "maximumWait must be >= 0 but is %d", maximumWait); - Preconditions.checkArgument(multiplier < maximumWait, "multiplier must be < maximumWait but is %d", multiplier); + Preconditions.checkArgument(multiplier > 0L, "multiplier must be > 0 but is %s", multiplier); + Preconditions.checkArgument(maximumWait >= 0L, "maximumWait must be >= 0 but is %s", maximumWait); + Preconditions.checkArgument(multiplier < maximumWait, "multiplier must be < maximumWait but is %s", multiplier); this.multiplier = multiplier; this.maximumWait = maximumWait; } @@ -315,9 +315,9 @@ private static final class FibonacciWaitStrategy implements WaitStrategy { private final long maximumWait; public FibonacciWaitStrategy(long multiplier, long maximumWait) { - Preconditions.checkArgument(multiplier > 0L, "multiplier must be > 0 but is %d", multiplier); - Preconditions.checkArgument(maximumWait >= 0L, "maximumWait must be >= 0 but is %d", maximumWait); - Preconditions.checkArgument(multiplier < maximumWait, "multiplier must be < maximumWait but is %d", multiplier); + Preconditions.checkArgument(multiplier > 0L, "multiplier must be > 0 but is %s", multiplier); + Preconditions.checkArgument(maximumWait >= 0L, "maximumWait must be >= 0 but is %s", maximumWait); + Preconditions.checkArgument(multiplier < maximumWait, "multiplier must be < maximumWait but is %s", multiplier); this.multiplier = multiplier; this.maximumWait = maximumWait; } diff --git a/src/test/java/com/github/rholder/retry/StopStrategiesTest.java b/src/test/java/com/github/rholder/retry/StopStrategiesTest.java index 5cb61b4..bc5ab3b 100644 --- a/src/test/java/com/github/rholder/retry/StopStrategiesTest.java +++ b/src/test/java/com/github/rholder/retry/StopStrategiesTest.java @@ -54,4 +54,9 @@ public void testStopAfterDelayWithTimeUnit() { public Attempt failedAttempt(long attemptNumber, long delaySinceFirstAttempt) { return new Retryer.ExceptionAttempt(new RuntimeException(), attemptNumber, delaySinceFirstAttempt); } + + @Test(expected = IllegalArgumentException.class) + public void testStopWithIllegalArgumentException(){ + StopStrategies.stopAfterAttempt(0); + } }