简体   繁体   中英

Integration test for transfer manager download directory from S3Bucket

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM