I have a method in a class, where internally calls
AmazonS3Client.java in which
AwsCredetialsProvider.getCredentials() is been called. For that I need to set
AWS_SECRET_ACCESS_KEY in my test class. Setting those values in Environment Variables are not allowed in my project.
I have tried to Mock
AWSCredentials and used stubbing to return credentials. But it is throwing the following error:
com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
Even I have tried setting those values using
ConfigurationProperties too. But nothing happened.
So, is there any possible way to mock these credential values?
I am using
MockitoJRunner. So, I cannot change it to Powermockito only for one method.
I want to fetch the files from S3 by calling
listObjects(). This is where I am facing the issue as it needs AWS credentials to fetch.
All the method callings are project specified where internally calling predefined classes and methods.
AmazonS3Client class instead of something it uses internally. If some day AWS library will get an update that changes
AmazonS3Client internals then you might have your tests broken.
AmazonS3Client amazonClient = Mockito.mock(AmazonS3Client.class);
And then set the object to be returned