I have been trying to test my code which internally calls Amazons3.listObjects(), but i am struggling with mocking the Amazons3 class. Can some one please let me know the right way to do it?
here is the code Processor.class
AmazonS3 s3 = getS3Build();
final List<String> flagFiles = s3.listObjectsV2(dataBucket, flagFolder)
public AmazonS3 getS3Build() {
return AmazonS3ClientBuilder.standard().withRegion(US_EAST_1).build();
}
Test.class
Mockito.when(processor.getS3Build()).thenReturn(s3);
Mockito.when(s3.listObjectsV2(anyString(), anyString())).thenReturn(listObjectsV2Result);
Error occuring at s3.listObjectsV2
Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied;
I don't understand why its trying to call the actual listObjectsV2 when i have already mocked the class.
Thanks for the help :)