### Question:
Decryptor { public static String getAlias(final Dictionary<String, Object> config) { String alias = getValue(config, DECRYPTOR_ALIAS); for (Enumeration<String> e = config.keys(); e.hasMoreElements();) { final String key = e.nextElement(); String value = getValue(config, key); String newAlias = getAlias(value); if (newAlias != null) { if (alias == null) { alias = newAlias; } else { if (!alias.equals(newAlias)) { throw new RuntimeException("Only one alias is supported but found at least two: " + newAlias + ", " + alias); } } } } return alias; } Decryptor(final StringEncryptor decryptor); static String getAlias(final Dictionary<String, Object> config); Dictionary<String, Object> decrypt(final Dictionary<String, Object> config); static boolean isEncrypted(String value); static boolean isEncrypted(Dictionary<String, Object> loadedConfig);  }### Answer:
@Test public void testDecryptWithEncryptedPropertiesAndUnknownAlias() { Dictionary cfProps = new Hashtable<>(); cfProps.put("name", "testCF"); cfProps.put("password", "ENC(something,testAlias)"); cfProps.put("timeout", 2000); Assert.assertEquals("testAlias", Decryptor.getAlias(cfProps)); }
@Test(expected = RuntimeException.class) public void testDecryptWithTwoDifferentAliases() { Dictionary cfProps = new Hashtable<>(); cfProps.put("password", "ENC(something,testAlias)"); cfProps.put("password2", "ENC(something,testAlias2)"); Decryptor.getAlias(cfProps); }
@Test public void testDecryptWithEncryptedPropertiesAndUnknownAlias() { Dictionary dsProps = new Hashtable<>(); dsProps.put("dataSourceName", "testDS"); dsProps.put("password", "ENC(something,testAlias)"); dsProps.put("timeout", 2000); Assert.assertEquals("testAlias", Decryptor.getAlias(dsProps)); }
@Test(expected = RuntimeException.class) public void testDecryptWithTwoDifferentAliases() { Dictionary dsProps = new Hashtable<>(); dsProps.put("password", "ENC(something,testAlias)"); dsProps.put("password2", "ENC(something,testAlias2)"); Decryptor.getAlias(dsProps); }