Skip to content

Commit

Permalink
Simplify collector definition
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Sep 18, 2020
1 parent d54e663 commit f7159ed
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@

import org.testng.annotations.DataProvider;

import java.util.ArrayList;
import java.util.stream.Collector;

import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;

public final class DataProviders
{
private DataProviders() {}

public static <T> Collector<T, ?, Object[][]> toDataProvider()
{
return Collector.of(
ArrayList::new,
(builder, entry) -> builder.add(new Object[] {entry}),
(left, right) -> {
left.addAll(right);
return left;
},
builder -> builder.toArray(new Object[][] {}));
return collectingAndThen(
mapping(
value -> new Object[] {value},
toList()),
list -> list.toArray(new Object[][] {}));
}

@DataProvider
Expand Down

0 comments on commit f7159ed

Please sign in to comment.