### Question:
Retry { public T run() throws Exception { try { return execute(); } catch(Exception e) { if (e.getClass().equals(retryExceptionType)){ tries++; if (MAX_RETRIES == tries) { throw e; } else { return run(); } } else { throw e; } } } Retry(Class exceptionClassType); abstract T execute(); T run(); T runWithDelay(); static final int MAX_RETRIES; static final int DELAY; }### Answer:
@Test public void testRetrySuccess() { Retry<Void> retriable = new Retry<Void>(NullPointerException.class) { private int count = 0; @Override public Void execute() { if (count < 1) { count++; throw new NullPointerException(); } else { return null; } } }; try { retriable.run(); } catch (Exception e) { Assert.fail(); } }
@Test public void testRetryFailure() { Retry<Void> retriable = new Retry<Void>(NullPointerException.class) { @Override public Void execute() { throw new RuntimeException(); } }; try { retriable.run(); Assert.fail(); } catch (Exception e) { Assert.assertEquals(RuntimeException.class, e.getClass()); } }