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

Convenience System property setting on SystemPropertiesRestoreRule? #293

Open
dsmiley opened this issue Nov 13, 2020 · 1 comment
Open

Comments

@dsmiley
Copy link
Contributor

dsmiley commented Nov 13, 2020

SystemPropertiesRestoreRule is pretty nice. It'd be even nicer if I could conveniently set particular system properties at the site of the rule definition, to make it clear why the rule is there in the first place. This would work by adding a convenient (String key, String value) constructor, and another (Map<String, String> properties) when there is more than one. My proposal here is inspired by https://gist.github.com/mike10004/7f6865b46c23005e9496a53589194788 which I found with some googling.

Of course this isn't necessary. I can define this rule, and then somewhere in some @Before or wherever, I can call System.setProperty(name, value. But my proposal keeps these linked together. One might want to define System.setProperty as a "forbidden API", in tests, and instead rely purely on your JUnit Rule to manipulate them, which communicates to readers that it's important to clean up after test execution.

@dweiss
Copy link
Contributor

dweiss commented Nov 13, 2020

Wouldn't a rule-chain with a separate rule (the "setter" rule) underneath serve the same purpose? I understand the notation brevity convenience though - if you care to make a patch, go ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants