Skip to content

@NestedTestConfiguration should not be discovered on enclosing class for nested interface #25917

@sbrannen

Description

@sbrannen

Status Quo

While switching the default @NestedTestConfiguration mode to INHERIT in fbb3c5c, I noticed that @NestedTestConfiguration was discovered on an enclosing class for a nested interface if a @Nested test class implemented the nested interface.

If the nested interface is local to a test class that is itself annotated with @NestedTestConfiguration, the search algorithm in MetaAnnotationUtils.lookUpEnclosingConfiguration() will find that annotation before declarations more local to the @Nested test class, and that annotation may be declared differently than a local declaration.

As a workaround, developers can redeclare @NestedTestConfiguration with the desired mode directly on a @Nested test class that implements such an interface, but that is cumbersome and error prone.

Analysis

This bug originates from use of SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES in the MergedAnnotations API. To fix this bug, a custom annotation search algorithm will have to be used, analogous to other search algorithms recently introduced in MetaAnnotationUtils.

Deliverables

  • Ensure that MetaAnnotationUtils.lookUpEnclosingConfiguration() does not search on enclosing classes for nested interfaces.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions