junit5 icon indicating copy to clipboard operation
junit5 copied to clipboard

Add new AnnotationBasedArgumentsProvider

Open Michael1993 opened this issue 3 years ago • 8 comments

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> and ArgumentsProvider
  • [ ] Alternatively: A new extension point merging Consumer<T> and ArgumentsProvider.

Michael1993 avatar May 22 '21 10:05 Michael1993

Tentatively slated for 5.8-M2 solely for the purpose of team discussion

juliette-derancourt avatar May 22 '21 11:05 juliette-derancourt

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.

Michael1993 avatar May 23 '21 10:05 Michael1993

I edited the original post to add another alternative I think you could consider. Hope that's OK.

Yes, that's totally fine.

sbrannen avatar May 23 '21 15:05 sbrannen

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.

stale[bot] avatar Jul 05 '22 22:07 stale[bot]

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?

marcphilipp avatar Jul 08 '22 15:07 marcphilipp

I could work on this if the OP is not interested in creating the PR.

gilbertojrequena avatar Jul 09 '22 12:07 gilbertojrequena

Go for it - I'm interested but don't really have free capacity at the moment.

Michael1993 avatar Jul 09 '22 12:07 Michael1993

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 ;)

gilbertojrequena avatar Aug 02 '22 13:08 gilbertojrequena

Team Decision: We'll also create an AnnotationBasedArgumentConverter for symmetry.

marcphilipp avatar Mar 03 '23 11:03 marcphilipp