use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class MaybeRetryTest method retryTimesPredicateWithMatchingPredicate.
@Test
public void retryTimesPredicateWithMatchingPredicate() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
Maybe.fromCallable(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}
throw new IllegalArgumentException();
}
}).retry(Integer.MAX_VALUE, new Predicate<Throwable>() {
@Override
public boolean test(final Throwable throwable) throws Exception {
return !(throwable instanceof IllegalArgumentException);
}
}).test().assertFailure(IllegalArgumentException.class);
assertEquals(3, numberOfSubscribeCalls.get());
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableFilterTest method sourceIgnoresCancel.
@Test
public void sourceIgnoresCancel() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
}).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableAllTest method predicateThrowsObservable.
@Test
public void predicateThrowsObservable() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onNext(1);
subscriber.onNext(2);
subscriber.onError(new TestException());
subscriber.onComplete();
}
}.all(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}).toFlowable().test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableAnyTest method predicateThrowsSuppressOthers.
@Test
public void predicateThrowsSuppressOthers() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onNext(1);
subscriber.onNext(2);
subscriber.onError(new IOException());
subscriber.onComplete();
}
}.any(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}).toFlowable().test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableFirstTest method firstWithPredicateAndOneElement.
@Test
public void firstWithPredicateAndOneElement() {
Maybe<Integer> maybe = Flowable.just(1, 2).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 % 2 == 0;
}
}).firstElement();
maybe.subscribe(wm);
InOrder inOrder = inOrder(wm);
inOrder.verify(wm, times(1)).onSuccess(2);
inOrder.verifyNoMoreInteractions();
}
Aggregations