Search in sources :

Example 1 with Observer

use of io.reactivex.Observer in project RxJava by ReactiveX.

the class FlowableElementAtTest method badSourceObservable.

@Test
public void badSourceObservable() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposables.empty());
                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }.elementAt(0).toFlowable().test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) Observer(io.reactivex.Observer) Observable(io.reactivex.Observable)

Example 2 with Observer

use of io.reactivex.Observer in project RxJava by ReactiveX.

the class BlockingObservableLatestTest method onError.

@SuppressWarnings("unchecked")
@Test
public void onError() {
    Iterator<Object> it = Observable.never().blockingLatest().iterator();
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        ((Observer<Object>) it).onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) Observer(io.reactivex.Observer)

Example 3 with Observer

use of io.reactivex.Observer in project RxJava by ReactiveX.

the class ObservableCacheTest method testCache.

@Test
public void testCache() throws InterruptedException {
    final AtomicInteger counter = new AtomicInteger();
    Observable<String> o = Observable.unsafeCreate(new ObservableSource<String>() {

        @Override
        public void subscribe(final Observer<? super String> observer) {
            observer.onSubscribe(Disposables.empty());
            new Thread(new Runnable() {

                @Override
                public void run() {
                    counter.incrementAndGet();
                    System.out.println("published Observable being executed");
                    observer.onNext("one");
                    observer.onComplete();
                }
            }).start();
        }
    }).cache();
    // we then expect the following 2 subscriptions to get that same value
    final CountDownLatch latch = new CountDownLatch(2);
    // subscribe once
    o.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            System.out.println("v: " + v);
            latch.countDown();
        }
    });
    // subscribe again
    o.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            System.out.println("v: " + v);
            latch.countDown();
        }
    });
    if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
        fail("subscriptions did not receive values");
    }
    assertEquals(1, counter.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.observers.TestObserver) Observer(io.reactivex.Observer)

Example 4 with Observer

use of io.reactivex.Observer in project RxJava by ReactiveX.

the class ObservablePublishTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposables.empty());
                observer.onNext(1);
                observer.onComplete();
                observer.onNext(2);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }.publish().autoConnect().test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) TestObserver(io.reactivex.observers.TestObserver) Observer(io.reactivex.Observer) ConnectableObservable(io.reactivex.observables.ConnectableObservable) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 5 with Observer

use of io.reactivex.Observer in project RxJava by ReactiveX.

the class ObservableReplayTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposables.empty());
                observer.onError(new TestException("First"));
                observer.onNext(1);
                observer.onError(new TestException("Second"));
                observer.onComplete();
            }
        }.replay().autoConnect().test().assertFailureAndMessage(TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.exceptions.TestException) TestObserver(io.reactivex.observers.TestObserver) Observer(io.reactivex.Observer) ConnectableObservable(io.reactivex.observables.ConnectableObservable) Observable(io.reactivex.Observable)

Aggregations

Observer (io.reactivex.Observer)18 Observable (io.reactivex.Observable)12 Test (org.junit.Test)9 TestException (io.reactivex.exceptions.TestException)8 TestObserver (io.reactivex.observers.TestObserver)6 ConnectableObservable (io.reactivex.observables.ConnectableObservable)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Bundle (android.os.Bundle)2 Log (android.util.Log)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Disposable (io.reactivex.disposables.Disposable)2 ObserveOnObserver (io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver)2 Schedulers (io.reactivex.schedulers.Schedulers)2 TimeUnit (java.util.concurrent.TimeUnit)2 Inject (javax.inject.Inject)2 UserPrivate (kaaes.spotify.webapi.android.models.UserPrivate)2 Callback (retrofit.Callback)2 RetrofitError (retrofit.RetrofitError)2 Response (retrofit.client.Response)2 ApplicationConstants (se.zinokader.spotiq.constant.ApplicationConstants)2