use of com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.
the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionFlowable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionFlowable() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
// noinspection unchecked
final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
when(deleteResolver.performDelete(same(storIOSQLite), any(DeleteQuery.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<DeleteResult> testSubscriber = new TestSubscriber<DeleteResult>();
new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).prepare().asRxFlowable(MISSING).subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertNoValues();
testSubscriber.assertError(StorIOException.class);
// noinspection ThrowableResultOfMethodCallIgnored
StorIOException expected = (StorIOException) testSubscriber.errors().get(0);
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
verify(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
verify(storIOSQLite).defaultRxScheduler();
verify(storIOSQLite).interceptors();
verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
}
use of com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.
the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionSingle.
@Test
public void shouldWrapExceptionIntoStorIOExceptionSingle() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
// noinspection unchecked
final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
when(deleteResolver.performDelete(same(storIOSQLite), any(DeleteQuery.class))).thenThrow(new IllegalStateException("test exception"));
final TestObserver<DeleteResult> testObserver = new TestObserver<DeleteResult>();
new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).prepare().asRxSingle().subscribe(testObserver);
testObserver.awaitTerminalEvent();
testObserver.assertNoValues();
testObserver.assertError(StorIOException.class);
// noinspection ThrowableResultOfMethodCallIgnored
StorIOException expected = (StorIOException) testObserver.errors().get(0);
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
verify(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
verify(storIOSQLite).defaultRxScheduler();
verify(storIOSQLite).interceptors();
verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
}
use of com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.
the class DeleteOperationTest method deleteByQueryAsRxFlowable.
@Test
public void deleteByQueryAsRxFlowable() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(2).subscribe(changesTestSubscriber);
TestItem testItemToInsert = TestItem.create(null, "value");
contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
Cursor firstDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(firstDbState).hasCount(1);
DeleteResult deleteResult = storIOContentResolver.delete().byQuery(DeleteQuery.builder().uri(TestItem.CONTENT_URI).build()).prepare().asRxFlowable(BackpressureStrategy.MISSING).blockingFirst();
assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
Cursor secondDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(secondDbState).hasCount(0);
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValues(Changes.newInstance(TestItem.CONTENT_URI), Changes.newInstance(TestItem.CONTENT_URI));
}
use of com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.
the class DeleteOperationTest method deleteObjectAsRxFlowable.
@Test
public void deleteObjectAsRxFlowable() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(2).subscribe(changesTestSubscriber);
TestItem testItemToInsert = TestItem.create(null, "value");
contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
Cursor firstDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(firstDbState).hasCount(1);
// noinspection ConstantConditions
assertThat(firstDbState.moveToFirst()).isTrue();
TestItem testItem = TestItem.fromCursor(firstDbState);
DeleteResult deleteResult = storIOContentResolver.delete().object(testItem).prepare().asRxFlowable(BackpressureStrategy.MISSING).blockingFirst();
assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
Cursor secondDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(secondDbState).hasCount(0);
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValues(Changes.newInstance(TestItem.CONTENT_URI), Changes.newInstance(TestItem.CONTENT_URI));
}
use of com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.
the class DefaultDeleteResolver method performDelete.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public DeleteResult performDelete(@NonNull StorIOContentResolver storIOContentResolver, @NonNull T object) {
final DeleteQuery deleteQuery = mapToDeleteQuery(object);
final int numberOfRowsDeleted = storIOContentResolver.lowLevel().delete(deleteQuery);
return DeleteResult.newInstance(numberOfRowsDeleted, deleteQuery.uri());
}
Aggregations