Dependencies between annotation driven extensions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dependencies between annotation driven extensions

Björn Kautler
I just learned about Spock and now I'm playing a bit with it.
What I currently try is to have two AnnotationDrivenExtensions that have an order constraint.
Is this possible somehow?

Here some more exemplary details:

If annotation A is applied to a specification or feature method, it adds an iteration interceptor that sets some String fields of the specification to some value.
If annotation B is applied, it does the same, but it needs to be given somehow the value that was set by annotation A.

The best I got so far is giving annotation B a value like

Class<Closure<? extends File>> value()

Then in the specification apply the annotation like

@B({ fieldSetByA })

and then in the interceptor use

bAnnotation.value().newInstance(it.instance, it.instance)()

to call that annotation and get the value.

But this only works if annotation B is applied after annotation A or rather if annotation B is evaluated by Spock after annotation A and thus the interceptor of A runs before the interceptor of B and the value thus is present and can be delivered by the closure given to the B annotation. If B is applied first, then the value will still be null.

Now is there a reliable way to somehow make this work correctly?
Or do I have to repeat the work that A did in B and then have one annotation that does A and one annotation AandB instead of applying A and B individually which I would greatly prefer.

Regards
Björn

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dependencies between annotation driven extensions

Björn Kautler
Noone? :-(

Am Mittwoch, 14. September 2016 22:29:12 UTC+2 schrieb Björn Kautler:
I just learned about Spock and now I'm playing a bit with it.
What I currently try is to have two AnnotationDrivenExtensions that have an order constraint.
Is this possible somehow?

Here some more exemplary details:

If annotation A is applied to a specification or feature method, it adds an iteration interceptor that sets some String fields of the specification to some value.
If annotation B is applied, it does the same, but it needs to be given somehow the value that was set by annotation A.

The best I got so far is giving annotation B a value like

Class<Closure<? extends File>> value()

Then in the specification apply the annotation like

@B({ fieldSetByA })

and then in the interceptor use

bAnnotation.value().newInstance(it.instance, it.instance)()

to call that annotation and get the value.

But this only works if annotation B is applied after annotation A or rather if annotation B is evaluated by Spock after annotation A and thus the interceptor of A runs before the interceptor of B and the value thus is present and can be delivered by the closure given to the B annotation. If B is applied first, then the value will still be null.

Now is there a reliable way to somehow make this work correctly?
Or do I have to repeat the work that A did in B and then have one annotation that does A and one annotation AandB instead of applying A and B individually which I would greatly prefer.

Regards
Björn

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Loading...