### Question:
S3Link { public ObjectMetadata downloadTo(final File destination) { return downloadTo(destination, null); } S3Link(S3ClientCache s3cc, String bucketName, String key);   S3Link(S3ClientCache s3cc, Region region, String bucketName, String key); private  S3Link(S3ClientCache s3cc, ID id); String getKey(); String getBucketName(); Region getS3Region(); String toJson(); static S3Link fromJson(S3ClientCache s3cc, String json); AmazonS3Client getAmazonS3Client(); TransferManager getTransferManager(); PutObjectResult uploadFrom(final File source); PutObjectResult uploadFrom(final File source,
            RequestMetricCollector requestMetricCollector); PutObjectResult uploadFrom(final byte[] buffer); PutObjectResult uploadFrom(final byte[] buffer,
            RequestMetricCollector requestMetricCollector); void setAcl(CannedAccessControlList acl); void setAcl(CannedAccessControlList acl, RequestMetricCollector col); void setAcl(AccessControlList acl); void setAcl(AccessControlList acl,
            RequestMetricCollector requestMetricCollector); URL getUrl(); ObjectMetadata downloadTo(final File destination); ObjectMetadata downloadTo(final File destination,
            RequestMetricCollector requestMetricCollector); ObjectMetadata downloadTo(final OutputStream output); ObjectMetadata downloadTo(final OutputStream output,
            RequestMetricCollector requestMetricCollector);  }### Answer:
@Test public void testDownloadToOutstream() { EasyMock.reset(mockS3); EasyMock.expect(mockS3.getRegion()).andReturn(Region.US_Standard); byte[] mockResponseBytes = "MyData".getBytes(StringUtils.UTF8); ByteArrayOutputStream bos = new ByteArrayOutputStream(); S3Object mockObj = EasyMock.createMock(S3Object.class); ByteArrayInputStream bis = new ByteArrayInputStream(mockResponseBytes); S3ObjectInputStream s3is = new S3ObjectInputStream(bis); EasyMock.expect(mockS3.getObject(anyObject(GetObjectRequest.class))).andReturn(mockObj); EasyMock.expect(mockObj.getObjectContent()).andReturn(s3is); EasyMock.expect(mockObj.getObjectMetadata()).andReturn(new ObjectMetadata()); EasyMock.replay(mockS3, mockObj); mapper.getS3ClientCache().useClient(mockS3); S3Link link = mapper.createS3Link(bucket, key); link.downloadTo(bos); EasyMock.verify(mockS3, mockObj); assertArrayEquals(mockResponseBytes, bos.toByteArray()); }
@Test public void testDownloadToFile() throws IOException { EasyMock.reset(mockS3); EasyMock.expect(mockS3.getRegion()).andReturn(Region.US_Standard); File testFile = new File("S3LinkTest"); if (testFile.exists()) { assertTrue(testFile.delete()); } assertTrue(testFile.createNewFile()); S3Object mockObj = EasyMock.createMock(S3Object.class); EasyMock.expect(mockS3.getObject(anyObject(GetObjectRequest.class), eq(testFile))) .andReturn(null); EasyMock.replay(mockS3, mockObj); mapper.getS3ClientCache().useClient(mockS3); S3Link link = mapper.createS3Link(bucket, key); link.downloadTo(testFile); EasyMock.verify(mockS3, mockObj); assertTrue(testFile.delete()); }