diff --git a/core.startup/test/unit/src/org/netbeans/core/startup/preferences/TestPreferences.java b/core.startup/test/unit/src/org/netbeans/core/startup/preferences/TestPreferences.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/preferences/TestPreferences.java +++ b/core.startup/test/unit/src/org/netbeans/core/startup/preferences/TestPreferences.java @@ -44,6 +44,7 @@ package org.netbeans.core.startup.preferences; +import java.io.InputStream; import java.util.Arrays; import java.util.prefs.BackingStoreException; import java.util.prefs.NodeChangeEvent; @@ -51,6 +52,7 @@ import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; +import org.openide.filesystems.FileObject; /** * @@ -451,6 +453,26 @@ pref.sync(); assertEquals("value", pref.get("key", null)); } + + public void testUnsavedChangesDropped () throws Exception { + NbPreferences pref = (NbPreferences) getPreferencesNode(); + FileObject fo = ((PropertiesStorage) pref.fileStorage).toPropertiesFile(true); + InputStream is = fo.getInputStream(); + // first change made to prefs + pref.put("KEY1", "VALUE1"); + // wait until the async task persisting the props starts + Thread.sleep(300); + // now let the async task finish it's job + is.close(); + // make the second change before the map in memory is nulled + pref.put("KEY2", "VALUE2"); + // wait for the finilizing stage of the async task - property map should be nulled + Thread.sleep(300); + // now time for tests, first value should be OK + assertEquals("VALUE1", pref.get("KEY1", null)); + // but where's the second value?? it nulled + assertEquals("VALUE2", pref.get("KEY2", null)); + } @Override protected int timeOut() {