### Question:
Aggregator { public void addItem(T item) { if (myBatchSize > 1) { myItems.add(item); if (myItems.size() >= myBatchSize) { processAll(); } } else { myProcessor.accept(Collections.singletonList(item)); } } Aggregator(int batchSize, Consumer<List<T>> processor); static void process(Collection<? extends T> items, int batchSize, Consumer<List<T>> processor); void addItem(T item); void addItems(Collection<? extends T> items); void processAll();  }### Answer:
@Test public void testAggregation() { StringJoiner joiner = new StringJoiner("-"); Aggregator<String> aggregator = new Aggregator<>(3, items -> items.forEach(joiner::add)); aggregator.addItem("hey"); Assert.assertEquals("", joiner.toString()); aggregator.addItem("there"); Assert.assertEquals("", joiner.toString()); aggregator.addItem("dude"); Assert.assertEquals("hey-there-dude", joiner.toString()); }
@Test public void testNoAggregation() { StringJoiner joiner = new StringJoiner("-"); Aggregator<String> aggregator = new Aggregator<>(1, items -> items.forEach(joiner::add)); aggregator.addItem("hey"); Assert.assertEquals("hey", joiner.toString()); aggregator.addItem("there"); Assert.assertEquals("hey-there", joiner.toString()); }