You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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!
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 callSystem.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.The text was updated successfully, but these errors were encountered: