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


Java TestObserver.awaitTerminalEvent方法代码示例

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


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

示例1: getRemoteTranslationListObservable

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void getRemoteTranslationListObservable() throws Exception {
  MockResponse mockResponse = new MockResponse();
  File file = new File(CLI_ROOT_DIRECTORY, "translations.json");
  Buffer buffer = new Buffer();
  buffer.writeAll(Okio.source(file));
  mockResponse.setBody(buffer);
  this.mockWebServer.enqueue(mockResponse);

  TestObserver<TranslationList> testObserver = new TestObserver<>();
  this.translationManager.getRemoteTranslationListObservable()
      .subscribe(testObserver);
  testObserver.awaitTerminalEvent();
  testObserver.assertValueCount(1);
  testObserver.assertNoErrors();
  TranslationList list = testObserver.values().get(0);
  assertThat(list.translations).hasSize(50);
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:19,代码来源:TranslationManagerPresenterTest.java

示例2: testExportAccountStore

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testExportAccountStore() {
	importAccountStore(STORE_1, PASS_1);
	TestObserver<String> subscriber = accountKeystoreService
			.exportAccount(new Wallet(ADDRESS_1), PASS_1, PASS_1)
			.test();
	subscriber.awaitTerminalEvent();
	subscriber.assertComplete();
	assertEquals(subscriber.valueCount(), 1);
	Log.d("EXPORT_ACC", "Val: " + subscriber.values().get(0));
	String val = subscriber.values().get(0);
	try {
		JSONObject json = new JSONObject(val);
		assertTrue(("0x" + json.getString("address")).equalsIgnoreCase(ADDRESS_1));
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	deleteAccountStore(ADDRESS_1, PASS_1);
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:20,代码来源:GetKeystoreWalletRepoTest.java

示例3: testDestroy

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testDestroy() throws Exception {
    RxPaperBook book = RxPaperBook.with("DESTROY", Schedulers.trampoline());
    final String key = "hello";
    final String key2 = "you";
    final ComplexObject value = ComplexObject.random();
    book.write(key, value).subscribe();
    book.write(key2, value).subscribe();
    final TestObserver<Void> destroySubscriber = book.destroy().test();
    destroySubscriber.awaitTerminalEvent();
    destroySubscriber.assertComplete();
    destroySubscriber.assertNoErrors();
    destroySubscriber.assertValueCount(0);
    Assert.assertFalse(book.book.exist(key));
    Assert.assertFalse(book.book.exist(key2));
}
 
开发者ID:pakoito,项目名称:RxPaper2,代码行数:17,代码来源:RxPaperBookTest.java

示例4: clientToServerBackpressure

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void clientToServerBackpressure() throws InterruptedException {
    RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);

    Flowable<NumberProto.Number> rxRequest = Flowable
            .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator)
            .doOnNext(i -> System.out.println(i + " --> "))
            .doOnNext(i -> updateNumberOfWaits(lastValueTime, numberOfWaits))
            .map(BackpressureIntegrationTest::protoNum);

    TestObserver<NumberProto.Number> rxResponse = stub.requestPressure(rxRequest).test();

    rxResponse.awaitTerminalEvent(5, TimeUnit.SECONDS);
    rxResponse.assertComplete()
            .assertValue(v -> v.getNumber(0) == NUMBER_OF_STREAM_ELEMENTS - 1);

    assertThat(numberOfWaits.get()).isEqualTo(1);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:19,代码来源:BackpressureIntegrationTest.java

示例5: testIsPageBookmarked

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testIsPageBookmarked() {
  when(bookmarksAdapter.getBookmarkId(null, null, 42)).thenReturn(1L);
  when(bookmarksAdapter.getBookmarkId(null, null, 43)).thenReturn(-1L);

  TestObserver<Pair<Integer, Boolean>> testObserver = new TestObserver<>();
  model.getIsBookmarkedObservable(42, 43)
      .subscribe(testObserver);
  testObserver.awaitTerminalEvent();
  testObserver.assertNoErrors();
  testObserver.assertValueCount(2);

  List<Pair<Integer, Boolean>> results = testObserver.values();
  for (int i = 0; i < results.size(); i++) {
    Pair<Integer, Boolean> result = results.get(i);
    assertThat(result.first).isAnyOf(42, 43);
    if (result.first == 42) {
      assertThat(result.second).isTrue();
    } else if (result.first == 43) {
      assertThat(result.second).isFalse();
    }
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:24,代码来源:BookmarkModelTest.java

示例6: usingTestObserver

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void usingTestObserver() {
    //An Observable with 5 one-second emissions
    Observable<Long> source = Observable.interval(1,
            TimeUnit.SECONDS)
            .take(5);

    //Declare TestObserver
    TestObserver<Long> testObserver = new TestObserver<>();

    //Assert no subscription has occurred yet
    testObserver.assertNotSubscribed();

    //Subscribe TestObserver to source
    source.subscribe(testObserver);

    //Assert TestObserver is subscribed
    testObserver.assertSubscribed();

    //Block and wait for Observable to terminate
    testObserver.awaitTerminalEvent();

    //Assert TestObserver called onComplete()
    testObserver.assertComplete();

    //Assert there were no errors
    testObserver.assertNoErrors();

    //Assert 5 values were received
    testObserver.assertValueCount(5);

    //Assert the received emissions were 0, 1, 2, 3, 4
    testObserver.assertValues(0L, 1L, 2L, 3L, 4L);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:35,代码来源:Ch10_12.java

示例7: createAccountStore

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
private Wallet createAccountStore() {
	TestObserver<Wallet> subscriber = new TestObserver<>();
	accountKeystoreService
			.createAccount("1234")
			.toObservable()
			.subscribe(subscriber);
	subscriber.awaitTerminalEvent();
	subscriber.assertComplete();
	assertEquals(subscriber.valueCount(), 1);
	return subscriber.values().get(0);
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:12,代码来源:GetKeystoreWalletRepoTest.java

示例8: testFindAccount

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testFindAccount() {
	importAccount(STORE_1, PASS_1);
	TestObserver<Wallet> subscribe = accountRepository
			.findWallet(ADDRESS_1)
			.test();
	subscribe.awaitTerminalEvent();
	subscribe.assertComplete();
	assertEquals(subscribe.valueCount(), 1);
	assertTrue(subscribe.values().get(0).sameAddress(ADDRESS_1));
	deleteAccount(ADDRESS_1, PASS_1);
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:13,代码来源:WalletRepoTest.java

示例9: testUpdateBookmarkTags

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testUpdateBookmarkTags() {
  when(bookmarksAdapter.tagBookmarks(
      any(long[].class), anySetOf(long.class), anyBoolean())).thenReturn(true);

  TestObserver<Boolean> testObserver = new TestObserver<>();
  model.updateBookmarkTags(new long[] { }, new HashSet<Long>(), false)
      .subscribe(testObserver);
  testObserver.awaitTerminalEvent();
  testObserver.assertNoErrors();
  testObserver.assertComplete();
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:13,代码来源:BookmarkModelTest.java

示例10: getGoogleTrend_200ResponseDelay5Secs

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void getGoogleTrend_200ResponseDelay5Secs() {
    //Given
    when(fancyTrendRestService.getGoogleTrend()).thenReturn(Single.just(Constant.generateTrendMap()).delay(5, TimeUnit.SECONDS));

    //When
    TestObserver<ArrayMap<String, List<String>>> subscriber = new TestObserver<>();
    trendRepository.getAllTrend().subscribe(subscriber);

    //Then
    subscriber.awaitTerminalEvent();
    subscriber.assertError(TimeoutException.class);

    verify(fancyTrendRestService).getGoogleTrend();
}
 
开发者ID:fantasy1022,项目名称:FancyTrendView,代码行数:16,代码来源:TrendRepositoryImplTest.java

示例11: ClientGetsContext

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void ClientGetsContext() {
    RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);

    TestObserver<HelloResponse> testObserver = stub.sayHello(worldReq)
            .doOnSuccess(resp -> {
                Context ctx = Context.current();
                assertThat(ctxKey.get(ctx)).isEqualTo("ClientGetsContext");
            })
            .test();

    testObserver.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testObserver.assertComplete();
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:15,代码来源:ContextPropagationIntegrationTest.java

示例12: testWrite

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testWrite() throws Exception {
    RxPaperBook book = RxPaperBook.with("WRITE", Schedulers.trampoline());
    final String key = "hello";
    final Completable write = book.write(key, ComplexObject.random());
    Assert.assertFalse(book.book.exist(key));
    final TestObserver<Void> testSubscriber = write.test();
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertComplete();
    testSubscriber.assertNoErrors();
    Assert.assertTrue(book.book.exist(key));
}
 
开发者ID:pakoito,项目名称:RxPaper2,代码行数:13,代码来源:RxPaperBookTest.java

示例13: manyToOne

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void manyToOne() {
    RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
    Single<HelloResponse> resp = stub.sayHelloReqStream(Flowable.just(HelloRequest.getDefaultInstance()));
    TestObserver<HelloResponse> test = resp.test();

    test.awaitTerminalEvent(3, TimeUnit.SECONDS);
    test.assertError(t -> t instanceof StatusRuntimeException);
    test.assertError(t -> ((StatusRuntimeException)t).getStatus() == Status.INTERNAL);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:11,代码来源:ServerErrorIntegrationTest.java

示例14: oneToOne

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void oneToOne() {
    RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
    Single<HelloResponse> resp = stub.sayHello(Single.just(HelloRequest.getDefaultInstance()));
    TestObserver<HelloResponse> test = resp.test();

    test.awaitTerminalEvent(3, TimeUnit.SECONDS);
    test.assertError(t -> t instanceof StatusRuntimeException);
    test.assertError(t -> ((StatusRuntimeException)t).getStatus().getCode() == Status.Code.INTERNAL);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:11,代码来源:UnexpectedServerErrorIntegrationTest.java

示例15: testUpdateTag

import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void testUpdateTag() {
  when(bookmarksAdapter.updateTag(anyLong(), anyString())).thenReturn(true);

  Tag tag = new Tag(1, "First Tag");
  TestObserver<Void> testObserver = new TestObserver<>();
  model.updateTag(tag)
      .subscribe(testObserver);
  testObserver.awaitTerminalEvent();
  testObserver.assertNoErrors();
  testObserver.assertComplete();

  verify(bookmarksAdapter, times(1)).updateTag(tag.id, tag.name);
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:15,代码来源:BookmarkModelTest.java


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