-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using a single aggregator on the method level #2778
Comments
@akruijff Thanks for raising the issue! Instead, I think we could add a If we decide for the former, @ParameterizedTest
@CsvSource({
"1, 2, 3, 4, 5"
})
public void test1(@AggregateWith(XA.class) X x, @AggregateWith(value = YA.class, startIndex = 2) Y y) {}
public class XA implements ArgumentsAggregator {
public Object aggregateArguments(ArgumentsAccessor accessor, ParameterContext context)
throws ArgumentsAggregationException {
int index = context.getIndex();
return new Y(accessor.getInt(0), accessor.getInt(1));
}
}
public class YA implements ArgumentsAggregator {
public Object aggregateArguments(ArgumentsAccessor accessor, ParameterContext context)
throws ArgumentsAggregationException {
int index = context.getIndex();
return new Y(accessor.getInt(0), accessor.getInt(1), accessor.getInt(2));
}
} Would that work in your use case? |
@marcphilipp That solution seems very error prone, because it requires that, when the parameters change, that change is administered two places. This would deter me from using it. Why do you think that my solution would be confusing? The rule is: the more specific My solution does require the
I read this as |
Thanks for sharing your perspective! We'll discuss this in the team. |
Team decision: We think this is a corner case and adding support for method-level aggregators would add considerable complexity to the codebase. We're open to reconsider this decision in case there's more interest from the community. |
The problem
When not all parameters consume the same number of arguments, then it is hard to consume the right arguments.
I have discusses the problem here: #2777
I currently do this with a static variable and a call from
@BeforeEach
setup method to reset method, but I do not like this solution.Example
Solution
I would like the option to use
@AggregateWith
on the method level. The aggregator that is referred to should be instanced once per method call and called for every parameter. This way, the consumed arguments can be tracked.Example
Future improvement
It might also be nice to use a default aggregator and register convertor classes with it. I think this will lead to more reuse being possible
Example
The text was updated successfully, but these errors were encountered: