@Test public void shouldReturnPositiveIntegerBetweenFromInclusiveAndToExclusive() { int from = 13; int to = 20; Generator<Integer> randomPositiveIntegerGenerator = new RandomPositiveIntegerGenerator(from, to); Set<Integer> generatedNumbers = newHashSet(); for (int i = 0; i < 100; i++) { Integer integer = randomPositiveIntegerGenerator.next(); assertThat(integer, greaterThanOrEqualTo(from)); assertThat(integer, lessThan(to)); generatedNumbers.add(integer); } assertThat(generatedNumbers, hasSize(greaterThan(5))); }
@Override public Integer next() { return from + random.nextInt(to - from); }
RandomPositiveIntegerGenerator implements Generator<Integer> { @Override public Integer next() { return from + random.nextInt(to - from); } }
RandomPositiveIntegerGenerator implements Generator<Integer> { @Override public Integer next() { return from + random.nextInt(to - from); } RandomPositiveIntegerGenerator(int from, int to);  RandomPositiveIntegerGenerator(); }
RandomPositiveIntegerGenerator implements Generator<Integer> { @Override public Integer next() { return from + random.nextInt(to - from); } RandomPositiveIntegerGenerator(int from, int to);  RandomPositiveIntegerGenerator(); @Override Integer next(); }
RandomPositiveIntegerGenerator implements Generator<Integer> { @Override public Integer next() { return from + random.nextInt(to - from); } RandomPositiveIntegerGenerator(int from, int to);  RandomPositiveIntegerGenerator(); @Override Integer next();  }