Skip to content

Allow system properties abstraction#5719

Open
TomaszGaweda wants to merge 3 commits into
junit-team:mainfrom
TomaszGaweda:allow-SystemProperties-abstraction
Open

Allow system properties abstraction#5719
TomaszGaweda wants to merge 3 commits into
junit-team:mainfrom
TomaszGaweda:allow-SystemProperties-abstraction

Conversation

@TomaszGaweda
Copy link
Copy Markdown

This PR allows building abstractions very similar to SystemPropertiesExtension.

The use case in my case is related to Hazelcast (#hazelcast/hazelcast), where we have our class wrapper for ClusterProperties - ClusterProperty. Cluster properties can be set via system properties.

It's common to see then patterns like System.setProperty(SOME_PROPERTY.name(), "value") in the code. We are now slowly migrating to JUnit 5 and it would be awesome if we could use @SetSystemProperty - however, Java does not allow us to call .name() method in annotation.

With this PR merged we will be able to make similar annotations like:

@SetClusterProperty(LOGGING_TYPE, "log4j2")

Obviously it is possible to make such extensions right now, however it will duplicate existing extension - I'd even say, only changes will be other annotation names. I think there will be more places where libraries would like to have derivatives of the SetSystemProperty & Co. annotations.

Notes to reviewers:

  • AbstractSystemPropertiesExtension is mostly a copy of old SystemPropertiesExtension
  • new SystemPropertiesExtension implements AbstractSystemPropertiesExtension with current and standard set of annotations
  • There is a test added SystemPropertiesExtensionViaCustomAnnotationTests, which is also mostly copied from SystemPropertiesExtensionTests, testing new abstraction and showing the usage.
  • Please let me know if documentation added is enough. I didn't write too much as it's only a technical abstraction, that I think everybody will see quickly how it works, but I am not sure.

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


Definition of Done

Signed-off-by: Tomasz Gawęda <tomasz.gaweda@outlook.com>
Signed-off-by: Tomasz Gawęda <tomasz.gaweda@outlook.com>
Signed-off-by: Tomasz Gawęda <tomasz.gaweda@outlook.com>
@TomaszGaweda TomaszGaweda force-pushed the allow-SystemProperties-abstraction branch from 5e4c3be to aa655cc Compare June 2, 2026 09:16
@TomaszGaweda
Copy link
Copy Markdown
Author

Thanks @mpkorstanje for adding the labels and forwarding to the Team. Please let me know when you will need changes to the PR, questions answered or anything else. Have a great day!

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.

2 participants