3

I created the following annotation to only activate test methods, if the given file (of fileName attribute) exists in the data.scans.path directory (configured in Spring's application.yml):

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@EnabledIf(
    value = "#{new java.io.File(\"${data.scans.path}\", \"R000008-ueberraschungsei4\").isDirectory()}",
    loadContext = true
)
public @interface EnabledWhenScanDirExists {
    String fileName() default "R000008-ueberraschungsei4";
}

This works for the hard-coded file with name R000008-ueberraschungsei4, but, the fileName attribute is not used. I wanna change that. I tried to figure out how to use it in the @EnabledIf meta annotation. I found the possibility to use the attribute as a full parameter in a meta annotation via @AliasFor in Spring (f.e. here).
But from what I understood, I would think I can't use the @AliasFor annotation only for a small part of the @EnabledIf.value() attribute.
Is that correct? Is there any other way to do it?
Initially I tried things like this, but none of them worked:

value = "#{new java.io.File(\"${data.scans.path}\", fileName()).isDirectory()}",

0 Answers0