@Test public void shouldReturnPositiveIntegerBetweenFromInclusiveAndToExclusive() { long from = 13; long to = 20; Generator<Long> randomPositiveLongGenerator = new RandomPositiveLongGenerator(from, to); Set<Long> generatedNumbers = newHashSet(); for (int i = 0; i < 100; i++) { Long generatedLong = randomPositiveLongGenerator.next(); assertThat(generatedLong, greaterThanOrEqualTo(from)); assertThat(generatedLong, lessThan(to)); generatedNumbers.add(generatedLong); } assertThat(generatedNumbers, hasSize(greaterThan(5))); }
@Override public Long next() { return from + random.nextLong(to - from); }
RandomPositiveLongGenerator implements Generator<Long> { @Override public Long next() { return from + random.nextLong(to - from); } }
RandomPositiveLongGenerator implements Generator<Long> { @Override public Long next() { return from + random.nextLong(to - from); } RandomPositiveLongGenerator(long from, long to);  RandomPositiveLongGenerator(); }
RandomPositiveLongGenerator implements Generator<Long> { @Override public Long next() { return from + random.nextLong(to - from); } RandomPositiveLongGenerator(long from, long to);  RandomPositiveLongGenerator(); @Override Long next(); }
RandomPositiveLongGenerator implements Generator<Long> { @Override public Long next() { return from + random.nextLong(to - from); } RandomPositiveLongGenerator(long from, long to);  RandomPositiveLongGenerator(); @Override Long next();  }