use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class ObservableFirstTest method firstOrDefaultWithPredicateAndOneElement.
@Test
public void firstOrDefaultWithPredicateAndOneElement() {
Single<Integer> o = Observable.just(1, 2).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 % 2 == 0;
}
}).first(4);
o.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 ObservableFirstTest method firstWithPredicate.
@Test
public void firstWithPredicate() {
Maybe<Integer> o = Observable.just(1, 2, 3, 4, 5, 6).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)).onSuccess(2);
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableFilterTest method withBackpressure2.
/**
* Make sure we are adjusting subscriber.request() for filtered items.
* @throws InterruptedException if the test is interrupted
*/
@Test
public void withBackpressure2() throws InterruptedException {
Flowable<Integer> w = Flowable.range(1, Flowable.bufferSize() * 2);
Flowable<Integer> f = w.filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 > 100;
}
});
final CountDownLatch latch = new CountDownLatch(1);
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onComplete() {
System.out.println("onComplete");
latch.countDown();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
latch.countDown();
}
@Override
public void onNext(Integer t) {
System.out.println("Received: " + t);
// request more each time we receive
request(1);
}
};
// this means it will only request 1 item and expect to receive more
ts.request(1);
f.subscribe(ts);
// this will wait forever unless OperatorTake handles the request(n) on filtered items
latch.await();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableFilterTest method withBackpressure.
/**
* Make sure we are adjusting subscriber.request() for filtered items.
* @throws InterruptedException if the test is interrupted
* @throws InterruptedException if the test is interrupted
*/
@Test
public void withBackpressure() throws InterruptedException {
Flowable<String> w = Flowable.just("one", "two", "three");
Flowable<String> f = w.filter(new Predicate<String>() {
@Override
public boolean test(String t1) {
return t1.equals("three");
}
});
final CountDownLatch latch = new CountDownLatch(1);
TestSubscriber<String> ts = new TestSubscriber<String>() {
@Override
public void onComplete() {
System.out.println("onComplete");
latch.countDown();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
latch.countDown();
}
@Override
public void onNext(String t) {
System.out.println("Received: " + t);
// request more each time we receive
request(1);
}
};
// this means it will only request "one" and "two", expecting to receive them before requesting more
ts.request(2);
f.subscribe(ts);
// this will wait forever unless OperatorTake handles the request(n) on filtered items
latch.await();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableMapTest method mapFilterMapperCrashFused.
@Test
public void mapFilterMapperCrashFused() {
TestSubscriberEx<Integer> ts = new TestSubscriberEx<Integer>().setInitialFusionMode(QueueFuseable.ANY);
Flowable.range(1, 2).hide().map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
throw new TestException();
}
}).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
return true;
}
}).subscribe(ts);
ts.assertFuseable().assertFusionMode(QueueFuseable.NONE).assertFailure(TestException.class);
}
Aggregations