Search in sources :

Example 1 with NodeChangeEvent

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

the class OldNodeChangeEventTest method testGetChild.

public void testGetChild() throws BackingStoreException {
    AbstractPreferences parent = (AbstractPreferences) Preferences.userNodeForPackage(Preferences.class);
    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
    MockNodeChangeListener nl = new MockNodeChangeListener() {

        public synchronized void childAdded(NodeChangeEvent e) {
            Preferences child = e.getChild();
            if (child == null) {
                addResult = false;
            } else {
                if (child.name() == "mock1") {
                    addResult = true;
                }
            }
            super.childAdded(e);
        }

        public synchronized void childRemoved(NodeChangeEvent e) {
            Preferences child = e.getChild();
            if (child == null) {
                removeResult = false;
            } else {
                if (child.name() == "mock1") {
                    removeResult = true;
                }
            }
            super.childRemoved(e);
        }
    };
    try {
        pref.addNodeChangeListener(nl);
        Preferences child1 = pref.node("mock1");
        nl.waitForEvent();
        assertEquals(1, nl.getAdded());
        assertTrue(nl.getAddResult());
        nl.reset();
        child1.removeNode();
        nl.waitForEvent();
        assertEquals(1, nl.getRemoved());
        assertTrue(nl.getRemoveResult());
        nl.reset();
    } finally {
        pref.removeNodeChangeListener(nl);
    }
}
Also used : NodeChangeEvent(java.util.prefs.NodeChangeEvent) AbstractPreferences(java.util.prefs.AbstractPreferences) AbstractPreferences(java.util.prefs.AbstractPreferences) Preferences(java.util.prefs.Preferences)

Example 2 with NodeChangeEvent

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

the class OldNodeChangeEventTest method testGetParent.

public void testGetParent() throws BackingStoreException {
    AbstractPreferences parent = (AbstractPreferences) Preferences.userNodeForPackage(Preferences.class);
    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
    MockNodeChangeListener nl = new MockNodeChangeListener() {

        public synchronized void childAdded(NodeChangeEvent e) {
            Preferences parent = e.getParent();
            if (parent == null) {
                addResult = false;
            } else {
                if (parent.name() == "mock") {
                    addResult = true;
                }
            }
            super.childAdded(e);
        }

        public synchronized void childRemoved(NodeChangeEvent e) {
            Preferences parent = e.getParent();
            if (parent == null) {
                removeResult = false;
            } else {
                if (parent.name() == "mock") {
                    removeResult = true;
                }
            }
            super.childRemoved(e);
        }
    };
    try {
        pref.addNodeChangeListener(nl);
        Preferences child1 = pref.node("mock1");
        nl.waitForEvent();
        assertEquals(1, nl.getAdded());
        assertTrue(nl.getAddResult());
        nl.reset();
        child1.removeNode();
        nl.waitForEvent();
        assertEquals(1, nl.getRemoved());
        assertTrue(nl.getRemoveResult());
        nl.reset();
    } finally {
        pref.removeNodeChangeListener(nl);
    }
}
Also used : NodeChangeEvent(java.util.prefs.NodeChangeEvent) AbstractPreferences(java.util.prefs.AbstractPreferences) AbstractPreferences(java.util.prefs.AbstractPreferences) Preferences(java.util.prefs.Preferences)

Aggregations

AbstractPreferences (java.util.prefs.AbstractPreferences)2 NodeChangeEvent (java.util.prefs.NodeChangeEvent)2 Preferences (java.util.prefs.Preferences)2