我是编写单元测试的新手。我正在尝试读取存储在其中的 JSON 文件S3,但收到“传递给 when() 的参数不是模拟!” 和“配置文件不能为空”错误。
到目前为止,这是我尝试使用 JAVA 检索对象的方法:
private void amazonS3Read() {
String clientRegion = "us-east-1";
String bucketName = "version";
String key = "version.txt";
S3Object fullObject = null;
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withRegion(clientRegion)
.withCredentials(new ProfileCredentialsProvider())
.build();
fullObject = s3Client.getObject(new GetObjectRequest(bucketName, key));
S3ObjectInputStream s3is = fullObject.getObjectContent();
json = returnStringFromInputStream(s3is);
fullObject.close();
s3is.close();
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an …Run Code Online (Sandbox Code Playgroud)