### Question:
S3Link { public PutObjectResult uploadFrom(final File source) { return uploadFrom(source, 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 testUploadFromByteArray() throws IOException { EasyMock.reset(mockS3); EasyMock.expect(mockS3.getRegion()).andReturn(Region.US_Standard); Capture<PutObjectRequest> por = new Capture<PutObjectRequest>(); EasyMock.expect(mockS3.putObject(EasyMock.capture(por))).andReturn(null); EasyMock.replay(mockS3); mapper.getS3ClientCache().useClient(mockS3); S3Link link = mapper.createS3Link(bucket, key); link.uploadFrom("Test".getBytes(StringUtils.UTF8)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); InputStream is = por.getValue().getInputStream(); int currByte = -1; while ((currByte = is.read()) != -1) { bos.write(currByte); } assertArrayEquals(bos.toByteArray(), "Test".getBytes(StringUtils.UTF8)); EasyMock.verify(); }
@Test public void testUploadFromFile() throws IOException { EasyMock.reset(mockS3); EasyMock.expect(mockS3.getRegion()).andReturn(Region.US_Standard); Capture<PutObjectRequest> por = new Capture<PutObjectRequest>(); EasyMock.expect(mockS3.putObject(EasyMock.capture(por))).andReturn(null); EasyMock.replay(mockS3); mapper.getS3ClientCache().useClient(mockS3); S3Link link = mapper.createS3Link(bucket, key); File temp = new File("testUpload"); if (temp.exists()) { assertTrue(temp.delete()); } temp.createNewFile(); FileOutputStream fos = new FileOutputStream(temp); fos.write("Test".getBytes(StringUtils.UTF8)); fos.close(); link.uploadFrom(temp); File sent = por.getValue().getFile(); assertEquals(temp, sent); assertTrue(temp.delete()); EasyMock.verify(); }