简体   繁体   中英

Mocking aws-sdk-java 2.0

I'm trying to test my AWS Lambda function but I can't figure out how to mock the 2.0 SDK with Mockito. Basically, all I want is to create a couple DBSnapshot mocks and set a bit of test information on them (snapshot name and creation time would be enough for my purposes).

If I make a new DBSnapshot with the 'new' operator, I can't seem to set any parameters on it, or even mock a builder with a request to create one.

In the 1.0 SDK, I could mock a DBSnapshot and set various ".withBlah' params like below:

DBSnapshot testSnapshot = new DBSnapshot().withSnapshotCreateTime("2020-01-01")[...]

but it doesn't seem possible here since the 2.0 rewrite to force everything through a builder, and I'm not sure how to mock it now. Googling hasn't turned up any code examples for the 2.0 SDK/RDS in particular.

Any ideas?

Try this:

DBSnapshot testSnapshot = DBSnapshot
    .builder()
    .snapshotCreateTime(Instant.now())
    .build();

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