Search in sources :

Example 76 with TestObserver

use of io.reactivex.observers.TestObserver in project storio by pushtorefresh.

the class PreparedExecuteSQLTest method shouldWrapExceptionIntoStorIOExceptionCompletable.

@Test
public void shouldWrapExceptionIntoStorIOExceptionCompletable() {
    final Stub stub = Stub.newInstanceApplyNotEmptyAffectedTablesAndTags();
    IllegalStateException testException = new IllegalStateException("test exception");
    doThrow(testException).when(stub.lowLevel).executeSQL(stub.rawQuery);
    final TestObserver<Object> testObserver = new TestObserver<Object>();
    stub.storIOSQLite.executeSQL().withQuery(stub.rawQuery).prepare().asRxCompletable().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(stub.storIOSQLite).executeSQL();
    verify(stub.storIOSQLite).defaultRxScheduler();
    verify(stub.storIOSQLite).lowLevel();
    verify(stub.lowLevel).executeSQL(stub.rawQuery);
    verify(stub.storIOSQLite).interceptors();
    verifyNoMoreInteractions(stub.storIOSQLite, stub.lowLevel);
}
Also used : StorIOException(com.pushtorefresh.storio3.StorIOException) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 77 with TestObserver

use of io.reactivex.observers.TestObserver in project sqlbrite by square.

the class QueryTest method mapToOneOrDefaultReturnsDefaultWhenNullCursor.

@Test
public void mapToOneOrDefaultReturnsDefaultWhenNullCursor() {
    Employee defaultEmployee = new Employee("bob", "Bob Bobberson");
    Query nully = new Query() {

        @Nullable
        @Override
        public Cursor run() {
            return null;
        }
    };
    TestObserver<Employee> observer = new TestObserver<>();
    Observable.just(nully).lift(Query.mapToOneOrDefault(MAPPER, defaultEmployee)).subscribe(observer);
    observer.assertValues(defaultEmployee);
    observer.assertComplete();
}
Also used : Employee(com.squareup.sqlbrite3.TestDb.Employee) Query(com.squareup.sqlbrite3.SqlBrite.Query) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 78 with TestObserver

use of io.reactivex.observers.TestObserver in project sqlbrite by square.

the class QueryTest method mapToListIgnoresNullCursor.

@Test
public void mapToListIgnoresNullCursor() {
    Query nully = new Query() {

        @Nullable
        @Override
        public Cursor run() {
            return null;
        }
    };
    TestObserver<List<Employee>> subscriber = new TestObserver<>();
    Observable.just(nully).lift(Query.mapToList(MAPPER)).subscribe(subscriber);
    subscriber.assertNoValues();
    subscriber.assertComplete();
}
Also used : Query(com.squareup.sqlbrite3.SqlBrite.Query) List(java.util.List) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 79 with TestObserver

use of io.reactivex.observers.TestObserver in project Store by NYTimes.

the class StoreRefreshWhenStaleTest method diskWasNotRefreshedWhenFreshRecord.

@Test
public void diskWasNotRefreshedWhenFreshRecord() {
    when(fetcher.fetch(barCode)).thenReturn(Single.just(network1));
    when(persister.read(barCode)).thenReturn(// get should return from disk
    Maybe.just(disk1)).thenReturn(// backfill should read from disk again
    Maybe.just(disk2));
    when(persister.getRecordState(barCode)).thenReturn(RecordState.FRESH);
    when(persister.write(barCode, network1)).thenReturn(Single.just(true));
    TestObserver testObserver = store.get(barCode).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertNoErrors();
    testObserver.assertResult(disk1);
    verify(fetcher, times(0)).fetch(barCode);
    verify(persister, times(1)).getRecordState(barCode);
    store.clear(barCode);
    testObserver = store.get(barCode).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertResult(disk2);
    verify(fetcher, times(0)).fetch(barCode);
    verify(persister, times(2)).getRecordState(barCode);
}
Also used : TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 80 with TestObserver

use of io.reactivex.observers.TestObserver in project RxCache by VictorAlbertos.

the class ProcessorProvidersTest method When_No_Loader_And_Cache_Expired_But_Use_Expired_Data_If_Loader_Not_Available_Then_Get_Mock.

@Test
public void When_No_Loader_And_Cache_Expired_But_Use_Expired_Data_If_Loader_Not_Available_Then_Get_Mock() {
    processorProvidersUT = new io.rx_cache2.internal.ProcessorProvidersBehaviour(twoLayersCacheMock, false, evictExpiredRecordsPersistence, getDeepCopy, doMigrations);
    TestObserver observerMock = getSubscriberCompleted(true, true, false, Loader.NULL, true);
    assertThat(observerMock.errorCount(), is(0));
    assertThat(observerMock.valueCount(), is(1));
}
Also used : TestObserver(io.reactivex.observers.TestObserver) BaseTest(io.rx_cache2.internal.common.BaseTest) Test(org.junit.Test)

Aggregations

TestObserver (io.reactivex.observers.TestObserver)158 Test (org.junit.Test)128 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)31 TargetApi (android.annotation.TargetApi)21 Matchers.anyString (org.mockito.Matchers.anyString)21 StorIOException (com.pushtorefresh.storio3.StorIOException)19 TestException (io.reactivex.exceptions.TestException)19 Observable (io.reactivex.Observable)12 BaseTest (io.rx_cache2.internal.common.BaseTest)12 Completable (io.reactivex.Completable)11 Disposable (io.reactivex.disposables.Disposable)11 InOrder (org.mockito.InOrder)10 TestScheduler (io.reactivex.schedulers.TestScheduler)9 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)8 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)7 Schedulers (io.reactivex.schedulers.Schedulers)6 Activity (android.app.Activity)5 Instrumentation (android.app.Instrumentation)5 ContentValues (android.content.ContentValues)5 Context (android.content.Context)5