diff options
author | Neil Fuller <nfuller@google.com> | 2014-05-21 15:37:24 +0100 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2014-05-21 18:00:05 +0100 |
commit | 408276e5d0d1a05790f8bf728d1bd7e156685856 (patch) | |
tree | 2bb671b658bacdcfa99cebf51386957b07aeb238 | |
parent | 324665480d3bf34b724d9a25a589a89379394139 (diff) | |
download | libcore-408276e5d0d1a05790f8bf728d1bd7e156685856.zip libcore-408276e5d0d1a05790f8bf728d1bd7e156685856.tar.gz libcore-408276e5d0d1a05790f8bf728d1bd7e156685856.tar.bz2 |
Adding more tests around System properties
This is in preparation for clearing all system properties
between CTS tests to reduce test leakage. The code in the test
runner that explicitly sets certain values can also be removed
now that those properties have been made immutable.
Note: As part of this I discovered that java.io.tmpdir
is still mutable under the Zygote and immutable under
vogar (where it is set as a command-line arg). This means
that calling System.getProperties().clear() or
System.setProperties(null) removes the property entirely
under an Android app but not under vogar.
Change-Id: If0361b138666909b21de9d6b8a73a584e9390550
-rw-r--r-- | luni/src/test/java/libcore/java/lang/SystemTest.java | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/luni/src/test/java/libcore/java/lang/SystemTest.java b/luni/src/test/java/libcore/java/lang/SystemTest.java index 4efecd7..1a672b0 100644 --- a/luni/src/test/java/libcore/java/lang/SystemTest.java +++ b/luni/src/test/java/libcore/java/lang/SystemTest.java @@ -149,8 +149,12 @@ public class SystemTest extends TestCase { done.set(true); } - public void testSystemProperties_immtuable() { + public void testSystemProperties_immutable() { + // Android-specific: The RI does not have a concept of immutable properties. + + // user.dir is an immutable property String userDir = System.getProperty("user.dir"); + assertNotNull(userDir); System.setProperty("user.dir", "not poop"); assertEquals(userDir, System.getProperty("user.dir")); @@ -166,4 +170,56 @@ public class SystemTest extends TestCase { assertEquals(userDir, System.getProperty("user.dir")); } + + public void testSystemProperties_setProperties_null() { + // user.dir is an immutable property + String userDir = System.getProperty("user.dir"); + assertNotNull(userDir); + + // Add a non-standard property + System.setProperty("p1", "v1"); + + // Reset using setProperties(null) + System.setProperties(null); + + // All the immutable properties should be reset. + assertEquals(userDir, System.getProperty("user.dir")); + // Non-standard properties are cleared. + assertNull(System.getProperty("p1")); + } + + public void testSystemProperties_setProperties_nonNull() { + String userDir = System.getProperty("user.dir"); + + Properties newProperties = new Properties(); + // Immutable property + newProperties.setProperty("user.dir", "v1"); + // Non-standard property + newProperties.setProperty("p1", "v2"); + + System.setProperties(newProperties); + + // Android-specific: The RI makes the setProperties() argument the system properties object, + // Android makes a new Properties object and copies the properties. + assertNotSame(newProperties, System.getProperties()); + // Android-specific: The RI does not have a concept of immutable properties. + assertEquals(userDir, System.getProperty("user.dir")); + + assertEquals("v2", System.getProperty("p1")); + } + + public void testSystemProperties_getProperties_clear() { + String userDir = System.getProperty("user.dir"); + assertNotNull(userDir); + System.setProperty("p1", "v1"); + + Properties properties = System.getProperties(); + assertEquals("v1", properties.getProperty("p1")); + + properties.clear(); + + // Android-specific: The RI clears everything, Android resets to immutable defaults. + assertEquals(userDir, System.getProperty("user.dir")); + assertNull(System.getProperty("p1")); + } } |