Class RestoreSystemProperties
java.lang.Object
org.junit.rules.ExternalResource
org.junit.contrib.java.lang.system.RestoreSystemProperties
- All Implemented Interfaces:
org.junit.rules.TestRule
public class RestoreSystemProperties
extends org.junit.rules.ExternalResource
The
RestoreSystemProperties rule undoes changes of system
properties when the test finishes (whether it passes or fails).
Let's assume the system property YourProperty has the
value YourValue. Now run the test
public void YourTest {
@Rule
public final TestRule restoreSystemProperties = new RestoreSystemProperties();
@Test
public void overrideProperty() {
System.setProperty("YourProperty", "other value");
assertEquals("other value", System.getProperty("YourProperty"));
}
}
After running the test, the system property YourProperty has
the value YourValue again.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates aRestoreSystemPropertiesrule that restores all system properties.RestoreSystemProperties(String... properties) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.Simply remove all calls to this method.protected voidafter()protected voidbefore()private PropertiescopyOf(Properties source) Methods inherited from class org.junit.rules.ExternalResource
apply
-
Field Details
-
originalProperties
-
-
Constructor Details
-
RestoreSystemProperties
Deprecated.Please useRestoreSystemProperties(). The rule restores all properties. That's why you don't have to specify the properties anymore.Creates aRestoreSystemPropertiesrule that restores all system properties. -
RestoreSystemProperties
public RestoreSystemProperties()Creates aRestoreSystemPropertiesrule that restores all system properties.- Since:
- 1.8.0
-
-
Method Details
-
add
Deprecated.Simply remove all calls to this method.RestoreSystemPropertiesrestores all properties automatically. That's why you don't have to add the properties anymore.Does nothing.- Since:
- 1.6.0
-
before
- Overrides:
beforein classorg.junit.rules.ExternalResource- Throws:
Throwable
-
copyOf
-
after
protected void after()- Overrides:
afterin classorg.junit.rules.ExternalResource
-
RestoreSystemProperties().