### Question:
Retrier { public T runWithRetry() { return myRetryTemplate.execute(retryContext -> mySupplier.get()); } Retrier(Supplier<T> theSupplier, int theMaxRetries); T runWithRetry();  }### Answer:
@Test public void happyPath() { Supplier<Boolean> supplier = () -> true; Retrier<Boolean> retrier = new Retrier<>(supplier, 5); assertTrue(retrier.runWithRetry()); }
@Test public void succeedBeforeMaxRetries() { AtomicInteger counter = new AtomicInteger(); Supplier<Boolean> supplier = () -> { if (counter.incrementAndGet() < 3) throw new RetryRuntimeException("test"); return true; }; Retrier<Boolean> retrier = new Retrier<>(supplier, 5); assertTrue(retrier.runWithRetry()); assertEquals(3, counter.get()); }
@Test public void failMaxRetries() { AtomicInteger counter = new AtomicInteger(); Supplier<Boolean> supplier = () -> { if (counter.incrementAndGet() < 3) throw new RetryRuntimeException("test failure message"); return true; }; Retrier<Boolean> retrier = new Retrier<>(supplier, 1); try { retrier.runWithRetry(); fail(); } catch (RetryRuntimeException e) { assertEquals("test failure message", e.getMessage()); } }