rx.android.plugins.RxAndroidPlugins Java Examples

The following examples show how to use rx.android.plugins.RxAndroidPlugins. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxSchedulersOverrideRule.java    From programming with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);

            RxJavaPlugins.getInstance().reset();
            RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);

            base.evaluate();

            RxAndroidPlugins.getInstance().reset();
            RxJavaPlugins.getInstance().reset();
        }
    };
}
 
Example #2
Source File: SignInPresenterTest.java    From Moxy with MIT License 6 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);
	presenter = new SignInPresenter();
	presenter.setViewState(signInViewState);

	RxJavaPlugins.getInstance().reset();
	RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() {
		@Override
		public Scheduler getIOScheduler() {
			return Schedulers.immediate();
		}
	});
	RxAndroidPlugins.getInstance().reset();
	RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() {
		@Override
		public Scheduler getMainThreadScheduler() {
			return Schedulers.immediate();
		}
	});
}
 
Example #3
Source File: RepositoriesPresenterTest.java    From Moxy with MIT License 6 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);
	presenter = new RepositoriesPresenter();
	presenter.setViewState(repositoriesViewState);

	RxJavaPlugins.getInstance().reset();
	RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() {
		@Override
		public Scheduler getIOScheduler() {
			return Schedulers.immediate();
		}
	});
	RxAndroidPlugins.getInstance().reset();
	RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() {
		@Override
		public Scheduler getMainThreadScheduler() {
			return Schedulers.immediate();
		}
	});
}
 
Example #4
Source File: RxJavaResetRule.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            //before: plugins reset, execution and schedulers hook defined
            RxJavaPlugins.getInstance().reset();
            RxJavaPlugins.getInstance().registerSchedulersHook(new SchedulerHook());

            RxAndroidPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().registerSchedulersHook(new AndroidSchedulersHook());

            base.evaluate();

            //after: clean up
            RxJavaPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().reset();
        }
    };
}
 
Example #5
Source File: RxSchedulersOverrideRule.java    From Stock-Hawk with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);

            RxJavaPlugins.getInstance().reset();
            RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);

            base.evaluate();

            RxAndroidPlugins.getInstance().reset();
            RxJavaPlugins.getInstance().reset();
        }
    };
}
 
Example #6
Source File: RxSchedulersOverrideRule.java    From FriendlyDemo with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
            callResetViaReflectionIn(RxJavaPlugins.getInstance());
            RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);

            base.evaluate();

            RxAndroidPlugins.getInstance().reset();
            callResetViaReflectionIn(RxJavaPlugins.getInstance());
        }
    };
}
 
Example #7
Source File: RxSchedulersTestRule.java    From AndroidSchool with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaHooks.reset();
            RxJavaHooks.setOnIOScheduler(mMockSchedulerFunc);
            RxJavaHooks.setOnNewThreadScheduler(mMockSchedulerFunc);

            RxAndroidPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);

            base.evaluate();

            RxJavaHooks.reset();
            RxAndroidPlugins.getInstance().reset();
        }
    };
}
 
Example #8
Source File: RxUnitTestTools.java    From fingerpoetry-android with Apache License 2.0 6 votes vote down vote up
/**
 * 把异步变成同步,方便测试
 */
public static void openRxTools() {
    if (isInitRxTools) {
        return;
    }
    isInitRxTools = true;

    RxAndroidSchedulersHook rxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
        @Override
        public Scheduler getMainThreadScheduler() {
            return Schedulers.immediate();
        }
    };

    RxJavaSchedulersHook rxJavaSchedulersHook = new RxJavaSchedulersHook() {
        @Override
        public Scheduler getIOScheduler() {
            return Schedulers.immediate();
        }
    };

    RxAndroidPlugins.getInstance().registerSchedulersHook(rxAndroidSchedulersHook);
    RxJavaPlugins.getInstance().registerSchedulersHook(rxJavaSchedulersHook);
}
 
Example #9
Source File: RxSchedulersOverrideRule.java    From Hews with MIT License 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);

            RxJavaPlugins.getInstance().reset();
            RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);

            base.evaluate();

            RxAndroidPlugins.getInstance().reset();
            RxJavaPlugins.getInstance().reset();
        }
    };
}
 
Example #10
Source File: RxSchedulersOverrideRule.java    From ribot-app-android with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
            callResetViaReflectionIn(RxJavaPlugins.getInstance());
            RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);

            base.evaluate();

            RxAndroidPlugins.getInstance().reset();
            callResetViaReflectionIn(RxJavaPlugins.getInstance());
        }
    };
}
 
Example #11
Source File: AndroidSchedulers.java    From letv with Apache License 2.0 5 votes vote down vote up
private AndroidSchedulers() {
    Scheduler main = RxAndroidPlugins.getInstance().getSchedulersHook().getMainThreadScheduler();
    if (main != null) {
        this.mainThreadScheduler = main;
    } else {
        this.mainThreadScheduler = new LooperScheduler(Looper.getMainLooper());
    }
}
 
Example #12
Source File: RxUtils.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
public static void setupTestSchedulers() {
    try {
        RxJavaHooks.setOnIOScheduler(scheduler -> Schedulers.immediate());
        RxJavaHooks.setOnNewThreadScheduler(scheduler -> Schedulers.immediate());

        RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() {
            @Override
            public Scheduler getMainThreadScheduler() {
                return Schedulers.immediate();
            }
        });
    } catch (IllegalStateException ignored) {
    }
}
 
Example #13
Source File: RxJUnitRunner.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
private void setupTestSchedulers() {
    RxJavaHooks.setOnIOScheduler(scheduler -> Schedulers.immediate());
    RxJavaHooks.setOnNewThreadScheduler(scheduler -> Schedulers.immediate());

    try {
        RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() {
            @Override
            public Scheduler getMainThreadScheduler() {
                return Schedulers.immediate();
            }
        });
    } catch (IllegalStateException ignored) {
        // already registered
    }
}