I want to mock response object here when I call getHSMDecryptedData method from my test method.
private String getHSMDecryptedData(String keysetName, int groupIndex, String ksn, String encryptedData) { String decryptedData = null; try { DecryptData decrypt = new DecryptData(); decrypt.setKeySet(keysetName); decrypt.setKsnDescriptor("906"); decrypt.setKsn(ksn); decrypt.setKeyType(HSMKeyTypeDataModel.TYPE_BDK); decrypt.setEncryptionMode(HSMEncryptionMode.CBC); decrypt.setInputFormat(HSMDataFormat.HEX_ENCODED_BINARY); decrypt.setOutputFormat(HSMDataFormat.HEX_ENCODED_BINARY); decrypt.setMessage(encryptedData); // sending M2 command to HSM for decryption of encrypted data coming from CP DecryptDataResponse response = (DecryptDataResponse) HSMService.getInstance().processRequest(decrypt); System.out.println(response+"***************reponse"); if (response != null && response.getResponseCode() == HSMResponseCodes.APPROVED) { decryptedData = response.getDecryptedMessage(); TraceLog.Info(getClass(), "Message decrypted[" + decryptedData + "], original input[" + encryptedData + "], replacing original encrypted data!"); if (decryptedData == null) { // throw new FirstadatException("Unable to get the decrypted Data from HSM "); } }//FirstadatException This is my test method:
HsmDataDecrypt hsmDataDecrypt = new HsmDataDecrypt(); try { DecryptDataResponse response=mock(DecryptDataResponse.class); //response. Method method = hsmDataDecrypt.getClass().getDeclaredMethod("getHSMDecryptedData", String.class,int.class,String.class,String.class);