S3MultipartUpload { PartETag upload(String uploadId, S3Part part) { Object[] logParams = new Object[] { part.getSize(), part.getNumber(), bucket, key }; log.debug("Uploading {} bytes for part {} to s3: UploadPartRequest request = new UploadPartRequest() .withUploadId(uploadId) .withBucketName(bucket) .withKey(key) .withPartNumber(part.getNumber()) .withPartSize(part.getSize()) .withMD5Digest(part.getMd5()) .withInputStream(part.getInputStream()); UploadPartResult result = s3.uploadPart(request); log.debug("Uploaded {} bytes for part {} to s3: bytes += part.getSize(); return result.getPartETag(); }    }
@Test public void upload() { ArgumentCaptor<UploadPartRequest> request = ArgumentCaptor.forClass(UploadPartRequest.class); UploadPartResult response = mock(UploadPartResult.class); PartETag partETag = mock(PartETag.class); when(response.getPartETag()).thenReturn(partETag); when(s3.uploadPart(request.capture())).thenReturn(response); InputStream inputStream = mock(InputStream.class); S3Part part = new S3Part(1, 2, "md5", inputStream); PartETag result = underTest.upload(UPLOAD_ID, part); assertThat(result, is(partETag)); assertThat(request.getValue().getBucketName(), is(BUCKET)); assertThat(request.getValue().getKey(), is(KEY)); assertThat(request.getValue().getPartNumber(), is(1)); assertThat(request.getValue().getPartSize(), is(2L)); assertThat(request.getValue().getMd5Digest(), is("md5")); assertThat(request.getValue().getInputStream(), is(inputStream)); }