use of io.reactivex.rxjava3.subjects in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableReorder.
@Test
public void delayWithObservableReorder() {
int n = 3;
PublishSubject<Integer> source = PublishSubject.create();
final List<PublishSubject<Integer>> subjects = new ArrayList<>();
for (int i = 0; i < n; i++) {
subjects.add(PublishSubject.<Integer>create());
}
Observable<Integer> result = source.delay(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return subjects.get(t1);
}
});
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
result.subscribe(o);
for (int i = 0; i < n; i++) {
source.onNext(i);
}
source.onComplete();
inOrder.verify(o, never()).onNext(anyInt());
inOrder.verify(o, never()).onComplete();
for (int i = n - 1; i >= 0; i--) {
subjects.get(i).onComplete();
inOrder.verify(o).onNext(i);
}
inOrder.verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
Aggregations