@Test
public void awaitCompletion() {

    UploadPartRequest request1 = UploadPartRequest.builder().uploadPartNum(1).build();
    UploadPartRequest request2 = UploadPartRequest.builder().uploadPartNum(2).build();
    final UploadPartResponse response1 = UploadPartResponse.builder().build();
    when(service.uploadPart(request1))
            .thenAnswer(
                    new Answer<UploadPartResponse>() {
                        @Override
                        public UploadPartResponse answer(InvocationOnMock arg0)
                                throws Throwable {
                            // long enough to test 'inprogress'
                            Thread.sleep(10000L);
                            return response1;
                        }
                    });
    when(service.uploadPart(request2)).thenThrow(new RuntimeException());
    manager.startTransfer(request1);
    manager.startTransfer(request2);
    List<Integer> inProgressParts = manifest.listInProgressParts();
    // serial executor, first one sleeps 10s, so both tasks will be in
    // progress
    assertEquals(2, inProgressParts.size());
    assertEquals(1, inProgressParts.get(0).intValue());
    assertEquals(2, inProgressParts.get(1).intValue());
    manager.awaitCompletion();
    List<CommitMultipartUploadPartDetails> successfulParts = manifest.listCompletedParts();
    assertEquals(1, successfulParts.size());
    assertEquals(1, successfulParts.get(0).getPartNum().intValue());
    List<Integer> failedParts = manifest.listFailedParts();
    assertEquals(1, failedParts.size());
    assertEquals(2, failedParts.get(0).intValue());
    assertTrue(manifest.listInProgressParts().isEmpty());
}