feisty meow concerns codebase  2.140
RegistryEditorTestCase.java
Go to the documentation of this file.
1 package org.feistymeow.system;
2 
3 import static org.junit.Assert.*;
4 import org.junit.*;
5 
6 import org.feistymeow.system.RegistryEditor;
7 
15 {
16  @Before
17  public void setUp() throws Exception
18  {
19  }
20 
21  @After
22  public void tearDown() throws Exception
23  {
24  }
25 
26  @Test
27  public void testCheckKey_missing() {
28  // this key cannot exist, since we're not allowed to write at that
29  // top level hive (as far as we know).
30  assertFalse(RegistryEditor.checkKey("HKLM\\flaubert\\maximus"));
31  }
32 
33  @Test
34  public void testCheckKey_present() {
35  // this key must always exist as far as we know.
36  assertTrue(RegistryEditor.checkKey("HKLM\\Software"));
37  }
38 
39  @Test
40  public void testCheckKey_bad() {
41  assertFalse(RegistryEditor.checkKey(null));
42  }
43 
44  @Test
45  public void testGetValue_present() {
46  String PERSONAL_FOLDER_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
47  String PERSONAL_FOLDER_VALUE = "Personal";
48  assertNotNull(RegistryEditor.getValue(PERSONAL_FOLDER_KEY, PERSONAL_FOLDER_VALUE,
50  }
51 
52  @Test
53  public void testGetValue_missing() {
54  String PERSONAL_FOLDER_KEY = "HKCU\\Flombix\\Gruntnork";
55  String PERSONAL_FOLDER_VALUE = "Personalish";
56  assertNull(RegistryEditor.getValue(PERSONAL_FOLDER_KEY, PERSONAL_FOLDER_VALUE,
58  }
59 
60  @Test
62  {
63  String EXAMPLE_KEY_ROOT = "HKCU\\Software\\SpunkBaster5000";
64  String EXAMPLE_KEY = EXAMPLE_KEY_ROOT + "\\traumix";
65  String EXAMPLE_VALUE = "glonkish";
66  String EXAMPLE_CONTENTS1 = "ralphWiggum!";
67  String EXAMPLE_CONTENTS2 = "moeSzyslak?";
68 
69  // first try deleting the value. this should fail to start with.
70  assertFalse(RegistryEditor.deleteValue(EXAMPLE_KEY, EXAMPLE_VALUE));
71  // remove the entire key if present.
72  assertFalse(RegistryEditor.deleteKey(EXAMPLE_KEY_ROOT));
73  // now test that it really doesn't seem to be there.
74  assertFalse(RegistryEditor.checkKey(EXAMPLE_KEY));
75 //System.out.println("now setting key [" + EXAMPLE_KEY + "] value [" + EXAMPLE_VALUE + "] to '" + EXAMPLE_CONTENTS1 + "'");
76  // now try adding the example value.
77  assertTrue(RegistryEditor.setValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE, EXAMPLE_CONTENTS1));
78  // check that the contents are what we expect.
79  assertEquals(RegistryEditor.getValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE),
80  EXAMPLE_CONTENTS1);
81  // now change the value's contents to a new setting.
82  assertTrue(RegistryEditor.setValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE, EXAMPLE_CONTENTS2));
83  // make sure the update has succeeded.
84  assertEquals(RegistryEditor.getValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE),
85  EXAMPLE_CONTENTS2);
86  // now whack the value we had added.
87  assertTrue(RegistryEditor.deleteValue(EXAMPLE_KEY, EXAMPLE_VALUE));
88  // now remove the entire key we added.
89  assertTrue(RegistryEditor.deleteKey(EXAMPLE_KEY_ROOT));
90  }
91 
92 }
93 
static boolean deleteKey(String keyName)
static boolean setValue(String keyName, String valueName, String typeExpected, String newValue)
static boolean checkKey(String keyName)
static String getValue(String keyName, String valueName, String typeExpected)
static boolean deleteValue(String keyName, String valueName)