ExtendedRetryTemplate extends RetryTemplate { public <T> Callable<T> asCallable(final RetryCallback<T, Exception> callback) { return new Callable<T>() { public T call() throws Exception { return ExtendedRetryTemplate.this.execute(callback); } }; } ExtendedRetryTemplate(); Callable<T> asCallable(final RetryCallback<T, Exception> callback); Callable<T> asCallable(final Callable<T> callable); T execute(final Callable<T> callable); T execute(final Callable<T> callable, RetryState retryState); T execute(final Callable<T> callable, RecoveryCallback<T> recoveryCallback, RetryState retryState);  }
@Test public void test_asCallable_callable() throws Exception { Callable<Long> callable = Mockito.mock(Callable.class); ExtendedRetryTemplate template = new ExtendedRetryTemplate(); Mockito.when(callable.call()).thenReturn(10L); Callable<Long> wrapped = template.asCallable(callable); Assert.assertEquals(10L, wrapped.call().longValue()); Mockito.verify(callable, Mockito.times(1)).call(); }
@Test public void test_asCallable_callback() throws Exception { RetryCallback<Long, Exception> callback = Mockito.mock(RetryCallback.class); ExtendedRetryTemplate template = new ExtendedRetryTemplate(); Mockito.when(callback.doWithRetry(Mockito.any(RetryContext.class))).thenReturn(10L); Callable<Long> wrapped = template.asCallable(callback); Assert.assertEquals(10L, wrapped.call().longValue()); Mockito.verify(callback, Mockito.times(1)).doWithRetry(Mockito.any(RetryContext.class)); }