ergerodr / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

Support for save/restore preferences #175

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
From Simeon Fitch:

Several of my higher level GUI components store state in the
java.util.prefs.Preferences service. Several tests directly or
indirectly modify the Preferences store, leaving behind "artifacts" of
the test runs, which I'd like to avoid. I'm exploring options for
backup up and restoring (or pushing/popping) the preferences state in
the @Before/@After or @BeforeClass/@AfterClass methods.

I'm curious to know if anyone else has tackled this, or if there are
plans to have it included in FEST-Swing.

If not, I'm considering using the
Preferences.exportSubtree(OutputStream) and
Preferences.importPreferences(InputStream) methods to save/restore
from a temporary file. Any thoughts or recommendations?

Original issue reported on code.google.com by Alex.Rui...@gmail.com on 14 Jul 2008 at 7:53

GoogleCodeExporter commented 8 years ago
From Simeon Fitch:

This is from an old posting, but I have a basic (and simple) solution
to what I was looking for in the description below, and wanted to
share it in case anyone else wanted it as well. I don't think it's
generalized or significant enough to be a part of the FEST suite (I
report, you decide), but here it is:

   public static void initPreferencesStore() throws IOException {
       File dir = new File("tmpPrefs");

       if(dir.exists()) {
           dir.delete();
       }

       dir.mkdirs();
       dir.deleteOnExit();

       System.setProperty("java.util.prefs.PreferencesFactory",
"java.util.prefs.FileSystemPreferencesFactory");
       System.setProperty("java.util.prefs.userRoot", new File(dir,
"user").getCanonicalPath());
       System.setProperty("java.util.prefs.userSystem", new File(dir,
"system").getCanonicalPath());

       // Initialize Preferences system by accessing something.
       Preferences.userRoot();

   }

Note that this has to be called before *any* call to the Preferences
API, or otherwise the property settings won't have any effect. The end
result is that you get a completely empty preferences store for your
test invocation, which is then deleted after execution ends. Note that
I've only tested this on MacOS X.

Original comment by Alex.Rui...@gmail.com on 5 Sep 2008 at 8:47

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Issue migrated to http://kenai.com/jira/browse/FEST-32

Original comment by Alex.Rui...@gmail.com on 15 Feb 2009 at 7:20

GoogleCodeExporter commented 8 years ago
Issue migrated to http://jira.codehaus.org/browse/FEST-33

Original comment by Alex.Rui...@gmail.com on 4 Mar 2009 at 1:49