use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRepeatWhen.
@Test
public void noCancelPreviousRepeatWhen() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> get() throws Exception {
if (times.get() < 4) {
return Observable.error(new TestException());
}
return Observable.just(1);
}
}).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retryWhen(new Function<Observable<Throwable>, ObservableSource<?>>() {
@Override
public ObservableSource<?> apply(Observable<Throwable> e) throws Exception {
return e.takeWhile(new Predicate<Object>() {
@Override
public boolean test(Object v) throws Exception {
return times.getAndIncrement() < 4;
}
});
}
}).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class TestObserverExTest method errorInPredicate.
@Test
public void errorInPredicate() {
TestObserverEx<Object> to = new TestObserverEx<>();
to.onError(new RuntimeException());
try {
to.assertError(new Predicate<Throwable>() {
@Override
public boolean test(Throwable throwable) throws Exception {
throw new TestException();
}
});
} catch (TestException ex) {
// expected
return;
}
fail("Error in predicate but not thrown!");
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class ObservableFirstTest method firstWithPredicateAndEmpty.
@Test
public void firstWithPredicateAndEmpty() {
Maybe<Integer> o = Observable.just(1).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 % 2 == 0;
}
}).firstElement();
o.subscribe(wm);
InOrder inOrder = inOrder(wm);
inOrder.verify(wm, times(1)).onComplete();
inOrder.verify(wm, never()).onError(any(Throwable.class));
inOrder.verifyNoMoreInteractions();
}
Aggregations