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