From bed8cba0b2cffd7b5bf7b5fa678b902f71fa3ba2 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Tue, 11 Jul 2017 18:26:59 +0200 Subject: [PATCH 1/2] set guava max version --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 210cecb..4e5f772 100644 --- a/build.gradle +++ b/build.gradle @@ -81,7 +81,7 @@ repositories { } dependencies { - compile 'com.google.guava:guava:[10.+,)' + compile 'com.google.guava:guava:[10.0,19.0]' compile 'com.google.code.findbugs:jsr305:2.0.2' // junit testing @@ -200,4 +200,4 @@ idea { languageLevel = project_jdk vcs = 'Git' } -} \ No newline at end of file +} From 6c330c64e45c763fc6cbb7d59ca8d479a54586fc Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Tue, 11 Jul 2017 18:29:52 +0200 Subject: [PATCH 2/2] tests --- .../github/rholder/retry/RetryListener.java | 5 ++-- .../com/github/rholder/retry/Retryer.java | 8 +++--- .../github/rholder/retry/RetryerBuilder.java | 2 +- .../rholder/retry/RetryerBuilderTest.java | 27 ++++++++----------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/github/rholder/retry/RetryListener.java b/src/main/java/com/github/rholder/retry/RetryListener.java index f062600..b584a59 100644 --- a/src/main/java/com/github/rholder/retry/RetryListener.java +++ b/src/main/java/com/github/rholder/retry/RetryListener.java @@ -23,14 +23,13 @@ * code through a {@link Retryer} instance. */ @Beta -public interface RetryListener { +public interface RetryListener { /** * This method with fire no matter what the result is and before the * rejection predicate and stop strategies are applied. * * @param attempt the current {@link Attempt} - * @param the type returned by the retryer callable */ - void onRetry(Attempt attempt); + void onRetry(Attempt attempt); } diff --git a/src/main/java/com/github/rholder/retry/Retryer.java b/src/main/java/com/github/rholder/retry/Retryer.java index eaff3ef..a978e4f 100644 --- a/src/main/java/com/github/rholder/retry/Retryer.java +++ b/src/main/java/com/github/rholder/retry/Retryer.java @@ -49,7 +49,7 @@ public final class Retryer { private final BlockStrategy blockStrategy; private final AttemptTimeLimiter attemptTimeLimiter; private final Predicate> rejectionPredicate; - private final Collection listeners; + private final Collection> listeners; /** * Constructor @@ -100,7 +100,7 @@ public Retryer(@Nonnull AttemptTimeLimiter attemptTimeLimiter, @Nonnull WaitStrategy waitStrategy, @Nonnull BlockStrategy blockStrategy, @Nonnull Predicate> rejectionPredicate) { - this(attemptTimeLimiter, stopStrategy, waitStrategy, blockStrategy, rejectionPredicate, new ArrayList()); + this(attemptTimeLimiter, stopStrategy, waitStrategy, blockStrategy, rejectionPredicate, new ArrayList>()); } /** @@ -121,7 +121,7 @@ public Retryer(@Nonnull AttemptTimeLimiter attemptTimeLimiter, @Nonnull WaitStrategy waitStrategy, @Nonnull BlockStrategy blockStrategy, @Nonnull Predicate> rejectionPredicate, - @Nonnull Collection listeners) { + @Nonnull Collection> listeners) { Preconditions.checkNotNull(attemptTimeLimiter, "timeLimiter may not be null"); Preconditions.checkNotNull(stopStrategy, "stopStrategy may not be null"); Preconditions.checkNotNull(waitStrategy, "waitStrategy may not be null"); @@ -163,7 +163,7 @@ public V call(Callable callable) throws ExecutionException, RetryException { attempt = new ExceptionAttempt(t, attemptNumber, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)); } - for (RetryListener listener : listeners) { + for (RetryListener listener : listeners) { listener.onRetry(attempt); } diff --git a/src/main/java/com/github/rholder/retry/RetryerBuilder.java b/src/main/java/com/github/rholder/retry/RetryerBuilder.java index d9c2f16..f79ebb2 100644 --- a/src/main/java/com/github/rholder/retry/RetryerBuilder.java +++ b/src/main/java/com/github/rholder/retry/RetryerBuilder.java @@ -37,7 +37,7 @@ public class RetryerBuilder { private WaitStrategy waitStrategy; private BlockStrategy blockStrategy; private Predicate> rejectionPredicate = Predicates.alwaysFalse(); - private List listeners = new ArrayList(); + private List> listeners = new ArrayList>(); private RetryerBuilder() { } diff --git a/src/test/java/com/github/rholder/retry/RetryerBuilderTest.java b/src/test/java/com/github/rholder/retry/RetryerBuilderTest.java index 9849b96..3446853 100644 --- a/src/test/java/com/github/rholder/retry/RetryerBuilderTest.java +++ b/src/test/java/com/github/rholder/retry/RetryerBuilderTest.java @@ -16,11 +16,11 @@ package com.github.rholder.retry; +import static org.junit.Assert.*; + import com.github.rholder.retry.Retryer.RetryerCallable; import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import org.junit.Test; - import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -30,12 +30,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.junit.Test; public class RetryerBuilderTest { @@ -463,9 +458,9 @@ public void testWhetherBuilderFailsForNullWaitStrategyWithCompositeStrategies() public void testRetryListener_SuccessfulAttempt() throws Exception { final Map attempts = new HashMap(); - RetryListener listener = new RetryListener() { + RetryListener listener = new RetryListener() { @Override - public void onRetry(Attempt attempt) { + public void onRetry(Attempt attempt) { attempts.put(attempt.getAttemptNumber(), attempt); } }; @@ -492,9 +487,9 @@ public void onRetry(Attempt attempt) { public void testRetryListener_WithException() throws Exception { final Map attempts = new HashMap(); - RetryListener listener = new RetryListener() { + RetryListener listener = new RetryListener() { @Override - public void onRetry(Attempt attempt) { + public void onRetry(Attempt attempt) { attempts.put(attempt.getAttemptNumber(), attempt); } }; @@ -531,15 +526,15 @@ public Boolean call() throws Exception { final AtomicBoolean listenerTwo = new AtomicBoolean(false); Retryer retryer = RetryerBuilder.newBuilder() - .withRetryListener(new RetryListener() { + .withRetryListener(new RetryListener() { @Override - public void onRetry(Attempt attempt) { + public void onRetry(Attempt attempt) { listenerOne.set(true); } }) - .withRetryListener(new RetryListener() { + .withRetryListener(new RetryListener() { @Override - public void onRetry(Attempt attempt) { + public void onRetry(Attempt attempt) { listenerTwo.set(true); } })