### Question:
ReplayingRandom extends Random { @Override public int nextInt(int n) { if (n == 5) { return getNextValueOf(fives, indexInFives++); } else if (n == 9) { return getNextValueOf(nines, indexInNines++); } throw new UnsupportedOperationException("not expected invocation of nextInt(" + n + ")"); } ReplayingRandom(String five, String nine); @Override int nextInt(int n);  }### Answer:
@Test public void shouldReturnExpectedRandomsFor5And9() { assertThat(rand.nextInt(5), equalTo(2)); assertThat(rand.nextInt(9), equalTo(3)); assertThat(rand.nextInt(5), equalTo(3)); assertThat(rand.nextInt(9), equalTo(3)); assertThat(rand.nextInt(5), equalTo(3)); assertThat(rand.nextInt(9), equalTo(8)); assertThat(rand.nextInt(5), equalTo(4)); assertThat(rand.nextInt(9), equalTo(2)); }
@Test(expected = UnsupportedOperationException.class) public void shouldFailForOthers() { rand.nextInt(3); }