Mocking/stubbing sys environment variables in Java unit testing

Scavenging the codebases for ways to do it, two main libraries exploiting reflection were found for this:

JUnit Pioneer

https://junit-pioneer.org/docs/environment-variables

org.junit-pioneer junit-pioneer

import org.junitpioneer.jupiter.SetEnvironmentVariable

These are per-test-method annotations for JUnit5.

System Stubs by Webcompere

https://github.com/webcompere/system-stubs

uk.org.webcompere system-stubs-core | system-stubs-junit4 | system-stubs-jupiter

https://github.com/webcompere/system-stubs/blob/main/system-stubs-junit4/README.md

https://github.com/webcompere/system-stubs/blob/main/system-stubs-jupiter/README.md

(old) System Rules for Java 6/7 and JUnit 4.9+

System Stubs JUnit4 Test Rules Plugin was made equivalent to previously existing System Rules project.

https://stefanbirkner.github.io/system-rules/index.html