DefaultResource implements Resource { @Override public void close() throws IOException { this.object.close(); } 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 closesUnderlyingObject() 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 ObjectMetadata meta = Mockito.mock(ObjectMetadata.class); Mockito.doReturn(meta).when(object).getObjectMetadata(); Mockito.doReturn(1L).when(meta).getContentLength(); new DefaultResource( client, "i", "", Range.ENTIRE, Version.LATEST, Mockito.mock(DomainStatsData.class) ).close(); Mockito.verify(object, Mockito.times(1)).close(); }