### Question:
Retry { public static NeedsRetries builder() { return new RetryFactoryBuilder(); } private  Retry(long maxRetries, long startWait, long waitIncrement, long maxWait, long logInterval,
      double backOffFactor); @VisibleForTesting void setBackOffFactor(double baskOffFactor); @VisibleForTesting double getWaitFactor(); boolean hasInfiniteRetries(); long getLogInterval(); boolean canRetry(); void useRetry(); boolean hasRetried(); long retriesCompleted(); void waitForNextAttempt(); void logRetry(Logger log, String message, Throwable t); void logRetry(Logger log, String message); static NeedsRetries builder();  }### Answer:
@Test public void testMaxRetries() { NeedsRetries builder = Retry.builder(); builder.maxRetries(10); builder.maxRetries(0); assertThrows("Should not allow negative retries", IllegalArgumentException.class, () -> builder.maxRetries(-1)); }
@Test public void testInitialWait() { NeedsRetryDelay builder = Retry.builder().maxRetries(10); builder.retryAfter(10, NANOSECONDS); builder.retryAfter(10, MILLISECONDS); builder.retryAfter(10, DAYS); builder.retryAfter(0, NANOSECONDS); builder.retryAfter(0, MILLISECONDS); builder.retryAfter(0, DAYS); assertThrows("Should not allow negative wait times", IllegalArgumentException.class, () -> builder.retryAfter(-1, NANOSECONDS)); }
@Test public void testIncrementBy() { NeedsTimeIncrement builder = Retry.builder().maxRetries(10).retryAfter(10, MILLISECONDS); builder.incrementBy(10, DAYS); builder.incrementBy(10, HOURS); builder.incrementBy(10, NANOSECONDS); builder.incrementBy(0, DAYS); builder.incrementBy(0, HOURS); builder.incrementBy(0, NANOSECONDS); assertThrows("Should not allow negative increments", IllegalArgumentException.class, () -> builder.incrementBy(-1, NANOSECONDS)); }
@Test public void testMaxWait() { NeedsMaxWait builder = Retry.builder().maxRetries(10).retryAfter(15, MILLISECONDS).incrementBy(10, MILLISECONDS); builder.maxWait(15, MILLISECONDS); builder.maxWait(16, MILLISECONDS); assertThrows("Max wait time should be greater than or equal to initial wait time", IllegalArgumentException.class, () -> builder.maxWait(14, MILLISECONDS)); }
@Test public void testLogInterval() { NeedsLogInterval builder = Retry.builder().maxRetries(10).retryAfter(15, MILLISECONDS) .incrementBy(10, MILLISECONDS).maxWait(16, MINUTES).backOffFactor(1); builder.logInterval(10, DAYS); builder.logInterval(10, HOURS); builder.logInterval(10, NANOSECONDS); builder.logInterval(0, DAYS); builder.logInterval(0, HOURS); builder.logInterval(0, NANOSECONDS); assertThrows("Log interval must not be negative", IllegalArgumentException.class, () -> builder.logInterval(-1, NANOSECONDS)); }