Skip to content

Repeated @ExtendWith meta-annotations on fields no longer supported in 5.11.x #4054

Closed

Description

Since version 5.11.x, if a field is meta-annotated with multiple @ExtendWith annotations, JUnit fails to detect them.

The problem seems to be in ExtensionUtils#streamExtensionFilteringFields, which does not take into account repeatable annotations:

private static Stream<Field> streamExtensionRegisteringFields(Class<?> clazz, Predicate<Field> predicate) {
Predicate<Field> composedPredicate = predicate.and(
field -> isAnnotated(field, ExtendWith.class) || isAnnotated(field, RegisterExtension.class));
return streamFields(clazz, composedPredicate, TOP_DOWN)//
.sorted(orderComparator);
}

Steps to reproduce

  1. Meta-annotate some test class fields with multiple @ExtendWith annotations:

    @Retention(RetentionPolicy.RUNTIME)
    @ExtendWith(Extension1.class)
    @ExtendWith(Extension2.class)
    public @interface ComposedAnnotation {}
    public class TestClassWithFields {
    
      @ComposedAnnotation
      private static int staticFieldMetaAnnotatedTwice;
    
      @ComposedAnnotation
      private int instanceFieldMetaAnnotatedTwice;
    }
  2. Run the following test cases:

    class ExtensionsUtilsTests {
      @Test
      void discoverExtensionsOnStaticFields() {
        ExtensionRegistrar registrar = mock();
        ExtensionUtils.registerExtensionsFromStaticFields(registrar, ClassWithFields.class);
        verify(registrar).registerExtension(Extension1.class);
        verify(registrar).registerExtension(Extension2.class);
      }
      @Test
      void discoverExtensionsOnInstanceFields() {
        ExtensionRegistrar registrar = mock();
        ExtensionUtils.registerExtensionsFromInstanceFields(registrar, ClassWithFields.class);
        verify(registrar).registerExtension(Extension1.class);
        verify(registrar).registerExtension(Extension2.class);
      }
    }

Context

  • Used versions (Jupiter/Vintage/Platform): Jupiter 5.11.1 / Platform 1.11.1
  • Build Tool/IDE: Maven
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions