I am currently using an annotation provided by a 3rd party library and I'm wondering if there is a way to create another 'wrapper annotation' around it so that I don't have to require all parameters.
For example I can use the library annotation like this:
@LibraryAnnotation(Parameter1, Parameter2, Parameter3)
But in my case Parameter2 and Parameter3 are always the same so I want to create an annotation that will only take in Parameter1
@MyAnnotation(Parameter1)
But will call the other annotation with all Parameters, similar to how you might create a wrapper for a 3rd party method.
My original tests was like this:
@Test
@SqlGroup(
    {
        @Sql(
            executionPhase = BEFORE_TEST_METHOD,
            config = @SqlConfig(transactionMode = ISOLATED),
            scripts = {"classpath:test/sqls/_truncate_tables.sql"}
        ),
        @Sql(
            executionPhase = AFTER_TEST_METHOD,
            config = @SqlConfig(transactionMode = ISOLATED),
            scripts = {"classpath:test/sqls/_truncate_tables.sql"}
        )
    }
)
public void countTeams_countOnEmptyTable_returnsWithEmptyList() {}
And whit this base annotation I cleaned up the test files:
 @Target({ElementType.TYPE, ElementType.METHOD})
 @Retention(RetentionPolicy.RUNTIME)
 @Documented
 @Inherited
 @SqlGroup(
        {
            @Sql(
                executionPhase = BEFORE_TEST_METHOD,
                config = @SqlConfig(transactionMode = ISOLATED),
                scripts = {"classpath:test/sqls/_truncate_tables.sql"}
            ),
            @Sql(
                executionPhase = AFTER_TEST_METHOD,
                config = @SqlConfig(transactionMode = ISOLATED),
                scripts = {"classpath:test/sqls/_truncate_tables.sql"}
            )
        }
)
And finally I got this clean version:
@Test
@BaseSqlGroup
public void countTeams_countOnEmptyTable_returnsWithEmptyList(){}
                        Annotations are quite limited. Unfortunately, I don't see a way, but I might be wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With