Allow directly present @BootstrapWith to override meta annotations
Prior to this commit, if a test class was meta-annotated with multiple @BootstrapWith declarations that registered different TestContextBootstrapper implementations, such a configuration would result in an IllegalStateException, and there was no way to override this behavior. This commit addresses this shortcoming by relaxing the explicit TestContextBootstrapper resolution in BootstrapUtils so that a directly present @BootstrapWith annotation will now override declarations of @BootstrapWith that are meta-present. In other words, if @BootstrapWith is used as a meta-annotation, it can be overridden directly on the test class via an explicit, local declaration of @BootstrapWith. Issue: SPR-17006
This commit is contained in:
@@ -99,6 +99,14 @@ public class BootstrapUtilsTests {
|
||||
assertBootstrapper(DuplicateMetaAnnotatedBootstrapWithAnnotationClass.class, FooBootstrapper.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Test
|
||||
public void resolveTestContextBootstrapperWithLocalDeclarationThatOverridesMetaBootstrapWithAnnotations() {
|
||||
assertBootstrapper(LocalDeclarationAndMetaAnnotatedBootstrapWithAnnotationClass.class, EnigmaBootstrapper.class);
|
||||
}
|
||||
|
||||
private void assertBootstrapper(Class<?> testClass, Class<?> expectedBootstrapper) {
|
||||
BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext(testClass, delegate);
|
||||
TestContextBootstrapper bootstrapper = resolveTestContextBootstrapper(bootstrapContext);
|
||||
@@ -112,6 +120,8 @@ public class BootstrapUtilsTests {
|
||||
|
||||
static class BarBootstrapper extends DefaultTestContextBootstrapper {}
|
||||
|
||||
static class EnigmaBootstrapper extends DefaultTestContextBootstrapper {}
|
||||
|
||||
@BootstrapWith(FooBootstrapper.class)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface BootWithFoo {}
|
||||
@@ -146,7 +156,12 @@ public class BootstrapUtilsTests {
|
||||
@BootWithFoo
|
||||
@BootWithFooAgain
|
||||
static class DuplicateMetaAnnotatedBootstrapWithAnnotationClass {}
|
||||
|
||||
|
||||
@BootWithFoo
|
||||
@BootWithBar
|
||||
@BootstrapWith(EnigmaBootstrapper.class)
|
||||
static class LocalDeclarationAndMetaAnnotatedBootstrapWithAnnotationClass {}
|
||||
|
||||
@WebAppConfiguration
|
||||
static class WebAppConfigurationAnnotatedClass {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user