use of com.amplifyframework.storage.options.StorageGetUrlOptions in project amplify-android by aws-amplify.
the class RxStorageBindingTest method getUrlEmitsFailure.
/**
* When the delegate emits a failure from the
* {@link StorageCategoryBehavior#getUrl(String, StorageGetUrlOptions, Consumer, Consumer)},
* the binding should emit a failure to its single observer.
*/
@Test
public void getUrlEmitsFailure() {
StorageException expectedException = new StorageException("oh", "boy!");
doAnswer(invocation -> {
int indexOfErrorConsumer = 3;
Consumer<StorageException> onError = invocation.getArgument(indexOfErrorConsumer);
onError.accept(expectedException);
return mock(StorageGetUrlOperation.class);
}).when(delegate).getUrl(eq(remoteKey), any(StorageGetUrlOptions.class), anyConsumer(), anyConsumer());
rxStorage.getUrl(remoteKey, StorageGetUrlOptions.defaultInstance()).test().awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS).assertError(expectedException);
}
use of com.amplifyframework.storage.options.StorageGetUrlOptions in project amplify-android by aws-amplify.
the class RxStorageBindingTest method getUrlReturnsResult.
/**
* When the delegate returns a result from the
* {@link StorageCategoryBehavior#getUrl(String, StorageGetUrlOptions, Consumer, Consumer)},
* the binding should emit the result via the single.
* @throws MalformedURLException Not expected; it's part of the URL constructor signature, though
*/
@Test
public void getUrlReturnsResult() throws MalformedURLException {
URL someRandomUrl = new URL("https://bogus.tld/foo");
StorageGetUrlResult expectedResult = StorageGetUrlResult.fromUrl(someRandomUrl);
doAnswer(invocation -> {
int indexOfResultConsumer = 2;
Consumer<StorageGetUrlResult> onResult = invocation.getArgument(indexOfResultConsumer);
onResult.accept(expectedResult);
return mock(StorageGetUrlOperation.class);
}).when(delegate).getUrl(eq(remoteKey), any(StorageGetUrlOptions.class), anyConsumer(), anyConsumer());
rxStorage.getUrl(remoteKey, StorageGetUrlOptions.defaultInstance()).test().awaitCount(1).assertNoErrors().assertValue(expectedResult);
}
Aggregations