@Test public void shouldCreateRichObject() { String someString = "someString"; Generator<Object> stringGenerator = Generators.<Object>ofInstance(someString); byte age = 25; Generator<Object> byteGenerator = Generators.<Object>ofInstance(age); Function<List<Object>, Person> aggregationFunction = new Function<List<Object>, Person>() { @Override public Person apply(List<Object> input) { return new Person(getFirst(input, null).toString(), (byte) getLast(input, null)); } }; Generator<Person> compositeGenerator = new CompositeGenerator<>(aggregationFunction, asList(stringGenerator, byteGenerator)); Person generatedString = compositeGenerator.next(); assertThat(generatedString, is(new Person(someString, age))); }
@Override public T next() { List<I> generatedValues = newArrayList(); for (Generator<I> generator : stringGenerator) { generatedValues.add(generator.next()); } return aggregationFunction.apply(generatedValues); }
CompositeGenerator implements Generator<T> { @Override public T next() { List<I> generatedValues = newArrayList(); for (Generator<I> generator : stringGenerator) { generatedValues.add(generator.next()); } return aggregationFunction.apply(generatedValues); } }
CompositeGenerator implements Generator<T> { @Override public T next() { List<I> generatedValues = newArrayList(); for (Generator<I> generator : stringGenerator) { generatedValues.add(generator.next()); } return aggregationFunction.apply(generatedValues); } CompositeGenerator(Function<List<I>, T> aggregationFunction, List<Generator<I>> generators); }
CompositeGenerator implements Generator<T> { @Override public T next() { List<I> generatedValues = newArrayList(); for (Generator<I> generator : stringGenerator) { generatedValues.add(generator.next()); } return aggregationFunction.apply(generatedValues); } CompositeGenerator(Function<List<I>, T> aggregationFunction, List<Generator<I>> generators); @Override T next(); }
CompositeGenerator implements Generator<T> { @Override public T next() { List<I> generatedValues = newArrayList(); for (Generator<I> generator : stringGenerator) { generatedValues.add(generator.next()); } return aggregationFunction.apply(generatedValues); } CompositeGenerator(Function<List<I>, T> aggregationFunction, List<Generator<I>> generators); @Override T next();  }