### Question:
RandomJitter implements Jitter { long highJitterBound(BackoffDelay backoff, long jitterOffset) { return Math.min( backoff.max.minus(backoff.delay).toMillis(), jitterOffset); } RandomJitter(double randomFactor); @Override Duration apply(BackoffDelay backoff); @Override String toString();  }### Answer:
@Test void highBoundNormal() { double factor = 0.5; Duration min = Duration.ofMillis(-123); Duration max = Duration.ofMillis(1000); Duration delay = Duration.ofMillis(500); BackoffDelay bd = new BackoffDelay(min, max, delay); RandomJitter jitter = new RandomJitter(factor); assertThat(jitter.highJitterBound(bd, 250)) .isEqualTo(250); }
@Test void highBoundCappedAtMax() { double factor = 0.5; Duration min = Duration.ofMillis(-123); Duration max = Duration.ofMillis(550); Duration delay = Duration.ofMillis(500); BackoffDelay bd = new BackoffDelay(min, max, delay); RandomJitter jitter = new RandomJitter(factor); assertThat(jitter.highJitterBound(bd, 250)) .as("offset over min") .isEqualTo(50); assertThat(jitter.highJitterBound(bd, Long.MAX_VALUE / 2)) .as("offset half long max") .isEqualTo(50); assertThat(jitter.highJitterBound(bd, Long.MAX_VALUE)) .as("offset long max") .isEqualTo(50); }
@Test public void highBoundNormal() { double factor = 0.5; Duration min = Duration.ofMillis(-123); Duration max = Duration.ofMillis(1000); Duration delay = Duration.ofMillis(500); BackoffDelay bd = new BackoffDelay(min, max, delay); RandomJitter jitter = new RandomJitter(factor); assertThat(jitter.highJitterBound(bd, 250)) .isEqualTo(250); }
@Test public void highBoundCappedAtMax() { double factor = 0.5; Duration min = Duration.ofMillis(-123); Duration max = Duration.ofMillis(550); Duration delay = Duration.ofMillis(500); BackoffDelay bd = new BackoffDelay(min, max, delay); RandomJitter jitter = new RandomJitter(factor); assertThat(jitter.highJitterBound(bd, 250)) .as("offset over min") .isEqualTo(50); assertThat(jitter.highJitterBound(bd, Long.MAX_VALUE / 2)) .as("offset half long max") .isEqualTo(50); assertThat(jitter.highJitterBound(bd, Long.MAX_VALUE)) .as("offset long max") .isEqualTo(50); }