Skip to content

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

Closed
@ppkarwasz

Description

@ppkarwasz

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:

https://github.com/junit-team/junit5/blob/8e9094d60fa7964e635c6f4e91b7241266b3f09e/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ExtensionUtils.java#L204-L209

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

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions