use of java.util.prefs.Preferences in project robovm by robovm.
the class OldPreferencesTest method testGet.
public void testGet() throws BackingStoreException {
Preferences root = Preferences.userNodeForPackage(Preferences.class);
Preferences pref = root.node("mock");
assertNull(pref.get("", null));
assertEquals("default", pref.get("key", "default"));
assertNull(pref.get("key", null));
pref.put("testGetkey", "value");
assertNull(pref.get("testGetKey", null));
assertEquals("value", pref.get("testGetkey", null));
try {
pref.get(null, "abc");
fail();
} catch (NullPointerException expected) {
}
pref.get("", "abc");
pref.get("key", null);
pref.get("key", "");
pref.putFloat("floatKey", 1.0f);
assertEquals("1.0", pref.get("floatKey", null));
pref.removeNode();
try {
pref.get("key", "abc");
fail();
} catch (IllegalStateException expected) {
}
try {
pref.get(null, "abc");
fail();
} catch (NullPointerException expected) {
}
}
use of java.util.prefs.Preferences in project robovm by robovm.
the class OldPreferencesTest method testAbstractMethods.
public void testAbstractMethods() throws IOException, BackingStoreException {
Preferences p = new MockPreferences();
p.absolutePath();
p.childrenNames();
p.clear();
p.exportNode(null);
p.exportSubtree(null);
p.flush();
p.get(null, null);
p.getBoolean(null, false);
p.getByteArray(null, null);
p.getFloat(null, 0.1f);
p.getDouble(null, 0.1);
p.getInt(null, 1);
p.getLong(null, 1l);
p.isUserNode();
p.keys();
p.name();
p.node(null);
p.nodeExists(null);
p.parent();
p.put(null, null);
p.putBoolean(null, false);
p.putByteArray(null, null);
p.putDouble(null, 1);
p.putFloat(null, 1f);
p.putInt(null, 1);
p.putLong(null, 1l);
p.remove(null);
p.removeNode();
p.addNodeChangeListener(null);
p.addPreferenceChangeListener(null);
p.removeNodeChangeListener(null);
p.removePreferenceChangeListener(null);
p.sync();
p.toString();
}
use of java.util.prefs.Preferences in project robovm by robovm.
the class OldPreferencesTest method testIsUserNode.
public void testIsUserNode() {
Preferences pref1 = Preferences.userNodeForPackage(Preferences.class);
assertTrue(pref1.isUserNode());
Preferences pref2 = Preferences.systemNodeForPackage(Preferences.class);
assertFalse(pref2.isUserNode());
}
use of java.util.prefs.Preferences in project robovm by robovm.
the class OldPreferencesTest method testPutInt.
public void testPutInt() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
pref.putInt(null, 3);
fail();
} catch (NullPointerException expected) {
}
pref.putInt(longKey, 3);
try {
pref.putInt(longKey + "a", 3);
fail();
} catch (IllegalArgumentException expected) {
}
pref.putInt("testPutIntKey", 3);
assertEquals("3", pref.get("testPutIntKey", null));
assertEquals(3, pref.getInt("testPutIntKey", 0));
}
use of java.util.prefs.Preferences in project robovm by robovm.
the class OldPreferencesTest method testGetByteArray.
public void testGetByteArray() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
pref.getByteArray(null, new byte[0]);
fail();
} catch (NullPointerException expected) {
}
// BASE64
byte[] b64Array = new byte[] { 0x59, 0x57, 0x4a, 0x6a };
pref.put("testGetByteArrayKey", "abc=");
pref.put("testGetByteArrayKey2", new String(b64Array));
pref.put("invalidKey", "<>?");
assertTrue(Arrays.equals(new byte[] { 105, -73 }, pref.getByteArray("testGetByteArrayKey", new byte[0])));
assertTrue(Arrays.equals(new byte[] { 'a', 'b', 'c' }, pref.getByteArray("testGetByteArrayKey2", new byte[0])));
assertTrue(Arrays.equals(new byte[0], pref.getByteArray("invalidKey", new byte[0])));
pref.putByteArray("testGetByteArrayKey3", b64Array);
pref.putByteArray("testGetByteArrayKey4", "abc".getBytes());
assertTrue(Arrays.equals(b64Array, pref.getByteArray("testGetByteArrayKey3", new byte[0])));
assertTrue(Arrays.equals("abc".getBytes(), pref.getByteArray("testGetByteArrayKey4", new byte[0])));
}
Aggregations