Retry { public Retry(int retries, Runnable runnable) { this.retries = retries; this.runnable = runnable; } Retry(int retries, Runnable runnable); Retry run(); boolean isFinished(); int getRemainingRetries();  }
@Test public void testRetry() { { Retry retry = new Retry(5, () -> { }); retry.run(); assertEquals(5, retry.getRemainingRetries()); assertTrue(retry.isFinished()); } { Retry retry = new Retry(5, () -> { throw new RuntimeException("This should fail right here"); }); try { retry.run(); } catch (Exception e) { assertTrue(e instanceof RetryException); } assertEquals(0, retry.getRemainingRetries()); assertFalse(retry.isFinished()); } }