1 package org.feistymeow.system;
\r
3 import static org.junit.Assert.*;
\r
6 import org.feistymeow.system.RegistryEditor;
\r
9 * RegistryEditor junit tests.
\r
11 * @author Chris Koeritz
\r
14 public class RegistryEditorTestCase
\r
17 public void setUp() throws Exception
\r
22 public void tearDown() throws Exception
\r
27 public void testCheckKey_missing() {
\r
28 // this key cannot exist, since we're not allowed to write at that
\r
29 // top level hive (as far as we know).
\r
30 assertFalse(RegistryEditor.checkKey("HKLM\\flaubert\\maximus"));
\r
34 public void testCheckKey_present() {
\r
35 // this key must always exist as far as we know.
\r
36 assertTrue(RegistryEditor.checkKey("HKLM\\Software"));
\r
40 public void testCheckKey_bad() {
\r
41 assertFalse(RegistryEditor.checkKey(null));
\r
45 public void testGetValue_present() {
\r
46 String PERSONAL_FOLDER_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
\r
47 String PERSONAL_FOLDER_VALUE = "Personal";
\r
48 assertNotNull(RegistryEditor.getValue(PERSONAL_FOLDER_KEY, PERSONAL_FOLDER_VALUE,
\r
49 RegistryEditor.STRING_TYPE));
\r
53 public void testGetValue_missing() {
\r
54 String PERSONAL_FOLDER_KEY = "HKCU\\Flombix\\Gruntnork";
\r
55 String PERSONAL_FOLDER_VALUE = "Personalish";
\r
56 assertNull(RegistryEditor.getValue(PERSONAL_FOLDER_KEY, PERSONAL_FOLDER_VALUE,
\r
57 RegistryEditor.STRING_TYPE));
\r
61 public void testSetValueAndRemove_AllWork()
\r
63 String EXAMPLE_KEY_ROOT = "HKCU\\Software\\SpunkBaster5000";
\r
64 String EXAMPLE_KEY = EXAMPLE_KEY_ROOT + "\\traumix";
\r
65 String EXAMPLE_VALUE = "glonkish";
\r
66 String EXAMPLE_CONTENTS1 = "ralphWiggum!";
\r
67 String EXAMPLE_CONTENTS2 = "moeSzyslak?";
\r
69 // first try deleting the value. this should fail to start with.
\r
70 assertFalse(RegistryEditor.deleteValue(EXAMPLE_KEY, EXAMPLE_VALUE));
\r
71 // remove the entire key if present.
\r
72 assertFalse(RegistryEditor.deleteKey(EXAMPLE_KEY_ROOT));
\r
73 // now test that it really doesn't seem to be there.
\r
74 assertFalse(RegistryEditor.checkKey(EXAMPLE_KEY));
\r
75 //System.out.println("now setting key [" + EXAMPLE_KEY + "] value [" + EXAMPLE_VALUE + "] to '" + EXAMPLE_CONTENTS1 + "'");
\r
76 // now try adding the example value.
\r
77 assertTrue(RegistryEditor.setValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE, EXAMPLE_CONTENTS1));
\r
78 // check that the contents are what we expect.
\r
79 assertEquals(RegistryEditor.getValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE),
\r
81 // now change the value's contents to a new setting.
\r
82 assertTrue(RegistryEditor.setValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE, EXAMPLE_CONTENTS2));
\r
83 // make sure the update has succeeded.
\r
84 assertEquals(RegistryEditor.getValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE),
\r
86 // now whack the value we had added.
\r
87 assertTrue(RegistryEditor.deleteValue(EXAMPLE_KEY, EXAMPLE_VALUE));
\r
88 // now remove the entire key we added.
\r
89 assertTrue(RegistryEditor.deleteKey(EXAMPLE_KEY_ROOT));
\r