Search in sources :

Example 21 with TestSubscriber

use of rx.observers.TestSubscriber 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)

Example 22 with TestSubscriber

use of rx.observers.TestSubscriber in project storio by pushtorefresh.

the class DeleteOperationTest method deleteByQueryExecuteAsBlocking.

@Test
public void deleteByQueryExecuteAsBlocking() {
    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);
    DeleteResult deleteResult = storIOContentResolver.delete().byQuery(DeleteQuery.builder().uri(TestItem.CONTENT_URI).build()).prepare().executeAsBlocking();
    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));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) DeleteResult(com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 23 with TestSubscriber

use of rx.observers.TestSubscriber in project storio by pushtorefresh.

the class DeleteOperationTest method deleteObjectAsSingle.

@Test
public void deleteObjectAsSingle() {
    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<DeleteResult> deleteResult = storIOContentResolver.delete().object(testItem).prepare().asRxSingle().toBlocking();
    assertThat(deleteResult.value().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));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) DeleteResult(com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 24 with TestSubscriber

use of rx.observers.TestSubscriber in project storio by pushtorefresh.

the class DeleteOperationTest method deleteObjectAsCompletable.

@Test
public void deleteObjectAsCompletable() {
    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);
    storIOContentResolver.delete().object(testItem).prepare().asRxCompletable().toObservable().toBlocking().subscribe();
    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) Test(org.junit.Test)

Example 25 with TestSubscriber

use of rx.observers.TestSubscriber in project storio by pushtorefresh.

the class GetOperationTest method getCursorExecuteAsBlocking.

@Test
public void getCursorExecuteAsBlocking() {
    final TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(1).subscribe(changesTestSubscriber);
    TestItem testItemToInsert = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
    Cursor cursor = storIOContentResolver.get().cursor().withQuery(Query.builder().uri(TestItem.CONTENT_URI).build()).prepare().executeAsBlocking();
    Assertions.assertThat(cursor).hasCount(1);
    cursor.moveToFirst();
    assertThat(testItemToInsert.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();
    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) Test(org.junit.Test)

Aggregations

TestSubscriber (rx.observers.TestSubscriber)238 Test (org.junit.Test)213 Intent (android.content.Intent)48 Environment (com.kickstarter.libs.Environment)43 Cursor (android.database.Cursor)36 Changes (com.pushtorefresh.storio.contentresolver.Changes)34 Project (com.kickstarter.models.Project)33 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)21 MockApiClient (com.kickstarter.services.MockApiClient)21 ApiClientType (com.kickstarter.services.ApiClientType)20 TargetApi (android.annotation.TargetApi)18 CurrentUserType (com.kickstarter.libs.CurrentUserType)18 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)18 StorIOException (com.pushtorefresh.storio.StorIOException)17 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)16 Matchers.anyString (org.mockito.Matchers.anyString)16 User (com.kickstarter.models.User)15 PutResult (com.pushtorefresh.storio.contentresolver.operations.put.PutResult)15 Uri (android.net.Uri)14 NonNull (android.support.annotation.NonNull)14