Search in sources :

Example 56 with TestObserver

use of io.reactivex.observers.TestObserver in project tutorials by eugenp.

the class OnErrorRetryTest method givenSubscriberAndError_whenRetryWhenOnError_thenResubscribed.

@Test
public void givenSubscriberAndError_whenRetryWhenOnError_thenResubscribed() {
    TestObserver<String> testObserver = new TestObserver<>();
    AtomicInteger atomicCounter = new AtomicInteger(0);
    Observable.<String>error(() -> {
        atomicCounter.incrementAndGet();
        return UNKNOWN_ERROR;
    }).retryWhen(throwableObservable -> Observable.just("anything")).subscribe(testObserver);
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertNoValues();
    assertTrue("should retry once", atomicCounter.get() == 1);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assert.assertTrue(org.junit.Assert.assertTrue) Observable(io.reactivex.Observable) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 57 with TestObserver

use of io.reactivex.observers.TestObserver in project tutorials by eugenp.

the class OnErrorRetryTest method givenSubscriberAndError_whenRetryOnError_thenRetryConfirmed.

@Test
public void givenSubscriberAndError_whenRetryOnError_thenRetryConfirmed() {
    TestObserver<String> testObserver = new TestObserver<>();
    AtomicInteger atomicCounter = new AtomicInteger(0);
    Observable.<String>error(() -> {
        atomicCounter.incrementAndGet();
        return UNKNOWN_ERROR;
    }).retry(1).subscribe(testObserver);
    testObserver.assertError(UNKNOWN_ERROR);
    testObserver.assertNotComplete();
    testObserver.assertNoValues();
    assertTrue("should call twice", atomicCounter.get() == 2);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 58 with TestObserver

use of io.reactivex.observers.TestObserver in project tutorials by eugenp.

the class OnErrorRetryTest method givenSubscriberAndError_whenRetryConditionallyOnError_thenRetryConfirmed.

@Test
public void givenSubscriberAndError_whenRetryConditionallyOnError_thenRetryConfirmed() {
    TestObserver<String> testObserver = new TestObserver<>();
    AtomicInteger atomicCounter = new AtomicInteger(0);
    Observable.<String>error(() -> {
        atomicCounter.incrementAndGet();
        return UNKNOWN_ERROR;
    }).retry((integer, throwable) -> integer < 4).subscribe(testObserver);
    testObserver.assertError(UNKNOWN_ERROR);
    testObserver.assertNotComplete();
    testObserver.assertNoValues();
    assertTrue("should call 4 times", atomicCounter.get() == 4);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assert.assertTrue(org.junit.Assert.assertTrue) Observable(io.reactivex.Observable) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 59 with TestObserver

use of io.reactivex.observers.TestObserver in project tutorials by eugenp.

the class OnErrorRetryTest method givenSubscriberAndError_whenRetryUntilOnError_thenRetryConfirmed.

@Test
public void givenSubscriberAndError_whenRetryUntilOnError_thenRetryConfirmed() {
    TestObserver<String> testObserver = new TestObserver<>();
    AtomicInteger atomicCounter = new AtomicInteger(0);
    Observable.<String>error(UNKNOWN_ERROR).retryUntil(() -> atomicCounter.incrementAndGet() > 3).subscribe(testObserver);
    testObserver.assertError(UNKNOWN_ERROR);
    testObserver.assertNotComplete();
    testObserver.assertNoValues();
    assertTrue("should call 4 times", atomicCounter.get() == 4);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 60 with TestObserver

use of io.reactivex.observers.TestObserver in project reark by reark.

the class GitHubRepositoryStoreCoreTest method getCached_WithNoId_ReturnsAllData_AndCompletes.

// GET ALL CACHED
@Test
public void getCached_WithNoId_ReturnsAllData_AndCompletes() throws InterruptedException {
    // ARRANGE
    final GitHubRepository value1 = create(100, "test name 1");
    final GitHubRepository value2 = create(200, "test name 2");
    final GitHubRepository value3 = create(300, "test name 3");
    TestObserver<List<GitHubRepository>> testObserver = new TestObserver<>();
    // ACT
    gitHubRepositoryStoreCore.put(100, value1);
    gitHubRepositoryStoreCore.put(200, value2);
    Thread.sleep(PROVIDER_WAIT_TIME);
    gitHubRepositoryStoreCore.getCached().subscribe(testObserver);
    gitHubRepositoryStoreCore.put(300, value3);
    // ASSERT
    testObserver.awaitDone(PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS).assertComplete().assertNoErrors().assertValue(asList(value1, value2));
}
Also used : List(java.util.List) Arrays.asList(java.util.Arrays.asList) TestObserver(io.reactivex.observers.TestObserver) GitHubRepository(io.reark.rxgithubapp.shared.pojo.GitHubRepository) 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