當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。