Code example for AbstractPreferences

Methods: addPreferenceChangeListener, node, putInt, removePreferenceChangeListener

0
 
    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);
        } 
    } 
 
    public void testGetNode() { 
        AbstractPreferences parent = (AbstractPreferences) Preferences