RetryStrategy implements Serializable { public void errorOccured() throws Exception { numberOfTriesLeft--; if (!shouldRetry()) { throw new Exception("Retry Failed: Total " + numberOfRetries + " attempts made at interval " + getTimeToWait() + "ms"); } waitUntilNextTry(); } RetryStrategy();  RetryStrategy(int numberOfRetries, long timeToWait); boolean shouldRetry(); void errorOccured(); long getTimeToWait(); static final int DEFAULT_RETRIES; static final long DEFAULT_WAIT_TIME_IN_MILLI; }
@Test public void testErrorOccured() throws Exception { retry= new RetryStrategy(3, 100); retry.errorOccured(); retry.errorOccured(); Exception ex= null; try { retry.errorOccured(); } catch (Exception e) {ex= e;} assertNotNull("Expected exception after some errors", ex); }