Is it possible to have multiple Aggregators in JUnit5 to start from different Indexes?

Viewed 85

Is it possible to use Aggregators to aggregate multiple objects, each starting with the first index not used by previous Aggregations?

In the example that would be true, true for the first parameter and true, false for the second, but they both use true, true.

I tried using context.getIndex() but that only works when I know the length of previous Aggregators.

public class Test {
    @ParameterizedTest
    @CsvSource({ "true, true, true, false" })
    void test(@AggregateWith(And.class) boolean first,
            @AggregateWith(And.class) boolean second) {
        assertThat(first).isTrue();
        assertThat(second).isFalse();
    }

}

class And implements ArgumentsAggregator {

    @Override
    public Object aggregateArguments(ArgumentsAccessor arguments,
            ParameterContext context) throws ArgumentsAggregationException {

        return arguments.getBoolean(0) && arguments.getBoolean(1);
    }

}
0 Answers
Related