Search in sources :

Example 6 with AbstractPreferences

use of java.util.prefs.AbstractPreferences in project robovm by robovm.

the class OldAbstractPreferencesTest method testNodeExists.

public void testNodeExists() throws BackingStoreException {
    AbstractPreferences ap1 = (AbstractPreferences) pref.node("First node");
    AbstractPreferences ap2 = (AbstractPreferences) pref.node("Second node");
    pref.putInt("IntegerValue", 33);
    pref.putBoolean("BoolValue", true);
    pref.flush();
    assertTrue(pref.nodeExists("First node"));
    assertTrue(pref.nodeExists("Second node"));
    assertFalse(pref.nodeExists("IntegerValue"));
    assertFalse(pref.nodeExists("BoolValue"));
    assertFalse(pref.nodeExists("Value"));
    assertFalse(pref.nodeExists(nodeName));
    try {
        pref.nodeExists("///invalid");
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    pref.removeNode();
    try {
        pref.nodeExists("Exception");
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //expected
    }
}
Also used : AbstractPreferences(java.util.prefs.AbstractPreferences)

Example 7 with AbstractPreferences

use of java.util.prefs.AbstractPreferences in project robovm by robovm.

the class OldPreferenceChangeEventTest method testGetNewValue.

public void testGetNewValue() {
    AbstractPreferences parent = (AbstractPreferences) Preferences.userNodeForPackage(Preferences.class);
    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
    MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {

        public void preferenceChange(PreferenceChangeEvent pce) {
            if (pce != null && pce.getNewValue().equals(Integer.toString(Integer.MAX_VALUE))) {
                result = true;
            }
            super.preferenceChange(pce);
        }
    };
    pref.addPreferenceChangeListener(pl);
    try {
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
    }
}
Also used : PreferenceChangeEvent(java.util.prefs.PreferenceChangeEvent) AbstractPreferences(java.util.prefs.AbstractPreferences) AbstractPreferences(java.util.prefs.AbstractPreferences) Preferences(java.util.prefs.Preferences)

Example 8 with AbstractPreferences

use of java.util.prefs.AbstractPreferences in project robovm by robovm.

the class OldPreferenceChangeEventTest method testGetNode.

public void testGetNode() {
    AbstractPreferences parent = (AbstractPreferences) Preferences.userNodeForPackage(Preferences.class);
    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
    MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {

        public void preferenceChange(PreferenceChangeEvent pce) {
            if (pce != null && "mock".equals(pce.getNode().name())) {
                result = true;
            }
            super.preferenceChange(pce);
        }
    };
    pref.addPreferenceChangeListener(pl);
    try {
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
    }
}
Also used : PreferenceChangeEvent(java.util.prefs.PreferenceChangeEvent) AbstractPreferences(java.util.prefs.AbstractPreferences) AbstractPreferences(java.util.prefs.AbstractPreferences) Preferences(java.util.prefs.Preferences)

Example 9 with AbstractPreferences

use of java.util.prefs.AbstractPreferences in project robovm by robovm.

the class OldAbstractPreferencesTest method testExportSubtree.

public void testExportSubtree() throws BackingStoreException, IOException, InvalidPreferencesFormatException {
    AbstractPreferences ap1 = (AbstractPreferences) pref.node("First node");
    AbstractPreferences ap2 = (AbstractPreferences) pref.node("Second node");
    pref.putInt("IntegerValue", 33);
    pref.putBoolean("BoolValue", true);
    pref.flush();
    ap1.putInt("FirstIntValue", 11);
    ap2.putDouble("DoubleValue", new Double(6.626e-34));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    pref.exportSubtree(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    assertTrue(pref.getBoolean("BoolValue", false));
    assertEquals(33, pref.getInt("IntegerValue", 22));
    assertEquals(2, pref.childrenNames().length);
    assertEquals(11, ap1.getInt("FirstIntValue", 22));
    assertEquals(new Double(6.626e-34), ap2.getDouble("DoubleValue", new Double(3.14)));
    String xmlData = new String(baos.toByteArray());
    assertTrue(xmlData.contains("IntegerValue"));
    assertTrue(xmlData.contains("BoolValue"));
    assertTrue(xmlData.contains("FirstIntValue"));
    assertTrue(xmlData.contains("DoubleValue"));
    assertTrue(xmlData.contains("33"));
    assertTrue(xmlData.contains("true"));
    assertTrue(xmlData.contains("11"));
    assertTrue(xmlData.contains("6.626E-34"));
    pref.removeNode();
    try {
        pref.exportSubtree(new ByteArrayOutputStream());
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //expected
    }
    try {
        pref.getBoolean("BoolValue", false);
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //expected
    }
    pref = (AbstractPreferences) parent.node(nodeName);
    pref.importPreferences(bais);
    ap1 = (AbstractPreferences) pref.node("First node");
    ap2 = (AbstractPreferences) pref.node("Second node");
    assertTrue(pref.getBoolean("BoolValue", false));
    assertEquals(33, pref.getInt("IntegerValue", 22));
    assertEquals(2, pref.childrenNames().length);
    assertEquals(11, ap1.getInt("FirstIntValue", 22));
    assertEquals(new Double(6.626e-34), ap2.getDouble("DoubleValue", new Double(3.14)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractPreferences(java.util.prefs.AbstractPreferences) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 10 with AbstractPreferences

use of java.util.prefs.AbstractPreferences in project robovm by robovm.

the class OldAbstractPreferencesTest method test_nodeExists.

public void test_nodeExists() throws BackingStoreException {
    AbstractPreferences test = (AbstractPreferences) Preferences.userRoot().node("test");
    try {
        test.nodeExists(null);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    // Expected
    }
    test.removeNode();
    try {
        test.nodeExists(null);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : AbstractPreferences(java.util.prefs.AbstractPreferences)

Aggregations

AbstractPreferences (java.util.prefs.AbstractPreferences)15 Preferences (java.util.prefs.Preferences)6 PreferenceChangeEvent (java.util.prefs.PreferenceChangeEvent)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 NodeChangeEvent (java.util.prefs.NodeChangeEvent)2