### Question:
BoundedExponentialBackoff { long nextBackoff() { int jitter = mJitterMillis == 0 ? 0 : mRandom.nextInt(mJitterMillis); long backoff = mCurrentBackoffDurationMillis + (long) jitter; mCurrentBackoffDurationMillis <<= 1; if (mCurrentBackoffDurationMillis > mMaxBackoffMillis) { mCurrentBackoffDurationMillis = mMaxBackoffMillis; } return backoff; } BoundedExponentialBackoff(long initialBackoffMillis, long maxBackoffMillis, int jitterMillis);   }### Answer:
@Test public void testNextBackOffNoJitterFirstCall() { BoundedExponentialBackoff backoff = new BoundedExponentialBackoff(INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, 0); assertThat(backoff.nextBackoff()).isEqualTo(INITIAL_BACKOFF_MS); }
@Test public void testNextBackoffNoJitterMultipleCalls() { BoundedExponentialBackoff backoff = new BoundedExponentialBackoff(INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, 0); assertThat(backoff.nextBackoff()).isEqualTo(1); assertThat(backoff.nextBackoff()).isEqualTo(2); assertThat(backoff.nextBackoff()).isEqualTo(4); assertThat(backoff.nextBackoff()).isEqualTo(8); assertThat(backoff.nextBackoff()).isEqualTo(MAX_BACKOFF_MS); }
@Test public void testNextBackoffWithJitterFirstCall() { BoundedExponentialBackoff backoff = new BoundedExponentialBackoff(INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, MAX_JITTER_MS); long result = backoff.nextBackoff(); assertThat(result).isAtLeast(INITIAL_BACKOFF_MS); assertThat(result).isAtMost(INITIAL_BACKOFF_MS + (long) MAX_JITTER_MS); }
@Test public void testNextBackoffWithJitterMultipleCalls() { BoundedExponentialBackoff backoff = new BoundedExponentialBackoff(INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, MAX_JITTER_MS); long expectedMin = INITIAL_BACKOFF_MS; for (int i = 0; i < ITERATIONS_TO_MAX; i++) { long result = backoff.nextBackoff(); assertThat(result).isAtLeast(expectedMin); assertThat(result).isAtMost(expectedMin + (long) MAX_JITTER_MS); expectedMin <<= 1; } }
@Test public void testNextBackoffWithJitterStopsAtMax() { BoundedExponentialBackoff backoff = new BoundedExponentialBackoff(INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, MAX_JITTER_MS); for (int i = 0; i < ITERATIONS_TO_MAX; i++) { backoff.nextBackoff(); } for (int i = 0; i < 100; i++) { long result = backoff.nextBackoff(); assertThat(result).isAtLeast(MAX_BACKOFF_MS); assertThat(result).isAtMost(MAX_BACKOFF_MS + (long) MAX_JITTER_MS); } }