@Test public void mainThreadCallsThroughToHook() { final AtomicInteger called = new AtomicInteger(); final Scheduler newScheduler = new EmptyScheduler(); RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() { @Override public Scheduler apply(Scheduler scheduler) { called.getAndIncrement(); return newScheduler; } }); assertSame(newScheduler, AndroidSchedulers.mainThread()); assertEquals(1, called.get()); assertSame(newScheduler, AndroidSchedulers.mainThread()); assertEquals(2, called.get()); }
@Override public Statement apply(Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.reset(); RxAndroidPlugins.setInitMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline()); RxJavaPlugins.reset(); RxJavaPlugins.setIoSchedulerHandler(schedulerCallable -> Schedulers.trampoline()); base.evaluate(); RxAndroidPlugins.reset(); RxJavaPlugins.reset(); } }; }
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline()); RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline()); try { base.evaluate(); } finally { RxJavaPlugins.reset(); RxAndroidPlugins.reset(); } } }; }
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.reset(); RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline()); RxJavaPlugins.reset(); RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline()); RxJavaPlugins.setComputationSchedulerHandler(scheduler -> Schedulers.trampoline()); RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> Schedulers.trampoline()); base.evaluate(); RxAndroidPlugins.reset(); RxJavaPlugins.reset(); } }; }
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.reset(); RxAndroidPlugins.setInitMainThreadSchedulerHandler(mRxAndroidSchedulersHook); RxJavaPlugins.reset(); RxJavaPlugins.setIoSchedulerHandler(mRxJavaImmediateScheduler); RxJavaPlugins.setNewThreadSchedulerHandler(mRxJavaImmediateScheduler); base.evaluate(); RxAndroidPlugins.reset(); RxJavaPlugins.reset(); } }; }
@Override protected void starting(Description description) { if (restoreHandlers) { // https://github.com/ReactiveX/RxAndroid/pull/358 // originalInitMainThreadInitHandler = // RxAndroidPlugins.getInitMainThreadScheduler(); // originalMainThreadHandler = RxAndroidPlugins.getMainThreadScheduler(); } RxAndroidPlugins.reset(); RxAndroidPlugins.setInitMainThreadSchedulerHandler( new Function<Callable<Scheduler>, Scheduler>() { @Override public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception { return delegatingMainThreadScheduler; } }); RxAndroidPlugins.setMainThreadSchedulerHandler( new Function<Scheduler, Scheduler>() { @Override public Scheduler apply(Scheduler scheduler) throws Exception { return delegatingMainThreadScheduler; } }); }
@BeforeClass public static void setupRxJavaPlugins() { RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() { @Override public Scheduler apply(Scheduler scheduler) throws Exception { return Schedulers.trampoline(); } }); RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() { @Override public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception { return Schedulers.trampoline(); } }); }
@BeforeClass public static void setupClass() { RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() { @Override public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception { return Schedulers.trampoline(); } }); RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() { @Override public Scheduler apply(Scheduler scheduler) throws Exception { return Schedulers.trampoline(); } }); }
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline()); RxJavaPlugins.setComputationSchedulerHandler(scheduler -> Schedulers.trampoline()); RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> Schedulers.trampoline()); RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline()); try { base.evaluate(); } finally { RxJavaPlugins.reset(); } } }; }
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.reset(); RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerFunctionLazy); RxJavaPlugins.reset(); RxJavaPlugins.setIoSchedulerHandler(schedulerFunction); RxJavaPlugins.setNewThreadSchedulerHandler(schedulerFunction); RxJavaPlugins.setComputationSchedulerHandler(schedulerFunction); base.evaluate(); RxAndroidPlugins.reset(); RxJavaPlugins.reset(); } }; }
@Before public void setUp () { RxAndroidPlugins.setInitMainThreadSchedulerHandler( new Function<Callable<Scheduler>, Scheduler>( ) { @Override public Scheduler apply (@NonNull Callable<Scheduler> schedulerCallable) throws Exception { return Schedulers.trampoline( ); } } ); when( mockCountryRepository.countries( getCountriesList.policy ) ) .thenReturn( Observable.<List<Country>>empty( ) ); }
public Statement apply(Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { Scheduler scheduler = TrampolineScheduler.instance(); Function<Callable<Scheduler>, Scheduler> schedulerFn = __ -> scheduler; RxJavaPlugins.reset(); RxJavaPlugins.setInitIoSchedulerHandler(schedulerFn); RxJavaPlugins.setInitNewThreadSchedulerHandler(schedulerFn); RxAndroidPlugins.reset(); RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerFn); try { base.evaluate(); } finally { RxJavaPlugins.reset(); RxAndroidPlugins.reset(); } } }; }
@Before public void setUp() throws Exception { mMockView = mock(SuggestContract.View.class); mApi = mock(LoklakAPI.class); mPresenter = new SuggestPresenter(mApi, mDb); mPresenter.attachView(mMockView); queries = getFakeQueries(); RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline()); RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline()); mDb.beginTransaction(); mDb.copyToRealm(queries); mDb.commitTransaction(); }
@BeforeClass public static void init() throws Exception { // Tell RxAndroid to not use android main ui thread scheduler RxAndroidPlugins.setInitMainThreadSchedulerHandler( new Function<Callable<Scheduler>, Scheduler>() { @Override public Scheduler apply(@NonNull Callable<Scheduler> schedulerCallable) throws Exception { return Schedulers.trampoline(); } }); }
@BeforeClass public static void setupBaseTestBeforeClass() { RxJavaPlugins.onComputationScheduler(Schedulers.trampoline()); RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() { @Override public Scheduler apply(@NonNull Callable<Scheduler> schedulerCallable) throws Exception { return Schedulers.trampoline(); } }); }
@BeforeClass public static void onlyOnce() throws Exception { RxAndroidPlugins.setInitMainThreadSchedulerHandler( new Function<Callable<Scheduler>, Scheduler>() { @Override public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception { return Schedulers.trampoline(); } }); }
@BeforeClass public static void setup() { RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.io()); // sample recent pages long timestamp = System.currentTimeMillis(); SAMPLE_RECENT_PAGES.add(new RecentPage(49, timestamp)); SAMPLE_RECENT_PAGES.add(new RecentPage(100, timestamp - 10000)); }
@Before public void setup() { RxAndroidPlugins.setInitMainThreadSchedulerHandler( new Function<Callable<Scheduler>, Scheduler>() { @Override public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception { return Schedulers.trampoline(); } }); }
@Override protected void finished(Description description) { RxAndroidPlugins.reset(); if (restoreHandlers) { // https://github.com/ReactiveX/RxAndroid/pull/358 // // RxAndroidPlugins.setInitMainThreadSchedulerHandler(originalInitMainThreadInitHandler); // RxAndroidPlugins.setMainThreadSchedulerHandler(originalMainThreadHandler); } }
@Before public void init() { loginPresenter = new LoginPresenter(); // BoltsConfig.configureMocks(); BundleFactoryConfig.setProvider(() -> Mockito.mock(Bundle.class)); RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline()); }
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.setInitMainThreadSchedulerHandler(__ -> Schedulers.trampoline()); base.evaluate(); } }; }
@Before public void setUp() throws Exception { RxAndroidPlugins.setInitMainThreadSchedulerHandler(__ -> Schedulers.trampoline()); RxJavaPlugins.setIoSchedulerHandler(__ -> Schedulers.trampoline()); testModelsGenerator = new TestModelsGenerator(); newsModelTestSubscriber = new TestSubscriber<>(); compositeDisposable = new CompositeDisposable(); }
@Before public void init() { testScheduler = new TestScheduler(); RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> testScheduler); RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> testScheduler); RxJavaPlugins.setIoSchedulerHandler(scheduler -> testScheduler); }
@AfterClass public static void tearDown() throws Exception { RxAndroidPlugins.reset(); }
/** A {@link Scheduler} which executes actions on the Android main thread. */ public static Scheduler mainThread() { return RxAndroidPlugins.onMainThreadScheduler(MAIN_THREAD); }
@Before @After public void setUpAndTearDown() { RxAndroidPlugins.reset(); }
@After public void tearDown(){ mockMvpPresenter.onDetach(); RxAndroidPlugins.reset(); }
@BeforeClass public static void setup() { RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.io()); }
@After public void cleanup() { RxAndroidPlugins.reset(); }
@Before public void init() { repositoriesPresenter = new RepositoriesPresenter(); // BoltsConfig.configureMocks(); RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline()); }
@After public void tearDown () { RxAndroidPlugins.reset( ); }
@After public void tearDown() { RxJavaPlugins.reset(); RxAndroidPlugins.reset(); }
@After public void shutDown() throws Exception { RxJavaPlugins.reset(); RxAndroidPlugins.reset(); }