@Test public void shouldConcatenateGeneratedValues() { Generator<Object> stringGenerator = Generators.<Object>ofInstance("someString"); Generator<Object> integerGenerator = Generators.<Object>ofInstance(78); Function<List<Object>, String> aggregationFunction = new Function<List<Object>, String>() { @Nullable @Override public String apply(@Nullable List<Object> input) { return Joiner.on(",").join(input); } }; Generator<String> compositeGenerator = new CompositeGenerator<>(aggregationFunction, asList(stringGenerator, integerGenerator)); String generatedString = compositeGenerator.next(); assertThat(generatedString, is("someString,78")); }
@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();  }