use of java.util.prefs.BackingStoreException in project jmonkeyengine by jMonkeyEngine.
the class TestCustomAppSettings method testPreferenceSettings.
/**
* Tests preference based AppSettings.
*/
private static void testPreferenceSettings() {
AppSettings settings = new AppSettings(false);
settings.putBoolean("TestBool", true);
settings.putInteger("TestInt", 123);
settings.putString("TestStr", "HelloWorld");
settings.putFloat("TestFloat", 123.567f);
// Objects not supported by preferences
settings.put("TestObj", new Mesh());
try {
settings.save(APPSETTINGS_KEY);
} catch (BackingStoreException ex) {
ex.printStackTrace();
}
AppSettings loadedSettings = new AppSettings(false);
try {
loadedSettings.load(APPSETTINGS_KEY);
} catch (BackingStoreException ex) {
ex.printStackTrace();
}
assertEqual(loadedSettings.getBoolean("TestBool"), true);
assertEqual(loadedSettings.getInteger("TestInt"), 123);
assertEqual(loadedSettings.getString("TestStr"), "HelloWorld");
assertEqual(loadedSettings.get("TestFloat"), 123.567f);
}
use of java.util.prefs.BackingStoreException in project robovm by robovm.
the class OldPreferencesTest method testAddPreferenceChangeListener.
public void testAddPreferenceChangeListener() throws Exception {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
MockPreferenceChangeListener pl = null;
try {
pref.addPreferenceChangeListener(null);
fail();
} catch (NullPointerException expected) {
}
// To get existed node doesn't create the change event
try {
pl = new MockPreferenceChangeListener();
pref.addPreferenceChangeListener(pl);
pref.putInt("mock1", 123);
pl.waitForEvent(1);
assertEquals(1, pl.getChanged());
pref.putLong("long_key", Long.MAX_VALUE);
pl.waitForEvent(2);
assertEquals(2, pl.getChanged());
pl.reset();
try {
pref.clear();
pl.waitForEvent(2);
assertEquals(2, pl.getChanged());
} catch (BackingStoreException bse) {
pl.reset();
fail("BackingStoreException is thrown");
}
pl.reset();
} finally {
pref.removePreferenceChangeListener(pl);
//child1.removeNode();
}
// same listener can be added twice, and must be removed twice
try {
pl = new MockPreferenceChangeListener();
pref.addPreferenceChangeListener(pl);
pref.addPreferenceChangeListener(pl);
pref.putFloat("float_key", Float.MIN_VALUE);
pl.waitForEvent(2);
assertEquals(2, pl.getChanged());
pl.reset();
} finally {
pref.removePreferenceChangeListener(pl);
pref.removePreferenceChangeListener(pl);
}
// test remove event
try {
pl = new MockPreferenceChangeListener();
pref.addPreferenceChangeListener(pl);
pref.putDouble("double_key", Double.MAX_VALUE);
pl.waitForEvent(1);
assertEquals(1, pl.getChanged());
try {
pref.clear();
pl.waitForEvent(3);
assertEquals(3, pl.getChanged());
} catch (BackingStoreException bse) {
fail("BackingStoreException is thrown");
}
pl.reset();
} finally {
pref.removePreferenceChangeListener(pl);
}
// test remove event with two listeners
try {
pl = new MockPreferenceChangeListener();
pref.addPreferenceChangeListener(pl);
pref.addPreferenceChangeListener(pl);
pref.putByteArray("byte_array_key", new byte[] { 1, 2, 3 });
try {
pref.clear();
pl.waitForEvent(4);
assertEquals(4, pl.getChanged());
} catch (BackingStoreException bse) {
fail("BackingStoreException is thrown");
}
pl.reset();
} finally {
pref.removePreferenceChangeListener(pl);
pref.removePreferenceChangeListener(pl);
}
}
use of java.util.prefs.BackingStoreException in project JMRI by JMRI.
the class JmriPreferencesProviderTest method testGetPreferences.
/**
* Test of getPreferences method, of class JmriPreferencesProvider.
* @throws java.io.IOException
*/
public void testGetPreferences() throws IOException {
String id = Long.toString((new Date()).getTime());
Profile project = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
Class<?> clazz = this.getClass();
Preferences shared = JmriPreferencesProvider.getPreferences(project, clazz, true);
Preferences privat = JmriPreferencesProvider.getPreferences(project, clazz, false);
assertNotNull(shared);
assertNotNull(privat);
assertNotSame(shared, privat);
try {
assertEquals(shared.keys().length, 0);
} catch (BackingStoreException ex) {
assertNotNull(ex);
}
try {
assertEquals(privat.keys().length, 0);
} catch (BackingStoreException ex) {
assertNotNull(ex);
}
FileUtil.delete(project.getPath());
}
use of java.util.prefs.BackingStoreException in project JMRI by JMRI.
the class JmriPreferencesProviderTest method testIsFirstUse.
/**
* Test of isFirstUse method, of class JmriPreferencesProvider.
* @throws java.io.IOException
*/
public void testIsFirstUse() throws IOException {
String id = Long.toString((new Date()).getTime());
Profile project = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
JmriPreferencesProvider shared = JmriPreferencesProvider.findProvider(project.getPath(), true);
assertEquals(shared.isFirstUse(), true);
Preferences prefs = shared.getPreferences(this.getClass());
prefs.put("test", "test");
try {
// force write
prefs.flush();
} catch (BackingStoreException ex) {
assertNull(ex);
}
shared = new JmriPreferencesProvider(project.getPath(), true);
assertEquals(shared.isFirstUse(), false);
}
use of java.util.prefs.BackingStoreException in project jabref by JabRef.
the class ArgumentProcessor method resetPreferences.
private void resetPreferences(String value) {
if ("all".equals(value.trim())) {
try {
System.out.println(Localization.lang("Setting all preferences to default values."));
Globals.prefs.clear();
new SharedDatabasePreferences().clear();
} catch (BackingStoreException e) {
System.err.println(Localization.lang("Unable to clear preferences."));
LOGGER.error("Unable to clear preferences", e);
}
} else {
String[] keys = value.split(",");
for (String key : keys) {
if (Globals.prefs.hasKey(key.trim())) {
System.out.println(Localization.lang("Resetting preference key '%0'", key.trim()));
Globals.prefs.clear(key.trim());
} else {
System.out.println(Localization.lang("Unknown preference key '%0'", key.trim()));
}
}
}
}
Aggregations