Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for DisplayNameGeneration annotations on runtime enclosing types #4268

Merged
merged 8 commits into from
Jan 27, 2025

Conversation

marcphilipp
Copy link
Member

Resolves #4131.


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

Copy link
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general the PR looks good, and the tests demonstrate the expected results. 👍

I've asked a few questions and requested a few minor changes.

Regarding the internal refactoring in DisplayNameUtils, I'll have to review that later in an IDE.

@@ -37,7 +39,11 @@ public enum SearchOption {
* Search the inheritance hierarchy as with the {@link #DEFAULT} search option
* but also search the {@linkplain Class#getEnclosingClass() enclosing class}
* hierarchy for <em>inner classes</em> (i.e., a non-static member classes).
*
* @deprecated because it's preferable to inspect the runtime enclosing
* types of a class rather than where they are declared.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I certainly agree with that sentiment, developers and libraries that use AnnotationSupport often will not have access to the runtime enclosing types. Typically only JUnit internals have access to those.

So, I am a bit reluctant to deprecate this feature.

However, if we deprecate it and nobody complains, then I suppose it's fine. 😇

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I certainly agree with that sentiment, developers and libraries that use AnnotationSupport often will not have access to the runtime enclosing types. Typically only JUnit internals have access to those.

Jupiter extension authors can access them via ExtensionContext.getRequiredTestClass(), recursively, or get them from ExtensionContext.getRequiredTestInstances() by calling Object.getClass() on each instance.

I checked the original issue and didn't find an actual user request. Therefore, since this was the only place we used it, I deprecated the method. We can always undeprecate it if anyone complains. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also considered the fact that Jupiter extension authors have a way to access that information, so I was thinking more about the general purpose nature of the utilities in AnnotationSupport for other testing frameworks, engines, etc.

I checked the original issue and didn't find an actual user request. Therefore, since this was the only place we used it, I deprecated the method. We can always undeprecate it if anyone complains. WDYT?

Yep, as I mentioned before.... if nobody complains, it's fine. 👍

@marcphilipp marcphilipp force-pushed the marc/4131-runtime-enclosing-types-annotation-lookup branch from dd5c4a0 to 3265d58 Compare January 26, 2025 16:53
Base automatically changed from marc/4130-display-name-generator-runtime-enclosing-types to main January 26, 2025 17:58
@marcphilipp marcphilipp force-pushed the marc/4131-runtime-enclosing-types-annotation-lookup branch from 56ce4ff to da61c32 Compare January 26, 2025 18:14
@marcphilipp marcphilipp marked this pull request as ready for review January 26, 2025 18:14
@marcphilipp marcphilipp requested a review from sbrannen January 27, 2025 07:02
@marcphilipp marcphilipp merged commit ed68831 into main Jan 27, 2025
15 checks passed
@marcphilipp marcphilipp deleted the marc/4131-runtime-enclosing-types-annotation-lookup branch January 27, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@DisplayNameGeneration is not discovered on runtime enclosing type for @Nested test class
2 participants