use of com.amazonaws.mobileconnectors.s3.transferutility.TransferListener in project amplify-android by aws-amplify.
the class StorageComponentTest method testDownloadError.
/**
* Test that calling download file method from Storage category fails
* successfully when {@link TransferListener} emits an error.
*
* @throws IOException when the temporary file cannot be created
*/
@Test
public void testDownloadError() throws IOException {
final StorageException testError = new StorageException("Test error message", "Test recovery message");
final String fromRemoteKey = RandomString.string();
final File toLocalFile = new RandomTempFile();
TransferObserver observer = mock(TransferObserver.class);
when(storageService.downloadToFile(anyString(), any(File.class))).thenReturn(observer);
doAnswer(invocation -> {
TransferListener listener = invocation.getArgument(0);
listener.onError(0, testError);
return null;
}).when(observer).setTransferListener(any(TransferListener.class));
StorageException error = Await.<StorageDownloadFileResult, StorageException>error((onResult, onError) -> storage.downloadFile(fromRemoteKey, toLocalFile, onResult, onError));
assertEquals(testError, error.getCause());
}
Aggregations