@SuppressWarnings({ "rawtypes" }) @Test public void lockdown() throws Exception { RxJavaPlugins.reset(); RxJavaPlugins.lockdown(); try { assertTrue(RxJavaPlugins.isLockdown()); Consumer a1 = Functions.emptyConsumer(); Callable f0 = new Callable() { @Override public Object call() { return null; } }; Function f1 = Functions.identity(); BiFunction f2 = new BiFunction() { @Override public Object apply(Object t1, Object t2) { return t2; } }; BooleanSupplier bs = new BooleanSupplier() { @Override public boolean getAsBoolean() throws Exception { return true; } }; for (Method m : RxJavaPlugins.class.getMethods()) { if (m.getName().startsWith("set")) { Method getter; Class<?> paramType = m.getParameterTypes()[0]; if (paramType == Boolean.TYPE) { getter = RxJavaPlugins.class.getMethod("is" + m.getName().substring(3)); } else { getter = RxJavaPlugins.class.getMethod("get" + m.getName().substring(3)); } Object before = getter.invoke(null); try { if (paramType.isAssignableFrom(Boolean.TYPE)) { m.invoke(null, true); } else if (paramType.isAssignableFrom(Callable.class)) { m.invoke(null, f0); } else if (paramType.isAssignableFrom(Function.class)) { m.invoke(null, f1); } else if (paramType.isAssignableFrom(Consumer.class)) { m.invoke(null, a1); } else if (paramType.isAssignableFrom(BooleanSupplier.class)) { m.invoke(null, bs); } else { m.invoke(null, f2); } fail("Should have thrown InvocationTargetException(IllegalStateException)"); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof IllegalStateException) { assertEquals("Plugins can't be changed anymore",ex.getCause().getMessage()); } else { fail("Should have thrown InvocationTargetException(IllegalStateException)"); } } Object after = getter.invoke(null); if (paramType.isPrimitive()) { assertEquals(m.toString(), before, after); } else { assertSame(m.toString(), before, after); } } } } finally { RxJavaPlugins.unlock(); RxJavaPlugins.reset(); assertFalse(RxJavaPlugins.isLockdown()); } }
public static void lockdown() { lockdown = true; }
RxJavaPlugins { public static void lockdown() { lockdown = true; } }
RxJavaPlugins { public static void lockdown() { lockdown = true; } private  RxJavaPlugins(); }
RxJavaPlugins { public static void lockdown() { lockdown = true; } private  RxJavaPlugins(); static void lockdown(); static boolean isLockdown(); static void setFailOnNonBlockingScheduler(boolean enable); static boolean isFailOnNonBlockingScheduler(); @Nullable static Function<? super Scheduler, ? extends Scheduler> getComputationSchedulerHandler(); @Nullable static Consumer<? super Throwable> getErrorHandler(); @Nullable static Function<? super Callable<Scheduler>, ? extends Scheduler> getInitComputationSchedulerHandler(); @Nullable static Function<? super Callable<Scheduler>, ? extends Scheduler> getInitIoSchedulerHandler(); @Nullable static Function<? super Callable<Scheduler>, ? extends Scheduler> getInitNewThreadSchedulerHandler(); @Nullable static Function<? super Callable<Scheduler>, ? extends Scheduler> getInitSingleSchedulerHandler(); @Nullable static Function<? super Scheduler, ? extends Scheduler> getIoSchedulerHandler(); @Nullable static Function<? super Scheduler, ? extends Scheduler> getNewThreadSchedulerHandler(); @Nullable static Function<? super Runnable, ? extends Runnable> getScheduleHandler(); @Nullable static Function<? super Scheduler, ? extends Scheduler> getSingleSchedulerHandler(); @NonNull static Scheduler initComputationScheduler(@NonNull Callable<Scheduler> defaultScheduler); @NonNull static Scheduler initIoScheduler(@NonNull Callable<Scheduler> defaultScheduler); @NonNull static Scheduler initNewThreadScheduler(@NonNull Callable<Scheduler> defaultScheduler); @NonNull static Scheduler initSingleScheduler(@NonNull Callable<Scheduler> defaultScheduler); @NonNull static Scheduler onComputationScheduler(@NonNull Scheduler defaultScheduler); static void onError(@NonNull Throwable error); @NonNull static Scheduler onIoScheduler(@NonNull Scheduler defaultScheduler); @NonNull static Scheduler onNewThreadScheduler(@NonNull Scheduler defaultScheduler); @NonNull static Runnable onSchedule(@NonNull Runnable run); @NonNull static Scheduler onSingleScheduler(@NonNull Scheduler defaultScheduler); static void reset(); static void setComputationSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler); static void setErrorHandler(@Nullable Consumer<? super Throwable> handler); static void setInitComputationSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler); static void setInitIoSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler); static void setInitNewThreadSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler); static void setInitSingleSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler); static void setIoSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler); static void setNewThreadSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler); static void setScheduleHandler(@Nullable Function<? super Runnable, ? extends Runnable> handler); static void setSingleSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler); @Nullable static Function<? super Completable, ? extends Completable> getOnCompletableAssembly(); @Nullable static BiFunction<? super Completable, ? super CompletableObserver, ? extends CompletableObserver> getOnCompletableSubscribe(); @SuppressWarnings("rawtypes") @Nullable static Function<? super Flowable, ? extends Flowable> getOnFlowableAssembly(); @SuppressWarnings("rawtypes") @Nullable static Function<? super ConnectableFlowable, ? extends ConnectableFlowable> getOnConnectableFlowableAssembly(); @Nullable @SuppressWarnings("rawtypes") static BiFunction<? super Flowable, ? super Subscriber, ? extends Subscriber> getOnFlowableSubscribe(); @Nullable @SuppressWarnings("rawtypes") static BiFunction<? super Maybe, ? super MaybeObserver, ? extends MaybeObserver> getOnMaybeSubscribe(); @Nullable @SuppressWarnings("rawtypes") static Function<? super Maybe, ? extends Maybe> getOnMaybeAssembly(); @Nullable @SuppressWarnings("rawtypes") static Function<? super Single, ? extends Single> getOnSingleAssembly(); @Nullable @SuppressWarnings("rawtypes") static BiFunction<? super Single, ? super SingleObserver, ? extends SingleObserver> getOnSingleSubscribe(); @Nullable @SuppressWarnings("rawtypes") static Function<? super Observable, ? extends Observable> getOnObservableAssembly(); @Nullable @SuppressWarnings("rawtypes") static Function<? super ConnectableObservable, ? extends ConnectableObservable> getOnConnectableObservableAssembly(); @Nullable @SuppressWarnings("rawtypes") static BiFunction<? super Observable, ? super Observer, ? extends Observer> getOnObservableSubscribe(); static void setOnCompletableAssembly(@Nullable Function<? super Completable, ? extends Completable> onCompletableAssembly); static void setOnCompletableSubscribe(
            @Nullable BiFunction<? super Completable, ? super CompletableObserver, ? extends CompletableObserver> onCompletableSubscribe); @SuppressWarnings("rawtypes") static void setOnFlowableAssembly(@Nullable Function<? super Flowable, ? extends Flowable> onFlowableAssembly); @SuppressWarnings("rawtypes") static void setOnMaybeAssembly(@Nullable Function<? super Maybe, ? extends Maybe> onMaybeAssembly); @SuppressWarnings("rawtypes") static void setOnConnectableFlowableAssembly(@Nullable Function<? super ConnectableFlowable, ? extends ConnectableFlowable> onConnectableFlowableAssembly); @SuppressWarnings("rawtypes") static void setOnFlowableSubscribe(@Nullable BiFunction<? super Flowable, ? super Subscriber, ? extends Subscriber> onFlowableSubscribe); @SuppressWarnings("rawtypes") static void setOnMaybeSubscribe(@Nullable BiFunction<? super Maybe, MaybeObserver, ? extends MaybeObserver> onMaybeSubscribe); @SuppressWarnings("rawtypes") static void setOnObservableAssembly(@Nullable Function<? super Observable, ? extends Observable> onObservableAssembly); @SuppressWarnings("rawtypes") static void setOnConnectableObservableAssembly(@Nullable Function<? super ConnectableObservable, ? extends ConnectableObservable> onConnectableObservableAssembly); @SuppressWarnings("rawtypes") static void setOnObservableSubscribe(
            @Nullable BiFunction<? super Observable, ? super Observer, ? extends Observer> onObservableSubscribe); @SuppressWarnings("rawtypes") static void setOnSingleAssembly(@Nullable Function<? super Single, ? extends Single> onSingleAssembly); @SuppressWarnings("rawtypes") static void setOnSingleSubscribe(@Nullable BiFunction<? super Single, ? super SingleObserver, ? extends SingleObserver> onSingleSubscribe); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Subscriber<? super T> onSubscribe(@NonNull Flowable<T> source, @NonNull Subscriber<? super T> subscriber); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Observer<? super T> onSubscribe(@NonNull Observable<T> source, @NonNull Observer<? super T> observer); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static SingleObserver<? super T> onSubscribe(@NonNull Single<T> source, @NonNull SingleObserver<? super T> observer); @NonNull static CompletableObserver onSubscribe(@NonNull Completable source, @NonNull CompletableObserver observer); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static MaybeObserver<? super T> onSubscribe(@NonNull Maybe<T> source, @NonNull MaybeObserver<? super T> subscriber); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Maybe<T> onAssembly(@NonNull Maybe<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Flowable<T> onAssembly(@NonNull Flowable<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static ConnectableFlowable<T> onAssembly(@NonNull ConnectableFlowable<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Observable<T> onAssembly(@NonNull Observable<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static ConnectableObservable<T> onAssembly(@NonNull ConnectableObservable<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Single<T> onAssembly(@NonNull Single<T> source); @NonNull static Completable onAssembly(@NonNull Completable source); @Beta @SuppressWarnings("rawtypes") static void setOnParallelAssembly(@Nullable Function<? super ParallelFlowable, ? extends ParallelFlowable> handler); @Beta @SuppressWarnings("rawtypes") @Nullable static Function<? super ParallelFlowable, ? extends ParallelFlowable> getOnParallelAssembly(); @Beta @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static ParallelFlowable<T> onAssembly(@NonNull ParallelFlowable<T> source); static boolean onBeforeBlocking(); static void setOnBeforeBlocking(@Nullable BooleanSupplier handler); @Nullable static BooleanSupplier getOnBeforeBlocking(); @NonNull static Scheduler createComputationScheduler(@NonNull ThreadFactory threadFactory); @NonNull static Scheduler createIoScheduler(@NonNull ThreadFactory threadFactory); @NonNull static Scheduler createNewThreadScheduler(@NonNull ThreadFactory threadFactory); @NonNull static Scheduler createSingleScheduler(@NonNull ThreadFactory threadFactory); }
RxJavaPlugins { public static void lockdown() { lockdown = true; } private  RxJavaPlugins(); static void lockdown(); static boolean isLockdown(); static void setFailOnNonBlockingScheduler(boolean enable); static boolean isFailOnNonBlockingScheduler(); @Nullable static Function<? super Scheduler, ? extends Scheduler> getComputationSchedulerHandler(); @Nullable static Consumer<? super Throwable> getErrorHandler(); @Nullable static Function<? super Callable<Scheduler>, ? extends Scheduler> getInitComputationSchedulerHandler(); @Nullable static Function<? super Callable<Scheduler>, ? extends Scheduler> getInitIoSchedulerHandler(); @Nullable static Function<? super Callable<Scheduler>, ? extends Scheduler> getInitNewThreadSchedulerHandler(); @Nullable static Function<? super Callable<Scheduler>, ? extends Scheduler> getInitSingleSchedulerHandler(); @Nullable static Function<? super Scheduler, ? extends Scheduler> getIoSchedulerHandler(); @Nullable static Function<? super Scheduler, ? extends Scheduler> getNewThreadSchedulerHandler(); @Nullable static Function<? super Runnable, ? extends Runnable> getScheduleHandler(); @Nullable static Function<? super Scheduler, ? extends Scheduler> getSingleSchedulerHandler(); @NonNull static Scheduler initComputationScheduler(@NonNull Callable<Scheduler> defaultScheduler); @NonNull static Scheduler initIoScheduler(@NonNull Callable<Scheduler> defaultScheduler); @NonNull static Scheduler initNewThreadScheduler(@NonNull Callable<Scheduler> defaultScheduler); @NonNull static Scheduler initSingleScheduler(@NonNull Callable<Scheduler> defaultScheduler); @NonNull static Scheduler onComputationScheduler(@NonNull Scheduler defaultScheduler); static void onError(@NonNull Throwable error); @NonNull static Scheduler onIoScheduler(@NonNull Scheduler defaultScheduler); @NonNull static Scheduler onNewThreadScheduler(@NonNull Scheduler defaultScheduler); @NonNull static Runnable onSchedule(@NonNull Runnable run); @NonNull static Scheduler onSingleScheduler(@NonNull Scheduler defaultScheduler); static void reset(); static void setComputationSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler); static void setErrorHandler(@Nullable Consumer<? super Throwable> handler); static void setInitComputationSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler); static void setInitIoSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler); static void setInitNewThreadSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler); static void setInitSingleSchedulerHandler(@Nullable Function<? super Callable<Scheduler>, ? extends Scheduler> handler); static void setIoSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler); static void setNewThreadSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler); static void setScheduleHandler(@Nullable Function<? super Runnable, ? extends Runnable> handler); static void setSingleSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler> handler); @Nullable static Function<? super Completable, ? extends Completable> getOnCompletableAssembly(); @Nullable static BiFunction<? super Completable, ? super CompletableObserver, ? extends CompletableObserver> getOnCompletableSubscribe(); @SuppressWarnings("rawtypes") @Nullable static Function<? super Flowable, ? extends Flowable> getOnFlowableAssembly(); @SuppressWarnings("rawtypes") @Nullable static Function<? super ConnectableFlowable, ? extends ConnectableFlowable> getOnConnectableFlowableAssembly(); @Nullable @SuppressWarnings("rawtypes") static BiFunction<? super Flowable, ? super Subscriber, ? extends Subscriber> getOnFlowableSubscribe(); @Nullable @SuppressWarnings("rawtypes") static BiFunction<? super Maybe, ? super MaybeObserver, ? extends MaybeObserver> getOnMaybeSubscribe(); @Nullable @SuppressWarnings("rawtypes") static Function<? super Maybe, ? extends Maybe> getOnMaybeAssembly(); @Nullable @SuppressWarnings("rawtypes") static Function<? super Single, ? extends Single> getOnSingleAssembly(); @Nullable @SuppressWarnings("rawtypes") static BiFunction<? super Single, ? super SingleObserver, ? extends SingleObserver> getOnSingleSubscribe(); @Nullable @SuppressWarnings("rawtypes") static Function<? super Observable, ? extends Observable> getOnObservableAssembly(); @Nullable @SuppressWarnings("rawtypes") static Function<? super ConnectableObservable, ? extends ConnectableObservable> getOnConnectableObservableAssembly(); @Nullable @SuppressWarnings("rawtypes") static BiFunction<? super Observable, ? super Observer, ? extends Observer> getOnObservableSubscribe(); static void setOnCompletableAssembly(@Nullable Function<? super Completable, ? extends Completable> onCompletableAssembly); static void setOnCompletableSubscribe(
            @Nullable BiFunction<? super Completable, ? super CompletableObserver, ? extends CompletableObserver> onCompletableSubscribe); @SuppressWarnings("rawtypes") static void setOnFlowableAssembly(@Nullable Function<? super Flowable, ? extends Flowable> onFlowableAssembly); @SuppressWarnings("rawtypes") static void setOnMaybeAssembly(@Nullable Function<? super Maybe, ? extends Maybe> onMaybeAssembly); @SuppressWarnings("rawtypes") static void setOnConnectableFlowableAssembly(@Nullable Function<? super ConnectableFlowable, ? extends ConnectableFlowable> onConnectableFlowableAssembly); @SuppressWarnings("rawtypes") static void setOnFlowableSubscribe(@Nullable BiFunction<? super Flowable, ? super Subscriber, ? extends Subscriber> onFlowableSubscribe); @SuppressWarnings("rawtypes") static void setOnMaybeSubscribe(@Nullable BiFunction<? super Maybe, MaybeObserver, ? extends MaybeObserver> onMaybeSubscribe); @SuppressWarnings("rawtypes") static void setOnObservableAssembly(@Nullable Function<? super Observable, ? extends Observable> onObservableAssembly); @SuppressWarnings("rawtypes") static void setOnConnectableObservableAssembly(@Nullable Function<? super ConnectableObservable, ? extends ConnectableObservable> onConnectableObservableAssembly); @SuppressWarnings("rawtypes") static void setOnObservableSubscribe(
            @Nullable BiFunction<? super Observable, ? super Observer, ? extends Observer> onObservableSubscribe); @SuppressWarnings("rawtypes") static void setOnSingleAssembly(@Nullable Function<? super Single, ? extends Single> onSingleAssembly); @SuppressWarnings("rawtypes") static void setOnSingleSubscribe(@Nullable BiFunction<? super Single, ? super SingleObserver, ? extends SingleObserver> onSingleSubscribe); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Subscriber<? super T> onSubscribe(@NonNull Flowable<T> source, @NonNull Subscriber<? super T> subscriber); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Observer<? super T> onSubscribe(@NonNull Observable<T> source, @NonNull Observer<? super T> observer); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static SingleObserver<? super T> onSubscribe(@NonNull Single<T> source, @NonNull SingleObserver<? super T> observer); @NonNull static CompletableObserver onSubscribe(@NonNull Completable source, @NonNull CompletableObserver observer); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static MaybeObserver<? super T> onSubscribe(@NonNull Maybe<T> source, @NonNull MaybeObserver<? super T> subscriber); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Maybe<T> onAssembly(@NonNull Maybe<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Flowable<T> onAssembly(@NonNull Flowable<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static ConnectableFlowable<T> onAssembly(@NonNull ConnectableFlowable<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Observable<T> onAssembly(@NonNull Observable<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static ConnectableObservable<T> onAssembly(@NonNull ConnectableObservable<T> source); @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static Single<T> onAssembly(@NonNull Single<T> source); @NonNull static Completable onAssembly(@NonNull Completable source); @Beta @SuppressWarnings("rawtypes") static void setOnParallelAssembly(@Nullable Function<? super ParallelFlowable, ? extends ParallelFlowable> handler); @Beta @SuppressWarnings("rawtypes") @Nullable static Function<? super ParallelFlowable, ? extends ParallelFlowable> getOnParallelAssembly(); @Beta @SuppressWarnings({ "rawtypes", "unchecked" }) @NonNull static ParallelFlowable<T> onAssembly(@NonNull ParallelFlowable<T> source); static boolean onBeforeBlocking(); static void setOnBeforeBlocking(@Nullable BooleanSupplier handler); @Nullable static BooleanSupplier getOnBeforeBlocking(); @NonNull static Scheduler createComputationScheduler(@NonNull ThreadFactory threadFactory); @NonNull static Scheduler createIoScheduler(@NonNull ThreadFactory threadFactory); @NonNull static Scheduler createNewThreadScheduler(@NonNull ThreadFactory threadFactory); @NonNull static Scheduler createSingleScheduler(@NonNull ThreadFactory threadFactory);  }