DefaultResource implements Resource { @Override public String toString() { return String.format("%s:%s", this.bucket, this.key); } DefaultResource(@NotNull final AmazonS3 clnt,
        @NotNull final String bckt, @NotNull final String name,
        @NotNull final Range rng, @NotNull final Version ver,
        @NotNull final DomainStatsData dstats); @Override String toString(); @Override int status(); @Override @Loggable( value = Loggable.DEBUG, limit = Integer.MAX_VALUE, ignore = DefaultResource.StreamingException.class ) long writeTo(@NotNull final OutputStream output); @Override @NotNull Collection<String> headers(); @Override @NotNull String etag(); @Override Date lastModified(); @Override String contentType(); @Override void close();  }
@Test public void writesFromAmazonObjectToOutputStream() throws Exception { final AmazonS3 client = Mockito.mock(AmazonS3.class); final S3Object object = Mockito.mock(S3Object.class); Mockito.doReturn(object).when(client) .getObject(Mockito.any(GetObjectRequest.class)); final S3ObjectInputStream stream = Mockito.mock(S3ObjectInputStream.class); Mockito.doReturn(-1).when(stream).read(Mockito.any(byte[].class)); Mockito.doReturn(stream).when(object).getObjectContent(); MatcherAssert.assertThat( ResourceMocker.toString( new DefaultResource( client, "b", "", Range.ENTIRE, Version.LATEST, Mockito.mock(DomainStatsData.class) ) ), Matchers.equalTo("") ); }
@Test(expected = IOException.class) public void throwsWhenFailedToRead() throws Exception { final S3ObjectInputStream stream = Mockito.mock(S3ObjectInputStream.class); Mockito.doThrow(new IOException("oops")) .when(stream).read(Mockito.any(byte[].class)); final AmazonS3 client = Mockito.mock(AmazonS3.class); final S3Object object = Mockito.mock(S3Object.class); Mockito.doReturn(object).when(client) .getObject(Mockito.any(GetObjectRequest.class)); Mockito.doReturn(stream).when(object).getObjectContent(); MatcherAssert.assertThat( ResourceMocker.toString( new DefaultResource( client, "d", "", Range.ENTIRE, Version.LATEST, Mockito.mock(DomainStatsData.class) ) ), Matchers.equalTo("") ); }