S3 { public static PagedIterable<ObjectMetadata> listBucket(final S3Client s3Client, final String bucket, final ListBucketOptions options) { return PagedIterables.advance(ToIterableWithMarker.INSTANCE.apply(s3Client.listBucket(bucket, options)), new Function<Object, IterableWithMarker<ObjectMetadata>>() { @Override public IterableWithMarker<ObjectMetadata> apply(Object input) { return ToIterableWithMarker.INSTANCE.apply(s3Client.listBucket(bucket, options.clone().afterMarker(input.toString()))); } @Override public String toString() { return "listBucket(" + options + ")"; } }); }  static PagedIterable<ObjectMetadata> listBucket(final S3Client s3Client, final String bucket,
         final ListBucketOptions options);  }
@Test public void testSinglePageResult() throws Exception { S3Client api = createMock(S3Client.class); ListBucketOptions options = new ListBucketOptions(); ListBucketResponse response = new ListBucketHandlerTest().expected(); expect(api.listBucket("bucket", options)).andReturn(response).once(); EasyMock.replay(api); PagedIterable<ObjectMetadata> result = S3.listBucket(api, "bucket", options); assertEquals(result.size(), 1); assertEquals(result.get(0).size(), 10); }
@Test public void testMultiPageResult() throws Exception { String nextMarker = "FOO"; S3Client api = createMock(S3Client.class); ListBucketOptions options = new ListBucketOptions(); ListBucketResponse response2 = new ListBucketHandlerTest().expected(); ListBucketResponse response1 = new ListBucketResponseImpl(response2.getName(), response2, response2.getPrefix(), null, nextMarker, response2.getMaxKeys(), response2.getDelimiter(), false, response2.getCommonPrefixes()); expect(api.listBucket("bucket", options)).andReturn(response1).once(); expect(api.listBucket("bucket", options.afterMarker(nextMarker))).andReturn(response2).once(); EasyMock.replay(api); PagedIterable<ObjectMetadata> result = S3.listBucket(api, "bucket", options); assertEquals(result.concat().size(), 20); }