### Question:
S3Client { List<S3ObjectSummary> listObjects(String bucket, String key) { List<S3ObjectSummary> objectSummaries = new ArrayList<>(); ListObjectsV2Result listObjectsV2Result; String continuationToken = null; do { ListObjectsV2Request request = new ListObjectsV2Request() .withBucketName(bucket) .withPrefix(key) .withEncodingType("url") .withContinuationToken(continuationToken); listObjectsV2Result = amazonS3.listObjectsV2(request); objectSummaries.addAll(listObjectsV2Result.getObjectSummaries()); continuationToken = listObjectsV2Result.getNextContinuationToken(); } while (listObjectsV2Result.isTruncated()); return objectSummaries; } S3Client(AmazonS3 amazonS3, boolean dryRunEnabled);   }### Answer:
@Test void listBatchObjects() { int s3BatchSize = 1000; int extraKeys = 100; List<String> keys = new ArrayList<>(); for (int i = 1; i <= s3BatchSize + extraKeys; i++) { keys.add(keyRoot + "/file" + i); } keys.parallelStream() .forEach(key -> amazonS3.putObject(bucket, key, content)); List<S3ObjectSummary> result = s3Client.listObjects(bucket, keyRoot); assertThat(result.size()).isEqualTo(s3BatchSize + extraKeys); }
@Test void listObjects() { amazonS3.putObject(bucket, key1, content); amazonS3.putObject(bucket, key2, content); List<S3ObjectSummary> result = s3Client.listObjects(bucket, keyRoot); assertThat(result.size()).isEqualTo(2); assertThat(result.get(0).getBucketName()).isEqualTo(bucket); assertThat(result.get(0).getKey()).isEqualTo(key1); assertThat(result.get(1).getBucketName()).isEqualTo(bucket); assertThat(result.get(1).getKey()).isEqualTo(key2); }
@Test void listObjectsWithSpace() { String spacedKey1 = keyRoot + "/ /file1"; String spacedKey2 = keyRoot + "/ /file2"; amazonS3.putObject(bucket, spacedKey1, content); amazonS3.putObject(bucket, spacedKey2, content); List<S3ObjectSummary> result = s3Client.listObjects(bucket, keyRoot); assertThat(result.size()).isEqualTo(2); assertThat(result.get(0).getBucketName()).isEqualTo(bucket); assertThat(result.get(0).getKey()).isEqualTo(spacedKey1); assertThat(result.get(1).getBucketName()).isEqualTo(bucket); assertThat(result.get(1).getKey()).isEqualTo(spacedKey2); }
@Test void listObjectsWithSpaceInSearch() { String spacedKeyRoot = keyRoot + "/ /"; String spacedKey1 = spacedKeyRoot + "file1"; String spacedKey2 = spacedKeyRoot + "file2"; amazonS3.putObject(bucket, spacedKey1, content); amazonS3.putObject(bucket, spacedKey2, content); List<S3ObjectSummary> result = s3Client.listObjects(bucket, spacedKeyRoot); assertThat(result.size()).isEqualTo(2); assertThat(result.get(0).getBucketName()).isEqualTo(bucket); assertThat(result.get(0).getKey()).isEqualTo(spacedKey1); assertThat(result.get(1).getBucketName()).isEqualTo(bucket); assertThat(result.get(1).getKey()).isEqualTo(spacedKey2); }