2323import  java .time .LocalDate ;
2424import  java .util .ArrayList ;
2525import  java .util .List ;
26+ import  java .util .function .Supplier ;
2627import  java .util .stream .Stream ;
2728
2829import  org .junit .jupiter .api .DisplayName ;
30+ import  org .junit .jupiter .api .Named ;
2931import  org .junit .jupiter .api .Test ;
3032import  org .junit .jupiter .api .extension .ExtensionContext ;
3133import  org .junit .jupiter .api .extension .ParameterContext ;
34+ import  org .junit .jupiter .params .ParameterizedTest ;
3235import  org .junit .jupiter .params .converter .AnnotationBasedArgumentConverter ;
3336import  org .junit .jupiter .params .converter .JavaTimeConversionPattern ;
3437import  org .junit .jupiter .params .provider .AnnotationBasedArgumentsProvider ;
3538import  org .junit .jupiter .params .provider .Arguments ;
3639import  org .junit .jupiter .params .provider .CsvSource ;
40+ import  org .junit .jupiter .params .provider .FieldSource ;
3741import  org .junit .platform .commons .JUnitException ;
3842
3943@ DisplayName ("AnnotationConsumerInitializer" )
@@ -51,10 +55,11 @@ void shouldInitializeAnnotationConsumer() throws NoSuchMethodException {
5155					source  -> assertThat (source .value ()).containsExactly ("a" , "b" ));
5256	}
5357
54- 	@ Test 
58+ 	@ ParameterizedTest 
59+ 	@ FieldSource ("argumentsProviders" )
5560	@ DisplayName ("should initialize annotation-based ArgumentsProvider" )
56- 	void  shouldInitializeAnnotationBasedArgumentsProvider ()  throws   NoSuchMethodException  { 
57- 		var   instance  =  new   SomeAnnotationBasedArgumentsProvider (); 
61+ 	void  shouldInitializeAnnotationBasedArgumentsProvider (AbstractAnnotationBasedArgumentsProvider   instance ) 
62+ 			 throws   NoSuchMethodException  { 
5863		var  method  = SubjectClass .class .getDeclaredMethod ("foo" );
5964		var  initialisedAnnotationConsumer  = initialize (method , instance );
6065
@@ -101,20 +106,32 @@ void shouldThrowExceptionWhenParameterIsNotAnnotated() throws NoSuchMethodExcept
101106		assertThatThrownBy (() -> initialize (parameter , instance )).isInstanceOf (JUnitException .class );
102107	}
103108
104- 	@ Test 
105- 	void  shouldInitializeForEachAnnotations () throws  NoSuchMethodException  {
106- 		var  instance  = spy (new  SomeAnnotationBasedArgumentsProvider ());
109+ 	@ ParameterizedTest 
110+ 	@ FieldSource ("argumentsProviders" )
111+ 	void  shouldInitializeForEachAnnotations (AbstractAnnotationBasedArgumentsProvider  provider )
112+ 			throws  NoSuchMethodException  {
113+ 		var  instance  = spy (provider );
107114		var  method  = SubjectClass .class .getDeclaredMethod ("repeatableAnnotation" , String .class );
108115
109116		initialize (method , instance );
110117
111118		verify (instance , times (2 )).accept (any (CsvSource .class ));
112119	}
113120
114- 	private  static  class  SomeAnnotationBasedArgumentsProvider  extends  AnnotationBasedArgumentsProvider <CsvSource > {
121+ 	static  Supplier <List <Named <? extends  AbstractAnnotationBasedArgumentsProvider >>> argumentsProviders  = () -> List .of ( // 
122+ 		Named .of ("current" , new  SomeAnnotationBasedArgumentsProvider ()), // 
123+ 		Named .of ("deprecated" , new  DeprecatedAnnotationBasedArgumentsProvider ()) // 
124+ 	);
125+ 
126+ 	private  static  abstract  class  AbstractAnnotationBasedArgumentsProvider 
127+ 			extends  AnnotationBasedArgumentsProvider <CsvSource > {
115128
116129		List <CsvSource > annotations  = new  ArrayList <>();
117130
131+ 	}
132+ 
133+ 	private  static  class  SomeAnnotationBasedArgumentsProvider  extends  AbstractAnnotationBasedArgumentsProvider  {
134+ 
118135		@ Override 
119136		protected  Stream <? extends  Arguments > provideArguments (ParameterDeclarations  parameters ,
120137				ExtensionContext  context , CsvSource  annotation ) {
@@ -123,6 +140,16 @@ protected Stream<? extends Arguments> provideArguments(ParameterDeclarations par
123140		}
124141	}
125142
143+ 	private  static  class  DeprecatedAnnotationBasedArgumentsProvider  extends  AbstractAnnotationBasedArgumentsProvider  {
144+ 
145+ 		@ Override 
146+ 		@ SuppressWarnings ("deprecation" )
147+ 		protected  Stream <? extends  Arguments > provideArguments (ExtensionContext  context , CsvSource  annotation ) {
148+ 			annotations .add (annotation );
149+ 			return  Stream .empty ();
150+ 		}
151+ 	}
152+ 
126153	private  static  class  SomeAnnotationBasedArgumentConverter 
127154			extends  AnnotationBasedArgumentConverter <JavaTimeConversionPattern > {
128155
0 commit comments