summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-05-23 08:51:03 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-05-23 08:51:03 +0000
commit5f846d730cbc19b1abc2fffc437ceee9241a1142 (patch)
tree7c56c9e549aacb8ebd547823b014132789df9f23 /luni
parent04769b3a84567a4bd83a4c1a43dfa41882666be2 (diff)
parent21d8bd1227a8b877adeca3062dc5a427753156e2 (diff)
downloadlibcore-5f846d730cbc19b1abc2fffc437ceee9241a1142.zip
libcore-5f846d730cbc19b1abc2fffc437ceee9241a1142.tar.gz
libcore-5f846d730cbc19b1abc2fffc437ceee9241a1142.tar.bz2
am 21d8bd12: Merge "Adding more tests around System properties"
* commit '21d8bd1227a8b877adeca3062dc5a427753156e2': Adding more tests around System properties
Diffstat (limited to 'luni')
-rw-r--r--luni/src/test/java/libcore/java/lang/SystemTest.java58
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"));
+ }
}