use of io.reactivex.observables.ConnectableObservable in project RxJava by ReactiveX.
the class RxJavaPluginsTest method clearIsPassthrough.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void clearIsPassthrough() {
try {
RxJavaPlugins.reset();
assertNull(RxJavaPlugins.onAssembly((Observable) null));
assertNull(RxJavaPlugins.onAssembly((ConnectableObservable) null));
assertNull(RxJavaPlugins.onAssembly((Flowable) null));
assertNull(RxJavaPlugins.onAssembly((ConnectableFlowable) null));
Observable oos = new Observable() {
@Override
public void subscribeActual(Observer t) {
}
};
Flowable fos = new Flowable() {
@Override
public void subscribeActual(Subscriber t) {
}
};
assertSame(oos, RxJavaPlugins.onAssembly(oos));
assertSame(fos, RxJavaPlugins.onAssembly(fos));
assertNull(RxJavaPlugins.onAssembly((Single) null));
Single sos = new Single() {
@Override
public void subscribeActual(SingleObserver t) {
}
};
assertSame(sos, RxJavaPlugins.onAssembly(sos));
assertNull(RxJavaPlugins.onAssembly((Completable) null));
Completable cos = new Completable() {
@Override
public void subscribeActual(CompletableObserver t) {
}
};
assertSame(cos, RxJavaPlugins.onAssembly(cos));
assertNull(RxJavaPlugins.onAssembly((Maybe) null));
assertNull(RxJavaPlugins.onSchedule(null));
Maybe myb = new Maybe() {
@Override
public void subscribeActual(MaybeObserver t) {
}
};
assertSame(myb, RxJavaPlugins.onAssembly(myb));
assertNull(RxJavaPlugins.onSchedule(null));
Runnable action = Functions.EMPTY_RUNNABLE;
assertSame(action, RxJavaPlugins.onSchedule(action));
class AllSubscriber implements Subscriber, Observer, SingleObserver, CompletableObserver, MaybeObserver {
@Override
public void onSuccess(Object value) {
}
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSubscribe(Subscription s) {
}
@Override
public void onNext(Object t) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
}
AllSubscriber all = new AllSubscriber();
assertNull(RxJavaPlugins.onSubscribe(Observable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Observable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Flowable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Flowable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Single.just(1), null));
assertSame(all, RxJavaPlugins.onSubscribe(Single.just(1), all));
assertNull(RxJavaPlugins.onSubscribe(Completable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Completable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Maybe.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Maybe.never(), all));
// These hooks don't exist in 2.0
// Subscription subscription = Subscriptions.empty();
//
// assertNull(RxJavaPlugins.onObservableReturn(null));
//
// assertSame(subscription, RxJavaPlugins.onObservableReturn(subscription));
//
// assertNull(RxJavaPlugins.onSingleReturn(null));
//
// assertSame(subscription, RxJavaPlugins.onSingleReturn(subscription));
//
// TestException ex = new TestException();
//
// assertNull(RxJavaPlugins.onObservableError(null));
//
// assertSame(ex, RxJavaPlugins.onObservableError(ex));
//
// assertNull(RxJavaPlugins.onSingleError(null));
//
// assertSame(ex, RxJavaPlugins.onSingleError(ex));
//
// assertNull(RxJavaPlugins.onCompletableError(null));
//
// assertSame(ex, RxJavaPlugins.onCompletableError(ex));
//
// Observable.Operator oop = new Observable.Operator() {
// @Override
// public Object call(Object t) {
// return t;
// }
// };
//
// assertNull(RxJavaPlugins.onObservableLift(null));
//
// assertSame(oop, RxJavaPlugins.onObservableLift(oop));
//
// assertNull(RxJavaPlugins.onSingleLift(null));
//
// assertSame(oop, RxJavaPlugins.onSingleLift(oop));
//
// Completable.CompletableOperator cop = new Completable.CompletableOperator() {
// @Override
// public CompletableSubscriber call(CompletableSubscriber t) {
// return t;
// }
// };
//
// assertNull(RxJavaPlugins.onCompletableLift(null));
//
// assertSame(cop, RxJavaPlugins.onCompletableLift(cop));
final Scheduler s = ImmediateThinScheduler.INSTANCE;
Callable<Scheduler> c = new Callable<Scheduler>() {
@Override
public Scheduler call() throws Exception {
return s;
}
};
assertSame(s, RxJavaPlugins.onComputationScheduler(s));
assertSame(s, RxJavaPlugins.onIoScheduler(s));
assertSame(s, RxJavaPlugins.onNewThreadScheduler(s));
assertSame(s, RxJavaPlugins.onSingleScheduler(s));
assertSame(s, RxJavaPlugins.initComputationScheduler(c));
assertSame(s, RxJavaPlugins.initIoScheduler(c));
assertSame(s, RxJavaPlugins.initNewThreadScheduler(c));
assertSame(s, RxJavaPlugins.initSingleScheduler(c));
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.observables.ConnectableObservable in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideConnectableObservable.
@SuppressWarnings("rawtypes")
@Test
public void overrideConnectableObservable() {
try {
RxJavaPlugins.setOnConnectableObservableAssembly(new Function<ConnectableObservable, ConnectableObservable>() {
@Override
public ConnectableObservable apply(ConnectableObservable co) throws Exception {
return new ConnectableObservable() {
@Override
public void connect(Consumer connection) {
}
@SuppressWarnings("unchecked")
@Override
protected void subscribeActual(Observer observer) {
observer.onSubscribe(Disposables.empty());
observer.onNext(10);
observer.onComplete();
}
};
}
});
Observable.just(1).publish().autoConnect().test().assertResult(10);
} finally {
RxJavaPlugins.reset();
}
Observable.just(1).publish().autoConnect().test().assertResult(1);
}
Aggregations