https://kotlinlang.org logo
Title
j

Jukka Siivonen

04/10/2019, 8:27 AM
Is it possible to define annotation that is composed or inherited from other annotations?
For example I know I can have
@WithUserDetails(value = DEFAULT_TEST_USERNAME)
annotation class SpringContextTest
but I cannot use @SpringContextTest like this:
d

diesieben07

04/10/2019, 8:27 AM
Those so-called meta annotations have to be explicitly supported by whatever framework / library is consuming those annotations
j

Jukka Siivonen

04/10/2019, 8:27 AM
@SpringContextTest(username = "foo")
d

diesieben07

04/10/2019, 8:28 AM
In the case of spring you can use
@AliasFor(annotation = SpringContextTest)
on your
username
property
Probably need
@AliasFor(annotation = SpringContextTest::class, attribute = "value")
acutally. Not quite sure how
@SpringContextTest
looks
j

Jukka Siivonen

04/10/2019, 8:31 AM
to be precise my custom @SpringContextTest just wraps two Spring annotations
@SpringBootTest
@WithUserDetails(value = DEFAULT_TEST_USERNAME)
annotation class SpringContextTest
and I would like to have possibility to use my annotation in tests as @SpringContextTest(username = "foo") or just @SpringContextTest (default user)
I will look in to AliasFor, I did not know about that. Thanks