Package com.android.testutils
Class SystemPropertyOverrides
- java.lang.Object
-
- com.android.testutils.SystemPropertyOverrides
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class SystemPropertyOverrides extends java.lang.Object implements java.lang.AutoCloseableUtility to make it easier for tests to override system properties (instead of directly usingSystem.setProperty(String, String)). By using this class within try-with-resources, the test can be assured that any property set will be restored to its initial state after the test completes (success & failure).
-
-
Constructor Summary
Constructors Constructor Description SystemPropertyOverrides()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidsetProperty(java.lang.String key, java.lang.String value)Sets a system property (by callingSystem.setProperty(String, String)) while backing up the original value and replacing it once this class is closed.
-
-
-
Method Detail
-
setProperty
public void setProperty(@NonNull java.lang.String key, java.lang.String value)Sets a system property (by callingSystem.setProperty(String, String)) while backing up the original value and replacing it once this class is closed.
-
close
public void close() throws java.lang.Exception- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.lang.Exception
-
-