### Question:
RandomGenerator extends AbstractGenerator<T> { @Override public T next() { return elements.get(random.nextInt(elements.size())); } RandomGenerator(Iterable<? extends T> iterable);  RandomGenerator(Iterable<? extends T> iterable, Random random); @Override T next(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void shouldGenerateAnIndexAtRandomAndReturnTheElementAtThatIndex() throws Exception { Random random = mock(Random.class); RandomGenerator<String> generator = new RandomGenerator<String>( iterableWith("zeroth", "first", "second"), random); ArgumentCaptor<Integer> argumentCaptor = ArgumentCaptor.forClass(Integer.class); when(random.nextInt(argumentCaptor.capture())).thenReturn(1); String value = generator.next(); assertThat(argumentCaptor.getValue(), is(3)); assertThat(value, is("first")); }