Some tweaks to error messages.

This commit is contained in:
Adam Murdoch
2013-12-12 12:13:55 +11:00
parent a42b016088
commit 9719776a8d
2 changed files with 8 additions and 8 deletions

View File

@@ -29,7 +29,7 @@ public class DefaultWindowsRegistry implements WindowsRegistry {
ArrayList<String> subkeys = new ArrayList<String>(); ArrayList<String> subkeys = new ArrayList<String>();
boolean found = WindowsRegistryFunctions.getSubkeys(key.ordinal(), subkey, subkeys, result); boolean found = WindowsRegistryFunctions.getSubkeys(key.ordinal(), subkey, subkeys, result);
if (result.isFailed()) { if (result.isFailed()) {
throw new NativeException(String.format("Could not get subkeys of registry key '%s\\%s': %s", key, throw new NativeException(String.format("Could not list the subkeys of registry key '%s\\%s': %s", key,
subkey, result.getMessage())); subkey, result.getMessage()));
} }
if (!found) { if (!found) {
@@ -44,12 +44,12 @@ public class DefaultWindowsRegistry implements WindowsRegistry {
ArrayList<String> names = new ArrayList<String>(); ArrayList<String> names = new ArrayList<String>();
boolean found = WindowsRegistryFunctions.getValueNames(key.ordinal(), subkey, names, result); boolean found = WindowsRegistryFunctions.getValueNames(key.ordinal(), subkey, names, result);
if (result.isFailed()) { if (result.isFailed()) {
throw new NativeException(String.format("Could not get value names of registry key '%s\\%s': %s", key, throw new NativeException(String.format("Could not list the values of registry key '%s\\%s': %s", key,
subkey, result.getMessage())); subkey, result.getMessage()));
} }
if (!found) { if (!found) {
throw new MissingRegistryEntryException(String.format( throw new MissingRegistryEntryException(String.format(
"Could not list the value names of registry key '%s\\%s' as it does not exist.", key, subkey)); "Could not list the values of registry key '%s\\%s' as it does not exist.", key, subkey));
} }
return names; return names;
} }

View File

@@ -34,12 +34,12 @@ class WindowsRegistryTest extends Specification {
e.message == /Could not get value 'Value' of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Unknown' as it does not exist./ e.message == /Could not get value 'Value' of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Unknown' as it does not exist./
} }
def "can read subkeys"() { def "can list subkeys of a key"() {
expect: expect:
windowsRegistry.getSubkeys(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Microsoft/).flatten().contains("Windows NT") windowsRegistry.getSubkeys(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Microsoft/).flatten().contains("Windows NT")
} }
def "cannot read subkeys of key that does not exist"() { def "cannot list subkeys of key that does not exist"() {
when: when:
windowsRegistry.getSubkeys(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Unknown/) windowsRegistry.getSubkeys(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Unknown/)
@@ -48,17 +48,17 @@ class WindowsRegistryTest extends Specification {
e.message == /Could not list the subkeys of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Unknown' as it does not exist./ e.message == /Could not list the subkeys of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Unknown' as it does not exist./
} }
def "can read value names"() { def "cannot list values of a key"() {
expect: expect:
windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Microsoft\Windows NT\CurrentVersion/).flatten().contains("CurrentVersion") windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Microsoft\Windows NT\CurrentVersion/).flatten().contains("CurrentVersion")
} }
def "cannot read value names of key that does not exist"() { def "cannot list values of key that does not exist"() {
when: when:
windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Unknown/) windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Unknown/)
then: then:
def e = thrown(MissingRegistryEntryException) def e = thrown(MissingRegistryEntryException)
e.message == /Could not list the value names of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Unknown' as it does not exist./ e.message == /Could not list the values of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Unknown' as it does not exist./
} }
} }