### Question:
SecretManager { public String decrypt(String configValue) { if (EncryptedSecret.isEncryptedSecret(configValue)) { return new String(decryptAsBytes(configValue)); } return configValue; } @Autowired  SecretManager(SecretEngineRegistry secretEngineRegistry); String decrypt(String configValue); Path decryptAsFile(String filePathOrEncrypted); byte[] decryptAsBytes(String encryptedString);  }### Answer:
@Test public void decryptTest() throws SecretDecryptionException { String secretConfig = "encrypted:s3!paramName:paramValue"; when(secretEngine.decrypt(any())).thenReturn("test".getBytes()); assertEquals("test", secretManager.decrypt(secretConfig)); }
@Test public void decryptSecretEngineNotFound() throws SecretDecryptionException { when(secretEngineRegistry.getEngine("does-not-exist")).thenReturn(null); String secretConfig = "encrypted:does-not-exist!paramName:paramValue"; exceptionRule.expect(SecretDecryptionException.class); exceptionRule.expectMessage("Secret Engine does not exist: does-not-exist"); secretManager.decrypt(secretConfig); }
@Test public void decryptInvalidParams() throws SecretDecryptionException { doThrow(InvalidSecretFormatException.class).when(secretEngine).validate(any()); String secretConfig = "encrypted:s3!paramName:paramValue"; exceptionRule.expect(InvalidSecretFormatException.class); secretManager.decrypt(secretConfig); }