Search in sources :

Example 1 with GroupedObservable

use of io.reactivex.rxjava3.observables.GroupedObservable in project RxJava by ReactiveX.

the class ObservableGroupByTest method newGroupValueSelectorFails.

@Test
public void newGroupValueSelectorFails() {
    TestObserver<Object> to1 = new TestObserver<>();
    final TestObserver<Object> to2 = new TestObserver<>();
    Observable.just(1).groupBy(Functions.<Integer>identity(), new Function<Integer, Object>() {

        @Override
        public Object apply(Integer v) throws Throwable {
            throw new TestException();
        }
    }).doOnNext(new Consumer<GroupedObservable<Integer, Object>>() {

        @Override
        public void accept(GroupedObservable<Integer, Object> g) throws Throwable {
            g.subscribe(to2);
        }
    }).subscribe(to1);
    to1.assertValueCount(1).assertError(TestException.class).assertNotComplete();
    to2.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) GroupedObservable(io.reactivex.rxjava3.observables.GroupedObservable) Test(org.junit.Test)

Example 2 with GroupedObservable

use of io.reactivex.rxjava3.observables.GroupedObservable in project RxJava by ReactiveX.

the class ObservableGroupByTest method existingGroupValueSelectorFails.

@Test
public void existingGroupValueSelectorFails() {
    TestObserver<Object> to1 = new TestObserver<>();
    final TestObserver<Object> to2 = new TestObserver<>();
    Observable.just(1, 2).groupBy(Functions.justFunction(1), new Function<Integer, Object>() {

        @Override
        public Object apply(Integer v) throws Throwable {
            if (v == 2) {
                throw new TestException();
            }
            return v;
        }
    }).doOnNext(new Consumer<GroupedObservable<Integer, Object>>() {

        @Override
        public void accept(GroupedObservable<Integer, Object> g) throws Throwable {
            g.subscribe(to2);
        }
    }).subscribe(to1);
    to1.assertValueCount(1).assertError(TestException.class).assertNotComplete();
    to2.assertFailure(TestException.class, 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) GroupedObservable(io.reactivex.rxjava3.observables.GroupedObservable) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)2 GroupedObservable (io.reactivex.rxjava3.observables.GroupedObservable)2 Test (org.junit.Test)2