use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableFirstTest method firstOrDefaultWithPredicate.
@Test
public void firstOrDefaultWithPredicate() {
Single<Integer> single = Flowable.just(1, 2, 3, 4, 5, 6).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 % 2 == 0;
}
}).first(8);
single.subscribe(wo);
InOrder inOrder = inOrder(wo);
inOrder.verify(wo, times(1)).onSuccess(2);
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableFirstTest method firstOrDefaultWithPredicateAndOneElement.
@Test
public void firstOrDefaultWithPredicateAndOneElement() {
Single<Integer> single = Flowable.just(1, 2).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 % 2 == 0;
}
}).first(4);
single.subscribe(wo);
InOrder inOrder = inOrder(wo);
inOrder.verify(wo, times(1)).onSuccess(2);
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableConcatMapCompletableTest method immediateOuterInnerErrorRace.
@Test
public void immediateOuterInnerErrorRace() {
final TestException ex = new TestException();
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final CompletableSubject cs = CompletableSubject.create();
TestObserver<Void> to = pp.concatMapCompletable(Functions.justFunction(cs)).test();
pp.onNext(1);
Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
cs.onError(ex);
}
};
TestHelper.race(r1, r2);
to.assertError(new Predicate<Throwable>() {
@Override
public boolean test(Throwable e) throws Exception {
return e instanceof TestException || e instanceof CompositeException;
}
}).assertNotComplete();
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class ObservableAnyTest method predicateThrowsSuppressOthers.
@Test
public void predicateThrowsSuppressOthers() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Observable<Integer>() {
@Override
protected void subscribeActual(Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onNext(1);
observer.onNext(2);
observer.onError(new IOException());
observer.onComplete();
}
}.any(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}).toObservable().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 ObservableTakeUntilPredicateTest method errorIncludesLastValueAsCause.
@Test
public void errorIncludesLastValueAsCause() {
TestObserverEx<String> to = new TestObserverEx<>();
final TestException e = new TestException("Forced failure");
Predicate<String> predicate = (new Predicate<String>() {
@Override
public boolean test(String t) {
throw e;
}
});
Observable.just("abc").takeUntil(predicate).subscribe(to);
to.assertTerminated();
to.assertNotComplete();
to.assertError(TestException.class);
// FIXME last cause value is not saved
// assertTrue(ts.errors().get(0).getCause().getMessage().contains("abc"));
}
Aggregations