本文整理汇总了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));
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}