use of io.reactivex.functions.Function in project RxJava by ReactiveX.
the class ObservableTimeoutWithSelectorTest method testTimeoutSelectorFirstObservableThrows.
@Test
public void testTimeoutSelectorFirstObservableThrows() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> timeout = PublishSubject.create();
Function<Integer, Observable<Integer>> timeoutFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return timeout;
}
};
Observable<Integer> other = Observable.fromIterable(Arrays.asList(100));
Observer<Object> o = TestHelper.mockObserver();
source.timeout(Observable.<Integer>error(new TestException()), timeoutFunc, other).subscribe(o);
verify(o).onError(any(TestException.class));
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.functions.Function in project RxJava by ReactiveX.
the class ObservableSwitchTest method switchMapSingleDelayErrorJustSource.
@Test
public void switchMapSingleDelayErrorJustSource() {
final AtomicBoolean completed = new AtomicBoolean();
Observable.just(0, 1).switchMapSingleDelayError(new Function<Integer, SingleSource<Integer>>() {
@Override
public SingleSource<Integer> apply(Integer v) throws Exception {
if (v == 0) {
return Single.error(new RuntimeException());
} else {
return Single.just(1).doOnSuccess(new Consumer<Integer>() {
@Override
public void accept(Integer n) throws Exception {
completed.set(true);
}
});
}
}
}).test().assertValue(1).assertError(RuntimeException.class);
assertTrue(completed.get());
}
use of io.reactivex.functions.Function in project RxJava by ReactiveX.
the class BehaviorProcessorTest method testUnsubscriptionCase.
@Test(timeout = 1000)
public void testUnsubscriptionCase() {
// FIXME was plain null which is not allowed
BehaviorProcessor<String> src = BehaviorProcessor.createDefault("null");
for (int i = 0; i < 10; i++) {
final Subscriber<Object> o = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(o);
String v = "" + i;
src.onNext(v);
System.out.printf("Turn: %d%n", i);
src.firstElement().toFlowable().flatMap(new Function<String, Flowable<String>>() {
@Override
public Flowable<String> apply(String t1) {
return Flowable.just(t1 + ", " + t1);
}
}).subscribe(new DefaultSubscriber<String>() {
@Override
public void onNext(String t) {
o.onNext(t);
}
@Override
public void onError(Throwable e) {
o.onError(e);
}
@Override
public void onComplete() {
o.onComplete();
}
});
inOrder.verify(o).onNext(v + ", " + v);
inOrder.verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
}
use of io.reactivex.functions.Function in project requery by requery.
the class ReactiveTest method testInsertOneToMany.
@Test
public void testInsertOneToMany() throws Exception {
final Person person = randomPerson();
data.insert(person).map(new Function<Person, Phone>() {
@Override
public Phone apply(Person person) {
Phone phone1 = randomPhone();
phone1.setOwner(person);
return phone1;
}
}).flatMap(new Function<Phone, Single<?>>() {
@Override
public Single<?> apply(Phone phone) {
return data.insert(phone);
}
}).blockingGet();
assertTrue(person.getPhoneNumbers().toList().size() == 1);
}
use of io.reactivex.functions.Function in project requery by requery.
the class ReactiveTest method testQuerySelfObservableMap.
@Test
public void testQuerySelfObservableMap() throws Exception {
final AtomicInteger count = new AtomicInteger();
Disposable disposable = data.select(Person.class).limit(2).get().observableResult().flatMap(new Function<ReactiveResult<Person>, Observable<Person>>() {
@Override
public Observable<Person> apply(ReactiveResult<Person> persons) {
return persons.observable();
}
}).subscribe(new Consumer<Person>() {
@Override
public void accept(Person persons) {
count.incrementAndGet();
}
});
data.insert(randomPerson()).blockingGet();
data.insert(randomPerson()).blockingGet();
assertEquals(3, count.get());
disposable.dispose();
}
Aggregations