I need to mock the amazonS3.getObject(GetObjectRequest, File) from com.amazonaws.services.s3 library, to test my own method that gets a file from it.
I need one test where the requested object is found and everything is ok, and one where file is not found in S3 bucked, and thenReturn would return null.
So the simple case is something like:
ObjectMetadata objectMetadata = new ObjectMetadata();
Mockito.lenient().when(amazonS3.getObject(any(GetObjectRequest.class), any(File.class))).thenReturn(objectMetadata);
How do I duplicate and modify this to allow different return as per the object input?
In the function itself, this is what is being fed as GetObjectRequest:
GetObjectRequest getObjectRequest = new GetObjectRequest(this.getBucketName(), objectKey);
So we neeed to change any(GetObjectRequest.class) to something that will distinguish an object where objectKey (string) is "X", of another call where the objectKey is "Y", in which case I want to return null to fully test my function.
I hope the question is clear?