Search in sources :

Example 11 with Preferences

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

the class PreferencesTest method testPreferencesClobbersExistingFiles.

/**
     * The preferences API is designed to be hostile towards files that exist
     * where it wants to store its XML data. http://b/3431233
     */
public void testPreferencesClobbersExistingFiles() throws Exception {
    File userPrefs = new File(System.getProperty("user.home") + "/.java/.userPrefs/prefs.xml");
    FileWriter writer = new FileWriter(userPrefs);
    writer.write("lamb");
    writer.close();
    userPrefs.setReadable(false);
    userPrefs.setWritable(false);
    long oldLength = userPrefs.length();
    Preferences userPreferences = Preferences.userRoot();
    userPreferences.sync();
    userPreferences.put("a", "lion");
    userPreferences.flush();
    assertTrue("Expected to exist " + userPrefs, userPrefs.exists());
    assertTrue("Expected file to be clobbered", oldLength != userPrefs.length());
}
Also used : FileWriter(java.io.FileWriter) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 12 with Preferences

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

the class OldPreferencesTest method testName.

public void testName() {
    Preferences pref = Preferences.userNodeForPackage(Preferences.class);
    Preferences child = pref.node("mock");
    assertEquals("mock", child.name());
}
Also used : Preferences(java.util.prefs.Preferences)

Example 13 with Preferences

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

the class OldPreferencesTest method testAbsolutePath.

public void testAbsolutePath() {
    Preferences p = Preferences.userNodeForPackage(Preferences.class);
    assertEquals("/java/util/prefs", p.absolutePath());
}
Also used : Preferences(java.util.prefs.Preferences)

Example 14 with Preferences

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

the class OldPreferencesTest method testNodeExists.

public void testNodeExists() throws BackingStoreException {
    Preferences parent = Preferences.userNodeForPackage(Preferences.class);
    Preferences pref = parent.node("mock");
    try {
        pref.nodeExists(null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        pref.nodeExists("/java/util/prefs/");
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        pref.nodeExists("/java//util/prefs");
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertTrue(pref.nodeExists("/"));
    assertTrue(pref.nodeExists("/java/util/prefs"));
    assertTrue(pref.nodeExists(""));
    assertFalse(pref.nodeExists("child"));
    Preferences grandchild = pref.node("child/grandchild");
    assertTrue(pref.nodeExists("child"));
    assertTrue(pref.nodeExists("child/grandchild"));
    grandchild.removeNode();
    assertTrue(pref.nodeExists("child"));
    assertFalse(pref.nodeExists("child/grandchild"));
    assertFalse(grandchild.nodeExists(""));
    assertFalse(pref.nodeExists("child2/grandchild"));
    pref.node("child2/grandchild");
    assertTrue(pref.nodeExists("child2/grandchild"));
}
Also used : Preferences(java.util.prefs.Preferences)

Example 15 with Preferences

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

the class OldPreferencesTest method testRemove.

public void testRemove() throws BackingStoreException {
    Preferences pref = Preferences.userNodeForPackage(Preferences.class);
    pref.remove("key");
    pref.put("key", "value");
    assertEquals("value", pref.get("key", null));
    pref.remove("key");
    assertNull(pref.get("key", null));
    pref.remove("key");
    try {
        pref.remove(null);
        fail();
    } catch (NullPointerException expected) {
    }
    pref.removeNode();
    try {
        pref.remove("key");
        fail();
    } catch (IllegalStateException expected) {
    }
}
Also used : Preferences(java.util.prefs.Preferences)

Aggregations

Preferences (java.util.prefs.Preferences)241 File (java.io.File)35 BackingStoreException (java.util.prefs.BackingStoreException)34 ResourceBundle (java.util.ResourceBundle)24 FileChooser (javafx.stage.FileChooser)21 FXML (javafx.fxml.FXML)16 IOException (java.io.IOException)13 JFileChooser (javax.swing.JFileChooser)12 ArrayList (java.util.ArrayList)10 SwingWorker (javax.swing.SwingWorker)8 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)7 Engine (jgnash.engine.Engine)7 AutoCompletePreferences (org.jabref.logic.autocompleter.AutoCompletePreferences)6 FieldContentParserPreferences (org.jabref.logic.bibtex.FieldContentParserPreferences)6 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)6 BibtexKeyPatternPreferences (org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)6 CleanupPreferences (org.jabref.logic.cleanup.CleanupPreferences)6 ImportFormatPreferences (org.jabref.logic.importer.ImportFormatPreferences)6 JournalAbbreviationPreferences (org.jabref.logic.journals.JournalAbbreviationPreferences)6 NbPreferences (org.openide.util.NbPreferences)6