The Testcase I'm writing looks something like this
@Mock AWSClient awsClient;
@Mock AWSSecretsManager secretsManagerClient;
@Mock GetSecretValueResult secretValueResult;
private static final SECRET_VALUE = "value";
private static final ID = "id";
@Test
public void handleRequest() {
when(secretsManagerClient.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult);
when(secretValueResult.getSecretString()).thenReturn(SECRET_VALUE));
String response = awsClient.getSecretsManagerSecret(ID);
assertNotNull(response);
}
The method I'm trying to test looks something like this (removed some try catch blocks and some logs) :
public class AWSClient{
public String getSecretsManagerSecret(String id) {
AWSSecretsManager client = AWSSecretsManagerClientBuilder.standard().build();
GetSecretValueRequest request = new GetSecretValueRequest().withSecretId(id);
GetSecretValueResult result = null;
result = client.getSecretValue(request);
response = result.getSecretString();
return response;
}
}
I am probably wrong about the functionality of the Secrets Manager Client here, but can anyone direct me towards why I'm getting a null response for the test?
The when(secretValueResult.getSecretString()).thenReturn(SECRET_VALUE)); doesn't seem to work here as result.getSecretString() seems to return null.
I need to mock the AWSClient as there are a few other external dependencies in that class and I don't have admin rights to install aws-cli.
Thanks in advance!