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