Search in sources :

Example 1 with StorIOException

use of com.pushtorefresh.storio3.StorIOException in project storio by pushtorefresh.

the class SingleOnSubscribeExecuteAsBlockingOptionalTest method shouldCallOnErrorIfExceptionOccurred.

@SuppressWarnings("CheckResult")
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
    // noinspection unchecked
    final PreparedOperation<Object, Optional<Object>, Object> preparedOperation = mock(PreparedOperation.class);
    StorIOException expectedException = new StorIOException("test exception");
    when(preparedOperation.executeAsBlocking()).thenThrow(expectedException);
    TestObserver<Optional<Object>> testObserver = new TestObserver<Optional<Object>>();
    Single<Optional<Object>> single = Single.create(new SingleOnSubscribeExecuteAsBlockingOptional<Object, Object>(preparedOperation));
    verifyZeroInteractions(preparedOperation);
    single.subscribe(testObserver);
    testObserver.assertError(expectedException);
    testObserver.assertNotComplete();
    verify(preparedOperation).executeAsBlocking();
}
Also used : Optional(com.pushtorefresh.storio3.Optional) StorIOException(com.pushtorefresh.storio3.StorIOException) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 2 with StorIOException

use of com.pushtorefresh.storio3.StorIOException in project storio by pushtorefresh.

the class MaybeOnSubscribeExecuteAsBlockingTest method shouldCallOnErrorIfExceptionOccurred.

@SuppressWarnings("CheckResult")
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
    // noinspection unchecked
    final PreparedMaybeOperation<Object, Object, Object> preparedOperation = mock(PreparedMaybeOperation.class);
    StorIOException expectedException = new StorIOException("test exception");
    when(preparedOperation.executeAsBlocking()).thenThrow(expectedException);
    TestObserver<Object> testObserver = new TestObserver<Object>();
    Maybe<Object> maybe = Maybe.create(new MaybeOnSubscribeExecuteAsBlocking<Object, Object, Object>(preparedOperation));
    verifyZeroInteractions(preparedOperation);
    maybe.subscribe(testObserver);
    testObserver.assertError(expectedException);
    testObserver.assertNotComplete();
    verify(preparedOperation).executeAsBlocking();
}
Also used : StorIOException(com.pushtorefresh.storio3.StorIOException) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 3 with StorIOException

use of com.pushtorefresh.storio3.StorIOException in project storio by pushtorefresh.

the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForFlowable.

@Test
public void shouldWrapExceptionIntoStorIOExceptionForFlowable() {
    final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
    Uri testUri = mock(Uri.class);
    when(storIOContentResolver.observeChangesOfUri(eq(testUri), eq(BackpressureStrategy.MISSING))).thenReturn(Flowable.<Changes>empty());
    // noinspection unchecked
    final GetResolver<Integer> getResolver = mock(GetResolver.class);
    when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
    final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
    new PreparedGetNumberOfResults.Builder(storIOContentResolver).withQuery(Query.builder().uri(testUri).build()).withGetResolver(getResolver).prepare().asRxFlowable(BackpressureStrategy.MISSING).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(60, SECONDS);
    testSubscriber.assertError(StorIOException.class);
    assertThat(testSubscriber.errors()).hasSize(1);
    StorIOException storIOException = (StorIOException) testSubscriber.errors().get(0);
    IllegalStateException cause = (IllegalStateException) storIOException.getCause();
    assertThat(cause).hasMessage("test exception");
    testSubscriber.dispose();
}
Also used : Query(com.pushtorefresh.storio3.contentresolver.queries.Query) StorIOException(com.pushtorefresh.storio3.StorIOException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) Uri(android.net.Uri) Test(org.junit.Test)

Example 4 with StorIOException

use of com.pushtorefresh.storio3.StorIOException in project storio by pushtorefresh.

the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForSingle.

@Test
public void shouldWrapExceptionIntoStorIOExceptionForSingle() {
    final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
    Uri testUri = mock(Uri.class);
    // noinspection unchecked
    final GetResolver<Integer> getResolver = mock(GetResolver.class);
    when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
    final TestObserver<Integer> testObserver = new TestObserver<Integer>();
    new PreparedGetNumberOfResults.Builder(storIOContentResolver).withQuery(Query.builder().uri(testUri).build()).withGetResolver(getResolver).prepare().asRxSingle().subscribe(testObserver);
    testObserver.awaitTerminalEvent(60, SECONDS);
    testObserver.assertError(StorIOException.class);
    assertThat(testObserver.errors()).hasSize(1);
    StorIOException storIOException = (StorIOException) testObserver.errors().get(0);
    IllegalStateException cause = (IllegalStateException) storIOException.getCause();
    assertThat(cause).hasMessage("test exception");
    testObserver.dispose();
}
Also used : Query(com.pushtorefresh.storio3.contentresolver.queries.Query) StorIOException(com.pushtorefresh.storio3.StorIOException) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) Uri(android.net.Uri) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 5 with StorIOException

use of com.pushtorefresh.storio3.StorIOException in project storio by pushtorefresh.

the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForFlowable.

@Test
public void shouldWrapExceptionIntoStorIOExceptionForFlowable() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    when(storIOSQLite.observeChanges(any(BackpressureStrategy.class))).thenReturn(Flowable.<Changes>empty());
    // noinspection unchecked
    final GetResolver<Integer> getResolver = mock(GetResolver.class);
    when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
    final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
    new PreparedGetNumberOfResults.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").observesTags("test_tag").build()).withGetResolver(getResolver).prepare().asRxFlowable(LATEST).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(60, SECONDS);
    testSubscriber.assertError(StorIOException.class);
    assertThat(testSubscriber.errorCount()).isEqualTo(1);
    StorIOException storIOException = (StorIOException) testSubscriber.errors().get(0);
    IllegalStateException cause = (IllegalStateException) storIOException.getCause();
    assertThat(cause).hasMessage("test exception");
    testSubscriber.dispose();
}
Also used : Query(com.pushtorefresh.storio3.sqlite.queries.Query) StorIOException(com.pushtorefresh.storio3.StorIOException) BackpressureStrategy(io.reactivex.BackpressureStrategy) TestSubscriber(io.reactivex.subscribers.TestSubscriber) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) Test(org.junit.Test)

Aggregations

StorIOException (com.pushtorefresh.storio3.StorIOException)34 Test (org.junit.Test)34 TestObserver (io.reactivex.observers.TestObserver)19 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)18 ContentValues (android.content.ContentValues)14 TestSubscriber (io.reactivex.subscribers.TestSubscriber)9 Query (com.pushtorefresh.storio3.sqlite.queries.Query)6 DeleteQuery (com.pushtorefresh.storio3.sqlite.queries.DeleteQuery)4 Cursor (android.database.Cursor)3 StorIOContentResolver (com.pushtorefresh.storio3.contentresolver.StorIOContentResolver)3 Query (com.pushtorefresh.storio3.contentresolver.queries.Query)3 BackpressureStrategy (io.reactivex.BackpressureStrategy)3 Uri (android.net.Uri)2 Optional (com.pushtorefresh.storio3.Optional)1 PreparedCompletableOperation (com.pushtorefresh.storio3.operations.PreparedCompletableOperation)1 Completable (io.reactivex.Completable)1