Search in sources :

Example 1 with StorageRemoveResult

use of com.amplifyframework.storage.result.StorageRemoveResult in project amplify-android by aws-amplify.

the class StorageComponentTest method testRemoveObjectGetsKey.

/**
 * Test that calling remove method from Storage category correctly
 * invokes the registered AWSS3StoragePlugin instance and returns a
 * {@link StorageRemoveResult} with key of removed item.
 *
 * @throws StorageException when an error is encountered while deleting
 *                          file from storage
 */
@Test
public void testRemoveObjectGetsKey() throws StorageException {
    final String remoteKey = RandomString.string();
    StorageRemoveResult result = Await.<StorageRemoveResult, StorageException>result((onResult, onError) -> storage.remove(remoteKey, onResult, onError));
    assertEquals(remoteKey, result.getKey());
}
Also used : StorageRemoveResult(com.amplifyframework.storage.result.StorageRemoveResult) Mockito.anyString(org.mockito.Mockito.anyString) RandomString(com.amplifyframework.testutils.random.RandomString) StorageException(com.amplifyframework.storage.StorageException) Test(org.junit.Test)

Example 2 with StorageRemoveResult

use of com.amplifyframework.storage.result.StorageRemoveResult in project amplify-android by aws-amplify.

the class RxStorageBindingTest method removeReturnsResult.

/**
 * When the {@link StorageCategoryBehavior#remove(String, Consumer, Consumer)} emits
 * a result, the {@link Single} returned by {@link RxStorageCategoryBehavior#remove(String)} should
 * emit a {@link StorageRemoveResult}.
 */
@Test
public void removeReturnsResult() {
    StorageRemoveResult result = StorageRemoveResult.fromKey(remoteKey);
    doAnswer(invocation -> {
        // 0 remoteKey, 1 onResult, 2 onError
        final int indexOfResultConsumer = 1;
        Consumer<StorageRemoveResult> resultConsumer = invocation.getArgument(indexOfResultConsumer);
        resultConsumer.accept(result);
        return mock(StorageRemoveOperation.class);
    }).when(delegate).remove(eq(remoteKey), anyConsumer(), anyConsumer());
    rxStorage.remove(remoteKey).test().assertValues(result);
}
Also used : StorageRemoveResult(com.amplifyframework.storage.result.StorageRemoveResult) Test(org.junit.Test)

Aggregations

StorageRemoveResult (com.amplifyframework.storage.result.StorageRemoveResult)2 Test (org.junit.Test)2 StorageException (com.amplifyframework.storage.StorageException)1 RandomString (com.amplifyframework.testutils.random.RandomString)1 Mockito.anyString (org.mockito.Mockito.anyString)1