Integration test for transfer manager download directory from S3Bucket

1.2k views Asked by At

I have successfully downloaded the directory from S3 Bucket using transfer manager builder. The code is given below.

TransferManager transferManager = 
TransferManagerBuilder.standard().withS3Client(client).build();
MultipleFileDownload download = 
transferManager.downloadDirectory(bname, key, destfile);

Now i am trying to write test for the same. I have mocked Amazon s3Client code below.

AmazonS3 client = Mockito.mock(AmazonS3.class);

There is a null pointer exception in

transferManager.downloadDirectory(bname, key, destfile); 

Kindly help me in writing the unit test!

1

There are 1 answers

0
Kraylog On

Don't mock what you don't own.

Mocking somebody else's code makes assumptions that you cannot guarantee, especially if you ever upgrade the library you're using.

There are a couple of things you can do instead:

  1. Use a tool such as WireMock to create a mock S3, and use that to create your integration test. This tool allows you to record/play HTTP interactions with the server. This still could break eventually, if you upgrade.
  2. Use a contract test that runs against the real S3 with the real Amazon client, to see that it actually works. I'd put this in a separate build, and run it occasionally just to make sure you're still compatible.

You could (and probably should) use both.