junit5
junit5 copied to clipboard
Add new AnnotationBasedArgumentsProvider
Sometimes an arguments provider needs to be initialised with an annotation externally before you can call provideArguments
. It has to implement something like Consumer<A>
or AnnotationConsumer<A>
. It'd be nice to have an extension point that merged ArgumentsProvider
with AnnotationConsumer<A>
(something like AnnotationBasedArgumentsProvider<A>
so I could call provideArguments(ExtensionContext extensionContext, A annotation)
instead of accept(A annotation)
and then provideArguments(ExtensionContext extensionContext)
.
An example extension that consumes an annotation is CsvArgumentsProvider. It seems AnnotationConsumer<A>
is only used by ArgumentsProvider
implementations (?).
Maybe this is too simple and doesn't add much value, other than a bit of convenience.
EDIT: Another option is to not constrict the ArgumentsProvider
in such a way (i.e.: AnnotationConsumer
can only consume annotations) and have a more generic type parameter. This way the ArgumentsProvider
can be initialised with anything - I recently used this approach with Parameter
.
Deliverables
- [ ] A new (very simple) extension point merging
AnnotationConsumer<A>
andArgumentsProvider
- [ ] Alternatively: A new extension point merging
Consumer<T>
andArgumentsProvider
.
Tentatively slated for 5.8-M2 solely for the purpose of team discussion
Sorry, I'm not really familiar with the process - I edited the original post to add another alternative I think you could consider. Hope that's OK.
I edited the original post to add another alternative I think you could consider. Hope that's OK.
Yes, that's totally fine.
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.
Team Decision: We think it should roughly look like the following:
public abstract class AnnotationBasedArgumentsProvider<A> implements ArgumentsProvider, AnnotationConsumer<A> {
private A annotation;
@Override
public final void accept(A annotation) {
this.annotation = annotation;
}
@Override
public final Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return provideArguments(context, annotation);
}
protected abstract Stream<? extends Arguments> provideArguments(ExtensionContext context, A annotation);
}
@Michael1993 Are you still interested in this? If so, could you please submit a PR and change the internal implementations to use it?
I could work on this if the OP is not interested in creating the PR.
Go for it - I'm interested but don't really have free capacity at the moment.
Hey guys can you give it a look to the open PR for solving this issue? It is being open for some time and it is not that big ;)
Team Decision: We'll also create an AnnotationBasedArgumentConverter
for symmetry.