@Test public void shouldAlwaysReturnSameElementForSingletonCollection() { String someString = "Hi"; Generator<String> someGenerator = new RandomFromCollectionGenerator<>(singleton(someString)); for (int i = 0; i < 3; i++) { String generatedString = someGenerator.next(); assertThat(generatedString, is(someString)); } }
@Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); @Override T next(); }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); @Override T next();  }