Search in sources :

Example 1 with DeleteResults

use of com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResults in project storio by pushtorefresh.

the class DeleteOperationTest method deleteObjectsAsSingle.

@Test
public void deleteObjectsAsSingle() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).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);
    BlockingSingle<DeleteResults<TestItem>> deleteResults = storIOContentResolver.delete().objects(singletonList(testItem)).prepare().asRxSingle().toBlocking();
    assertThat(deleteResults.value().wasDeleted(testItem)).isTrue();
    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));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) DeleteResults(com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResults) Test(org.junit.Test)

Aggregations

Cursor (android.database.Cursor)1 Changes (com.pushtorefresh.storio.contentresolver.Changes)1 DeleteResults (com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResults)1 Test (org.junit.Test)1 TestSubscriber (rx.observers.TestSubscriber)1