Skip to content

Convenience System property setting on SystemPropertiesRestoreRule? #293

@dsmiley

Description

@dsmiley

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions