当前位置: 首页>>代码示例>>Java>>正文


Java Observable.test方法代码示例

本文整理汇总了Java中io.reactivex.Observable.test方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.test方法的具体用法?Java Observable.test怎么用?Java Observable.test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Observable的用法示例。


在下文中一共展示了Observable.test方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCartEmitter

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void testCartEmitter() {
	CartManager cartManager = Injector.get(CartManager.class);

	Observable<Integer> observable = cartManager.cartChangedObserver();
	TestObserver<Integer> test = observable.test();

	Plate pizza = new Plate().setId(1L);

	cartManager.addPlate(pizza);
	cartManager.addPlate(new Plate());
	cartManager.removePlate(pizza);

	test.assertSubscribed()
			.assertValueAt(0, integer -> integer.equals(1))
			.assertValueAt(1, integer -> integer.equals(2))
			.assertValueAt(2, integer -> integer.equals(1));
}
 
开发者ID:leocabral,项目名称:lacomida,代码行数:19,代码来源:CartManagerTest.java

示例2: testForecast

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void testForecast() throws Exception {
    server.enqueue(new MockResponse().setBody(responseExample));

    DarkSkyApi darkSkyApi = Utils.buildDarkSkyInstance(server.url("/"));

    Observable<JsonObject> forecast = darkSkyApi.forecast("", -1, -1);
    TestObserver<JsonObject> test = forecast.test();
    test.assertNoErrors();
    JsonObject expected = new Gson().fromJson(responseExample, JsonObject.class);
    test.assertResult(expected);
}
 
开发者ID:TechIsFun,项目名称:RxJava2-weather-example,代码行数:13,代码来源:MockApiTest.java

示例3: shouldNotReceiveBroadcastAfterDisposed

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void shouldNotReceiveBroadcastAfterDisposed() {
    //GIVEN
    final Observable<Intent> observable = RxBroadcastReceivers.fromIntentFilter(application, testIntentFilter);

    //WHEN
    final TestObserver<Intent> observer = observable.test(true);
    application.sendBroadcast(testIntent1);
    application.sendBroadcast(testIntent2);
    application.sendBroadcast(testIntent3);
    //THEN
    observer.assertValueCount(0);
    observer.assertEmpty();
}
 
开发者ID:karczews,项目名称:RxBroadcastReceiver,代码行数:15,代码来源:RxBroadcastReceiverTest.java

示例4: shouldReturnErrorWhenSubscribeOnNonLooperThread

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void shouldReturnErrorWhenSubscribeOnNonLooperThread() {
    //GIVEN
    final Observable<Intent> observable = RxBroadcastReceivers.fromIntentFilter(application, testIntentFilter)
            .subscribeOn(Schedulers.newThread());

    //WHEN
    final TestObserver<Intent> observer = observable.test();

    //THEN
    observer.awaitTerminalEvent();
    observer.assertTerminated();
}
 
开发者ID:karczews,项目名称:RxBroadcastReceiver,代码行数:14,代码来源:RxBroadcastReceiverTest.java

示例5: shouldReceiveBroadcastOnLooperThread

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void shouldReceiveBroadcastOnLooperThread() throws InterruptedException {
    //GIVEN
    final Semaphore beforeLooperPrepare = new Semaphore(0);
    final Semaphore afterLooperPrepare = new Semaphore(0);
    //due to robolectic dirty hack to subscription to be run really on TestHandlerThread due to robolectric
    final HandlerThread handlerThread = new HandlerThread("TestHandlerThread") {
        @Override
        protected void onLooperPrepared() {
            try {
                beforeLooperPrepare.acquire();
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
            shadowOf(Looper.myLooper()).idle();
            afterLooperPrepare.release();
        }
    };

    handlerThread.start();
    final Observable<Intent> observable = RxBroadcastReceivers.fromIntentFilter(application, testIntentFilter)
            .subscribeOn(AndroidSchedulers.from(handlerThread.getLooper()));

    //WHEN
    final TestObserver<Intent> observer = observable.test();

    beforeLooperPrepare.release();
    afterLooperPrepare.acquire();

    assertEquals(0, shadowOf(handlerThread.getLooper()).getScheduler().size());
    application.sendBroadcast(testIntent1);
    assertEquals(1, shadowOf(handlerThread.getLooper()).getScheduler().size());
    application.sendBroadcast(testIntent2);
    assertEquals(2, shadowOf(handlerThread.getLooper()).getScheduler().size());
    application.sendBroadcast(testIntent3);
    assertEquals(3, shadowOf(handlerThread.getLooper()).getScheduler().size());

    shadowOf(handlerThread.getLooper()).idle();
    //THEN

    observer.assertValueCount(3);
    observer.assertValues(testIntent1, testIntent2, testIntent3);
}
 
开发者ID:karczews,项目名称:RxBroadcastReceiver,代码行数:44,代码来源:RxBroadcastReceiverTest.java


注:本文中的io.reactivex.Observable.test方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。