Issue
I'm working with Java and I'm using the AWS SDK for interact with S3. I've the following method and I want to unit test it
private final S3Client s3Client;
...
...
public byte[] download(String key) throws IOException {
GetObjectRequest getObjectRequest = GetObjectRequest.builder()
.bucket("myBucket")
.key(key)
.build();
return s3Client.getObject(getObjectRequest).readAllBytes();
}
For this purpose I'm using JUnit 5 and Mockito. The problem is that I don't know how to mock the result of
s3Client.getObject(getObjectRequest)
because the return type
ResponseInputStream<GetObjectResponse>
is a final class.
Any idea or suggestions? Thank you
Solution
The problem is solved. In a maven project you can add a file named "org.mockito.plugins.MockMaker" in the folder "src/test/resources/mockito-extensions".
Inside the file, add "mock-maker-inline" without quotes.
From now Mockito will be able to mock final classes also.
Answered By - Gavi