11package net .jqwik .engine .execution .lifecycle ;
22
33import java .lang .annotation .*;
4+ import java .util .*;
45
6+ import org .junit .platform .engine .*;
57import org .mockito .*;
68
79import net .jqwik .api .*;
1315import static org .assertj .core .api .Assertions .*;
1416
1517@ MyAnnotation
18+ @ MyRepeatableAnnotation ("one" )
19+ @ MyRepeatableAnnotation ("two" )
1620class LifecycleContextAnnotationsTests {
1721
1822 private final Reporter reporter = Mockito .mock (Reporter .class );
1923 private final ResolveParameterHook resolveParameter = Mockito .mock (ResolveParameterHook .class );
2024
25+ @ Example
26+ void engineLifecycleContext () {
27+
28+ TestDescriptor engineDescriptor = TestDescriptorBuilder .forEngine (new JqwikTestEngine ()).build ();
29+ EngineLifecycleContext lifecycleContext = new EngineLifecycleContext (
30+ engineDescriptor ,
31+ reporter ,
32+ resolveParameter
33+ );
34+ assertThat (lifecycleContext .findAnnotation (MyAnnotation .class )).isEmpty ();
35+ assertThat (lifecycleContext .findAnnotationsInContainer (MyAnnotation .class )).isEmpty ();
36+ assertThat (lifecycleContext .findRepeatableAnnotations (MyRepeatableAnnotation .class )).isEmpty ();
37+ }
38+
2139 @ Example
2240 void containerLifecycleDescriptor () {
2341
@@ -31,7 +49,11 @@ void containerLifecycleDescriptor() {
3149
3250 assertThat (lifecycleContext .findAnnotation (MyAnnotation .class )).isPresent ();
3351 assertThat (lifecycleContext .findAnnotationsInContainer (MyAnnotation .class )).isEmpty ();
34- assertThat (lifecycleContext .findAnnotation (Property .class )).isNotPresent ();
52+
53+ List <MyRepeatableAnnotation > repeatableAnnotations = lifecycleContext .findRepeatableAnnotations (MyRepeatableAnnotation .class );
54+ assertThat (repeatableAnnotations ).isNotEmpty ();
55+ assertThat (repeatableAnnotations .stream ().map (MyRepeatableAnnotation ::value ))
56+ .contains ("one" , "two" );
3557 }
3658
3759 @ Example
@@ -52,6 +74,8 @@ void nestedContainerLifecycleDescriptor() {
5274 .hasSize (1 );
5375 }
5476
77+ @ MyRepeatableAnnotation ("three" )
78+ @ MyRepeatableAnnotation ("four" )
5579 @ Example
5680 void propertyLifecycleDescriptor () {
5781
@@ -69,6 +93,39 @@ void propertyLifecycleDescriptor() {
6993 assertThat (lifecycleContext .findAnnotationsInContainer (MyAnnotation .class ))
7094 .hasSize (1 );
7195
96+ List <MyRepeatableAnnotation > repeatableAnnotations = lifecycleContext .findRepeatableAnnotations (MyRepeatableAnnotation .class );
97+ assertThat (repeatableAnnotations ).isNotEmpty ();
98+ assertThat (repeatableAnnotations .stream ().map (MyRepeatableAnnotation ::value ))
99+ .contains ("three" , "four" );
100+
101+ }
102+
103+ @ MyRepeatableAnnotation ("five" )
104+ @ MyRepeatableAnnotation ("six" )
105+ @ Example
106+ void tryLifecycleDescriptor () {
107+
108+ PropertyMethodDescriptor methodDescriptor = (PropertyMethodDescriptor ) TestDescriptorBuilder .forMethod (
109+ LifecycleContextAnnotationsTests .class , "tryLifecycleDescriptor"
110+ ).build ();
111+ DefaultPropertyLifecycleContext propertyLifecycleContext = new DefaultPropertyLifecycleContext (
112+ methodDescriptor ,
113+ new LifecycleContextAnnotationsTests (),
114+ reporter ,
115+ resolveParameter
116+ );
117+
118+ TryLifecycleContext lifecycleContext = new DefaultTryLifecycleContext (propertyLifecycleContext );
119+
120+ assertThat (lifecycleContext .findAnnotation (Example .class )).isPresent ();
121+ assertThat (lifecycleContext .findAnnotationsInContainer (MyAnnotation .class ))
122+ .hasSize (1 );
123+
124+ List <MyRepeatableAnnotation > repeatableAnnotations = lifecycleContext .findRepeatableAnnotations (MyRepeatableAnnotation .class );
125+ assertThat (repeatableAnnotations ).isNotEmpty ();
126+ assertThat (repeatableAnnotations .stream ().map (MyRepeatableAnnotation ::value ))
127+ .contains ("five" , "six" );
128+
72129 }
73130
74131 @ Group
@@ -83,3 +140,16 @@ void aProperty(@ForAll String aString) {}
83140@ Retention (RetentionPolicy .RUNTIME )
84141@interface MyAnnotation {
85142}
143+
144+ @ Target ({ElementType .ANNOTATION_TYPE , ElementType .METHOD , ElementType .TYPE })
145+ @ Retention (RetentionPolicy .RUNTIME )
146+ @ Repeatable (MyRepeatableAnnotations .class )
147+ @interface MyRepeatableAnnotation {
148+ String value ();
149+ }
150+
151+ @ Target ({ElementType .ANNOTATION_TYPE , ElementType .METHOD , ElementType .TYPE })
152+ @ Retention (RetentionPolicy .RUNTIME )
153+ @interface MyRepeatableAnnotations {
154+ MyRepeatableAnnotation [] value ();
155+ }
0 commit comments