I have encountered a problem with the RestoreSystemPropertiesRule. It modifies the original system properties and causes some of my unit tests to fail. I have done a little debugging and the problem is that the before() method in RestoreSystemProperties.java actually changes the existing properties. It appears that it is trying to create a copy, but it actually does not. If you look at the javadoc for Properties, the single argument constructor does not copy the Properties passed in. Rather it uses those as defaults when properties have not been set. This has different behavior than having the properties set. One example of this is when calling contains() the Property object will return false if the property has not been set - even if there is a default for that key.
I have encountered a problem with the
RestoreSystemProperties
Rule
. It modifies the original system properties and causes some of my unit tests to fail. I have done a little debugging and the problem is that thebefore()
method inRestoreSystemProperties.java
actually changes the existing properties. It appears that it is trying to create a copy, but it actually does not. If you look at the javadoc for Properties, the single argument constructor does not copy the Properties passed in. Rather it uses those as defaults when properties have not been set. This has different behavior than having the properties set. One example of this is when callingcontains()
the Property object will returnfalse
if the property has not been set - even if there is a default for that key.I would recommend a simple fix: