@Test public void shouldGenerateEnumRandomly() { Generator<SomeEnum> randomEnumGenerator = new RandomEnumGenerator<>(SomeEnum.class); EnumSet<SomeEnum> enumSet = EnumSet.noneOf(SomeEnum.class); for (int i = 0; i < 20; i++) { enumSet.add(randomEnumGenerator.next()); } assertThat(enumSet, contains(SomeEnum.FIRST, SomeEnum.SECOND, SomeEnum.THIRD)); }
@Override @SuppressWarnings("unchecked") public T next() { return enums[random.nextInt(enums.length)]; }
RandomEnumGenerator implements Generator<T> { @Override @SuppressWarnings("unchecked") public T next() { return enums[random.nextInt(enums.length)]; } }
RandomEnumGenerator implements Generator<T> { @Override @SuppressWarnings("unchecked") public T next() { return enums[random.nextInt(enums.length)]; } RandomEnumGenerator(@Nonnull Class<T> enumClass); }
RandomEnumGenerator implements Generator<T> { @Override @SuppressWarnings("unchecked") public T next() { return enums[random.nextInt(enums.length)]; } RandomEnumGenerator(@Nonnull Class<T> enumClass); @Override @SuppressWarnings("unchecked") //generated class is always of type T T next(); }
RandomEnumGenerator implements Generator<T> { @Override @SuppressWarnings("unchecked") public T next() { return enums[random.nextInt(enums.length)]; } RandomEnumGenerator(@Nonnull Class<T> enumClass); @Override @SuppressWarnings("unchecked") //generated class is always of type T T next();  }