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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations