我已经写了这个函数来从S3中获取对象,现在我想写单元测试用例。我无法模拟“s3Client.getObjectAsynchronous(objectRequest)”,因此我可以获得“ResponseAsynchronous objectRequest”的模拟响应并继续。
GetObjectRequest objectRequest = GetObjectRequest
.builder()
.key(keyName)
.bucket(bucketName)
.build();
ResponseBytes<GetObjectResponse> objectBytes = s3Client.getObjectAsBytes(objectRequest);
LOGGER.info(objectBytes.toString());
InputStream inputStream = objectBytes.asInputStream();
String result = new BufferedReader(new InputStreamReader(inputStream))
.lines().collect(Collectors.joining("\n"));
LOGGER.info(result);
1条答案
按热度按时间6za6bjd01#